|
| 1 | +name: Deploy to Azure WebApp Branch slot |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches-ignore: |
| 6 | + - main |
| 7 | + - master |
| 8 | + |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: 'ubuntu-latest' |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + |
| 17 | + - name: Set up Docker Buildx |
| 18 | + uses: docker/setup-buildx-action@v2 |
| 19 | + |
| 20 | + - name: Log in to registry |
| 21 | + uses: docker/login-action@v1 |
| 22 | + with: |
| 23 | + registry: https://dockerregistryspa.azurecr.io/ |
| 24 | + username: PushToken |
| 25 | + password: ${{ secrets.DOCKER_REGISTRY_SERVER_PASSWORD }} |
| 26 | + - name: Build and push container without tag |
| 27 | + uses: docker/build-push-action@v4 |
| 28 | + with: |
| 29 | + push: true |
| 30 | + tags: dockerregistryspa.azurecr.io/dockerregistryspa/${{ github.event.repository.name }}:${{ github.sha }} |
| 31 | + context: ./ |
| 32 | + deploy: |
| 33 | + needs: build |
| 34 | + runs-on: ubuntu-latest |
| 35 | + environment: |
| 36 | + name: 'branch' |
| 37 | + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} |
| 38 | + steps: |
| 39 | + - name: Check out code |
| 40 | + uses: actions/checkout@v3 |
| 41 | + |
| 42 | + - name: Login to Azure |
| 43 | + uses: azure/login@v1 |
| 44 | + with: |
| 45 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 46 | + |
| 47 | + - name: Create slot if it doesn't exist |
| 48 | + run: | |
| 49 | + SLOT_NAME=${GITHUB_REF##*/} |
| 50 | + az webapp deployment slot create \ |
| 51 | + --resource-group webappsdocker \ |
| 52 | + --name ${{ github.event.repository.name }} \ |
| 53 | + --configuration-source ${{ github.event.repository.name }} \ |
| 54 | + --slot $SLOT_NAME || echo "Slot already exists" |
| 55 | + - name: Set container settings for slot |
| 56 | + run: | |
| 57 | + az webapp config container set \ |
| 58 | + --name ${{ github.event.repository.name }} \ |
| 59 | + --resource-group webappsdocker \ |
| 60 | + --slot ${GITHUB_REF##*/} \ |
| 61 | + --docker-custom-image-name dockerregistryspa.azurecr.io/dockerregistryspa/${{ github.event.repository.name }}:${{ github.sha }} \ |
| 62 | + --docker-registry-server-url https://dockerregistryspa.azurecr.io |
| 63 | +
|
| 64 | + - name: Restart slot to apply changes |
| 65 | + run: | |
| 66 | + az webapp restart \ |
| 67 | + --name ${{ github.event.repository.name }} \ |
| 68 | + --resource-group webappsdocker \ |
| 69 | + --slot ${GITHUB_REF##*/} |
0 commit comments