|
1 | 1 | name: Deploy to Azure |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: [main] |
6 | | - workflow_dispatch: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
7 | 7 |
|
8 | 8 | env: |
9 | | - AZURE_WEBAPP_NAME: webapp-geolocation-prod |
10 | | - REGISTRY_NAME: acrgeolocation |
11 | | - IMAGE_NAME: geolocation |
| 9 | + AZURE_WEBAPP_NAME: geolocation-app |
| 10 | + REGISTRY_NAME: acrgeo4096 |
| 11 | + IMAGE_NAME: geolocation |
| 12 | + RESOURCE_GROUP: rg-geolocation |
12 | 13 |
|
13 | 14 | jobs: |
14 | | - build-and-deploy: |
15 | | - runs-on: ubuntu-latest |
16 | | - |
17 | | - steps: |
18 | | - - name: Checkout code |
19 | | - uses: actions/checkout@v4 |
20 | | - |
21 | | - - name: Set up Docker Buildx |
22 | | - uses: docker/setup-buildx-action@v3 |
23 | | - |
24 | | - - name: Log in to Azure Container Registry |
25 | | - uses: azure/docker-login@v1 |
26 | | - with: |
27 | | - login-server: ${{ env.REGISTRY_NAME }}.azurecr.io |
28 | | - username: ${{ secrets.AZURE_ACR_USERNAME }} |
29 | | - password: ${{ secrets.AZURE_ACR_PASSWORD }} |
30 | | - |
31 | | - - name: Build and push Docker image |
32 | | - uses: docker/build-push-action@v5 |
33 | | - with: |
34 | | - context: . |
35 | | - file: ./Dockerfile |
36 | | - push: true |
37 | | - tags: | |
38 | | - ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest |
39 | | - ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ github.sha }} |
40 | | - cache-from: type=registry,ref=${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:buildcache |
41 | | - cache-to: type=registry,ref=${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:buildcache,mode=max |
42 | | - |
43 | | - - name: Azure Login |
44 | | - uses: azure/login@v1 |
45 | | - with: |
46 | | - creds: ${{ secrets.AZURE_CREDENTIALS }} |
47 | | - |
48 | | - - name: Deploy to Azure Web App |
49 | | - uses: azure/webapps-deploy@v2 |
50 | | - with: |
51 | | - app-name: ${{ env.AZURE_WEBAPP_NAME }} |
52 | | - images: ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ github.sha }} |
53 | | - |
54 | | - - name: Restart Web App |
55 | | - run: | |
56 | | - az webapp restart --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group rg-geolocation-prod |
| 15 | + build-and-deploy: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Docker Buildx |
| 23 | + uses: docker/setup-buildx-action@v3 |
| 24 | + |
| 25 | + - name: Log in to Azure Container Registry |
| 26 | + uses: azure/docker-login@v1 |
| 27 | + with: |
| 28 | + login-server: ${{ env.REGISTRY_NAME }}.azurecr.io |
| 29 | + username: ${{ secrets.AZURE_ACR_USERNAME }} |
| 30 | + password: ${{ secrets.AZURE_ACR_PASSWORD }} |
| 31 | + |
| 32 | + - name: Build and push Docker image |
| 33 | + uses: docker/build-push-action@v5 |
| 34 | + with: |
| 35 | + context: . |
| 36 | + file: ./Dockerfile |
| 37 | + push: true |
| 38 | + tags: | |
| 39 | + ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest |
| 40 | + ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ github.sha }} |
| 41 | + cache-from: type=registry,ref=${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:buildcache |
| 42 | + cache-to: type=registry,ref=${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:buildcache,mode=max |
| 43 | + |
| 44 | + - name: Azure Login |
| 45 | + uses: azure/login@v1 |
| 46 | + with: |
| 47 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 48 | + |
| 49 | + - name: Deploy to Azure Web App |
| 50 | + uses: azure/webapps-deploy@v2 |
| 51 | + with: |
| 52 | + app-name: ${{ env.AZURE_WEBAPP_NAME }} |
| 53 | + images: ${{ env.REGISTRY_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ github.sha }} |
| 54 | + |
| 55 | + - name: Restart Web App |
| 56 | + run: | |
| 57 | + az webapp restart --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} |
0 commit comments