generated from Azure-Samples/openhack-devops-team
-
Notifications
You must be signed in to change notification settings - Fork 4
99 lines (93 loc) · 4.25 KB
/
user-java-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# This workflow will build and push a Docker container to an Azure Web App when a commit is pushed to your default branch.
#
# This workflow assumes you have already created the target Azure App Service web app.
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-custom-container?tabs=dotnet&pivots=container-linux
#
# To configure this workflow:
#
# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials
#
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret
#
# 3. Create a GitHub Personal access token with "repo" and "read:packages" permissions.
#
# 4. Create three app settings on your Azure Web app:
# DOCKER_REGISTRY_SERVER_URL: Set this to "https://ghcr.io"
# DOCKER_REGISTRY_SERVER_USERNAME: Set this to the GitHub username or organization that owns the repository
# DOCKER_REGISTRY_SERVER_PASSWORD: Set this to the value of your PAT token from the previous step
#
# 5. Change the value for the AZURE_WEBAPP_NAME.
#
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
name: user-java - CD
env:
AZURE_WEBAPP_NAME: openhackyvs74zq0userjava
BASEIMAGETAG: ${{github.sha}}
ACRNAME: openhackyvs74zq0acr.azurecr.io
GITOHTEAMDIRPATH: .
RESOURCE_GROUP: openhackyvs74zq0rg
on:
push:
branches:
#- $default-branch
- main
paths:
- 'apis/user-java/**'
- '.github/workflows/user-java-cd.yml'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Build and push container to ACR
run: |
echo "Building API-USER-JAVA image..."
echo "Changing directory to $GITOHTEAMDIRPATH/apis/user-java..."
cd "$GITOHTEAMDIRPATH/apis/user-java"
az acr build --image "devopsoh/api-user-java:${BASEIMAGETAG}" --registry $ACRNAME --file Dockerfile .
#<Azure Container Registry URI>/<ACR_repository_name>:<Revision Number> where the ACR_repository_name follows the naming convention devopsoh/<image_name>:<tag>.
#openhackyvs74zq0acr.azurecr.io/devopsoh/api-poi:
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Development'
#url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Debug'
run: |
echo "Deploying ${{ env.ACRNAME }}/devopsoh/api-user-java:${{ env.BASEIMAGETAG }}"
- name: 'Deploy to Azure Web App for Container'
id: deploy-staging
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
images: ${{ env.ACRNAME }}/devopsoh/api-user-java:${{ env.BASEIMAGETAG }}
#startup-command: 'mvn spring-boot:run' # Include start up command to start the app container
slot-name: staging
# check
- uses: actions/checkout@v2
- name: 'Check staging deployment is successful'
run: |
echo "Running polling.sh from $GITOHTEAMDIRPATH/resources/polling.sh"
cd "$GITOHTEAMDIRPATH/resources"
# make file runnable
chmod +x "./polling.sh"
./polling.sh "${{ steps.deploy-staging.outputs.webapp-url }}/api/healthcheck/user-java" 90
shell: bash
# if successful swap stage to prod
- name: 'Swap web app deployment slots for blue/green'
id: swap-to-prod
run: |
az webapp deployment slot swap -g ${{env.RESOURCE_GROUP}} -n ${{ env.AZURE_WEBAPP_NAME }} --slot staging --target-slot production