|
| 1 | +name: Azure Preview WWW |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + types: [opened, synchronize, reopened] |
| 7 | + paths: |
| 8 | + - 'apps/www/**' |
| 9 | + - 'internal/components/**' |
| 10 | + |
| 11 | +permissions: |
| 12 | + id-token: write |
| 13 | + contents: read |
| 14 | + |
| 15 | +env: |
| 16 | + RESOURCE_GROUP: rg-designsystemet-test |
| 17 | + CONTAINERAPPS_ENV: www-test-ca |
| 18 | + ACR_NAME: designsystemetacr |
| 19 | + APP_NAME: www-pr-${{ github.event.number }} |
| 20 | + PORT: '8000' |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: azure-www-preview-${{ github.event.pull_request.number || github.run_id }} |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + deploy: |
| 28 | + if: ${{ github.repository == 'digdir/designsystemet' }} |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + fqdn: ${{ steps.fqdn.outputs.fqdn }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: az login (oidc) |
| 36 | + uses: azure/login@v2 |
| 37 | + with: |
| 38 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 39 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 40 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 41 | + |
| 42 | + - name: acr login |
| 43 | + run: az acr login --name ${{ env.ACR_NAME }} |
| 44 | + |
| 45 | + - name: Build & push image |
| 46 | + uses: docker/build-push-action@v5 |
| 47 | + with: |
| 48 | + context: . |
| 49 | + file: ./Dockerfile |
| 50 | + target: www |
| 51 | + platforms: linux/amd64 |
| 52 | + push: true |
| 53 | + tags: ${{ env.ACR_NAME }}.azurecr.io/www:${{ env.APP_NAME }}-${{ github.sha }} |
| 54 | + |
| 55 | + - name: Deploy / Update Container App |
| 56 | + uses: azure/container-apps-deploy-action@v1 |
| 57 | + with: |
| 58 | + resourceGroup: ${{ env.RESOURCE_GROUP }} |
| 59 | + containerAppName: ${{ env.APP_NAME }} |
| 60 | + containerAppEnvironment: ${{ env.CONTAINERAPPS_ENV }} |
| 61 | + acrName: ${{ env.ACR_NAME }} |
| 62 | + imageToDeploy: ${{ env.ACR_NAME }}.azurecr.io/www:${{ env.APP_NAME }}-${{ github.sha }} |
| 63 | + targetPort: ${{ env.PORT }} |
| 64 | + ingress: external |
| 65 | + environmentVariables: | |
| 66 | + PORT=${{ env.PORT }} |
| 67 | + HOST=0.0.0.0 |
| 68 | +
|
| 69 | + - name: Fetch FQDN |
| 70 | + id: fqdn |
| 71 | + run: | |
| 72 | + echo "Retrieving FQDN for $APP_NAME" |
| 73 | + FQDN=$(az containerapp show -n $APP_NAME -g $RESOURCE_GROUP --query properties.configuration.ingress.fqdn -o tsv) |
| 74 | + echo "fqdn=$FQDN" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + - name: Summary |
| 77 | + run: | |
| 78 | + echo "Preview deployed: https://${{ steps.fqdn.outputs.fqdn }}" >> $GITHUB_STEP_SUMMARY |
| 79 | +
|
| 80 | + update-comment: |
| 81 | + if: ${{ github.event_name == 'pull_request' }} |
| 82 | + needs: deploy |
| 83 | + uses: ./.github/workflows/preview-comment.yml |
| 84 | + with: |
| 85 | + pr_number: ${{ github.event.number }} |
| 86 | + deployment_type: www |
| 87 | + deployment_url: https://${{ needs.deploy.outputs.fqdn }} |
0 commit comments