Skip to content

Commit 88a0947

Browse files
committed
rework actions, delete vercel actions
1 parent 66871b6 commit 88a0947

19 files changed

Lines changed: 231 additions & 602 deletions
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: azure deploy storybook prod
2+
run-name: Deploy to storybook to ${{ inputs.environment }} by @${{ github.actor }}
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
description: 'Deployment environment (production, preview)'
10+
pr_number:
11+
required: false
12+
type: string
13+
description: 'PR number for preview deployments'
14+
update_comment:
15+
required: false
16+
type: boolean
17+
default: false
18+
description: 'Whether to update PR comment with deployment URL'
19+
secrets:
20+
AZURE_CLIENT_ID:
21+
required: true
22+
AZURE_TENANT_ID:
23+
required: true
24+
AZURE_SUBSCRIPTION_ID:
25+
required: true
26+
27+
permissions:
28+
id-token: write # needed for OIDC
29+
contents: read
30+
31+
concurrency:
32+
group: azure-storybook-prod-deploy
33+
cancel-in-progress: true
34+
35+
env:
36+
RESOURCE_GROUP: ${{ inputs.environment == 'production' && 'rg-designsystemet-prod' || 'rg-designsystemet-test' }}
37+
CONTAINERAPPS_ENV: ${{ inputs.environment == 'production' && 'storybook-prod-ca' || 'storybook-test-ca' }}
38+
ACR_NAME: designsystemetacr
39+
APP_NAME: ${{ inputs.environment == 'production' && 'storybook-prod' || 'storybook-test-pr'-${{ inputs.pr_number }} }}
40+
IMAGE: ${{ github.event.number }}-${{ github.sha }}
41+
PORT: 8000
42+
43+
jobs:
44+
deploy:
45+
runs-on: ubuntu-latest
46+
environment: azure
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- name: az login (oidc)
51+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
52+
with:
53+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
54+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
55+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
56+
57+
- name: acr login
58+
run: az acr login --name designsystemetacr
59+
60+
- name: build & push (storybook)
61+
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
62+
with:
63+
context: .
64+
file: ./Dockerfile
65+
target: storybook
66+
platforms: linux/amd64
67+
push: true
68+
tags: designsystemetacr.azurecr.io/storybook:latest
69+
70+
- name: deploy
71+
uses: azure/container-apps-deploy-action@29ee19866ec987ededd70b8412d9ee241a9102d1 # v1
72+
with:
73+
resourceGroup: ${RESOURCE_GROUP}
74+
containerAppName: ${APP_NAME}
75+
containerAppEnvironment: ${CONTAINERAPPS_ENV}
76+
acrName: ${ACR_NAME}
77+
imageToDeploy: ${IMAGE}
78+
targetPort: ${PORT}
79+
ingress: external
80+
environmentVariables: |
81+
PORT=${PORT}
82+
HOST=0.0.0.0
83+
ENV=${{ inputs.environment }}

.github/workflows/azure-deploy-themebuilder.yml

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
1-
name: deploy themebuilder to aca
2-
1+
name: azure deploy themebuilder prod
2+
run-name: Deploy to themebuilder to ${{ inputs.environment }} by @${{ github.actor }}
33
on:
4-
workflow_dispatch:
5-
push:
6-
branches:
7-
- main
8-
paths:
9-
- 'apps/themebuilder/**'
10-
- 'internal/components/**'
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
description: 'Deployment environment (production, preview)'
10+
pr_number:
11+
required: false
12+
type: string
13+
description: 'PR number for preview deployments'
14+
update_comment:
15+
required: false
16+
type: boolean
17+
default: false
18+
description: 'Whether to update PR comment with deployment URL'
19+
secrets:
20+
AZURE_CLIENT_ID:
21+
required: true
22+
AZURE_TENANT_ID:
23+
required: true
24+
AZURE_SUBSCRIPTION_ID:
25+
required: true
1126

1227
permissions:
1328
id-token: write # needed for OIDC
1429
contents: read
1530

31+
concurrency:
32+
group: azure-themebuilder-prod-deploy
33+
cancel-in-progress: true
34+
35+
env:
36+
RESOURCE_GROUP: ${{ inputs.environment == 'production' && 'rg-designsystemet-prod' || 'rg-designsystemet-test' }}
37+
CONTAINERAPPS_ENV: ${{ inputs.environment == 'production' && 'themebuilder-prod-ca' || 'themebuilder-test-ca' }}
38+
ACR_NAME: designsystemetacr
39+
APP_NAME: ${{ inputs.environment == 'production' && 'themebuilder-prod' || 'themebuilder-test-pr'-${{ inputs.pr_number }} }}
40+
IMAGE: ${{ github.event.number }}-${{ github.sha }}
41+
PORT: 8000
42+
1643
jobs:
1744
deploy:
1845
runs-on: ubuntu-latest
@@ -38,18 +65,19 @@ jobs:
3865
target: themebuilder
3966
platforms: linux/amd64
4067
push: true
41-
tags: designsystemetacr.azurecr.io/themebuilder:${{ github.sha }}
68+
tags: designsystemetacr.azurecr.io/themebuilder:latest
4269

4370
- name: deploy
4471
uses: azure/container-apps-deploy-action@29ee19866ec987ededd70b8412d9ee241a9102d1 # v1
4572
with:
46-
resourceGroup: rg-designsystemet-test
47-
containerAppName: themebuilder-test-ca-app
48-
containerAppEnvironment: themebuilder-test-ca
49-
acrName: designsystemetacr
50-
imageToDeploy: designsystemetacr.azurecr.io/themebuilder:${{ github.sha }}
51-
targetPort: 8000
73+
resourceGroup: ${RESOURCE_GROUP}
74+
containerAppName: ${APP_NAME}
75+
containerAppEnvironment: ${CONTAINERAPPS_ENV}
76+
acrName: ${ACR_NAME}
77+
imageToDeploy: ${IMAGE}
78+
targetPort: ${PORT}
5279
ingress: external
5380
environmentVariables: |
54-
PORT=8000
81+
PORT=${PORT}
5582
HOST=0.0.0.0
83+
ENV=${{ inputs.environment }}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Azure Preview Cleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
id-token: write
9+
contents: read
10+
11+
env:
12+
RESOURCE_GROUP: rg-designsystemet-test
13+
ACR_NAME: designsystemetacr
14+
# Base names of preview apps we want to clean up. Add/remove as needed.
15+
PREVIEW_APPS: www themebuilder storybook
16+
17+
jobs:
18+
cleanup:
19+
if: ${{ github.repository == 'digdir/designsystemet' }}
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: az login (oidc)
25+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
26+
with:
27+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
28+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
29+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
30+
31+
- name: Delete preview Container Apps
32+
env:
33+
PR_NUMBER: ${{ github.event.number }}
34+
run: |
35+
set -euo pipefail
36+
echo "Starting cleanup for PR #${PR_NUMBER} in resource group ${RESOURCE_GROUP}" | tee -a $GITHUB_STEP_SUMMARY
37+
ANY_DELETED=0
38+
for base in $PREVIEW_APPS; do
39+
APP_NAME="${base}-pr-${PR_NUMBER}"
40+
echo "Checking ${APP_NAME}" | tee -a $GITHUB_STEP_SUMMARY
41+
if az containerapp show -n "${APP_NAME}" -g "${RESOURCE_GROUP}" >/dev/null 2>&1; then
42+
echo "Deleting ${APP_NAME}" | tee -a $GITHUB_STEP_SUMMARY
43+
az containerapp delete -n "${APP_NAME}" -g "${RESOURCE_GROUP}" --yes
44+
echo "Deleted ${APP_NAME}" | tee -a $GITHUB_STEP_SUMMARY
45+
ANY_DELETED=1
46+
else
47+
echo "Not found: ${APP_NAME} (skipping)" | tee -a $GITHUB_STEP_SUMMARY
48+
fi
49+
done
50+
if [ "$ANY_DELETED" = "0" ]; then
51+
echo "No preview container apps found for PR #${PR_NUMBER}" | tee -a $GITHUB_STEP_SUMMARY
52+
else
53+
echo "Cleanup complete for PR #${PR_NUMBER}" | tee -a $GITHUB_STEP_SUMMARY
54+
fi

.github/workflows/azure-preview-storybook.yml

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,99 +3,22 @@ name: azure preview storybook
33
on:
44
workflow_dispatch:
55
pull_request:
6-
types: [opened, synchronize, reopened]
6+
types: [opened, synchronize]
77
paths:
88
- 'apps/storybook/**'
99
- 'internal/components/**'
1010

1111
permissions:
12-
id-token: write
1312
contents: read
14-
pull-requests: write
15-
16-
env:
17-
RESOURCE_GROUP: rg-designsystemet-test
18-
CONTAINERAPPS_ENV: storybook-test-ca
19-
ACR_NAME: designsystemetacr
20-
APP_NAME: storybook-pr-${{ github.event.number }}
21-
IMAGE: ${{ github.event.number }}-${{ github.sha }}
22-
PORT: 6006
23-
24-
concurrency:
25-
group: azure-storybook-preview-${{ github.event.pull_request.number || github.run_id }}
26-
cancel-in-progress: true
2713

2814
jobs:
29-
deploy:
30-
if: ${{ github.repository == 'digdir/designsystemet' }}
31-
runs-on: ubuntu-latest
32-
outputs:
33-
fqdn: ${{ steps.fqdn.outputs.fqdn }}
34-
35-
steps:
36-
- uses: actions/checkout@v4
37-
38-
- name: az login (oidc)
39-
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
40-
with:
41-
client-id: ${{ secrets.AZURE_CLIENT_ID }}
42-
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
43-
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
44-
45-
- name: acr login (for docker push)
46-
run: az acr login --name ${{ env.ACR_NAME }}
47-
48-
- name: build & push image (storybook)
49-
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
50-
with:
51-
context: .
52-
file: ./Dockerfile
53-
target: storybook
54-
platforms: linux/amd64
55-
push: true
56-
tags: ${{ env.ACR_NAME }}.azurecr.io/storybook:${{ env.IMAGE }}
57-
58-
- name: get acr creds (masked)
59-
id: acr
60-
shell: bash
61-
run: |
62-
set -euo pipefail
63-
az acr update -n "${ACR_NAME}" --admin-enabled true >/dev/null
64-
USER=$(az acr credential show -n "${ACR_NAME}" --query username -o tsv)
65-
PASS=$(az acr credential show -n "${ACR_NAME}" --query 'passwords[0].value' -o tsv)
66-
echo "::add-mask::${USER}"
67-
echo "::add-mask::${PASS}"
68-
echo "user=${USER}" >> "$GITHUB_OUTPUT"
69-
echo "pass=${PASS}" >> "$GITHUB_OUTPUT"
70-
71-
- name: deploy (no mi; use registry creds)
72-
uses: azure/container-apps-deploy-action@29ee19866ec987ededd70b8412d9ee241a9102d1 # v1
73-
with:
74-
resourceGroup: ${{ env.RESOURCE_GROUP }}
75-
containerAppEnvironment: ${{ env.CONTAINERAPPS_ENV }}
76-
containerAppName: ${{ env.APP_NAME }}
77-
imageToDeploy: ${{ env.ACR_NAME }}.azurecr.io/storybook:${{ env.IMAGE }}
78-
registryUrl: ${{ env.ACR_NAME }}.azurecr.io
79-
registryUsername: ${{ steps.acr.outputs.user }}
80-
registryPassword: ${{ steps.acr.outputs.pass }}
81-
targetPort: ${{ env.PORT }}
82-
ingress: external
83-
environmentVariables: |
84-
PORT=${{ env.PORT }}
85-
HOST=0.0.0.0
86-
87-
- name: fetch fqdn
88-
id: fqdn
89-
run: |
90-
FQDN=$(az containerapp show -n "${APP_NAME}" -g "${RESOURCE_GROUP}" --query properties.configuration.ingress.fqdn -o tsv)
91-
echo "fqdn=${FQDN}" >> "$GITHUB_OUTPUT"
92-
echo "Resolved FQDN: ${FQDN}" # log for visibility
93-
94-
update-comment:
95-
if: ${{ github.event_name == 'pull_request' }}
96-
needs: deploy
97-
uses: ./.github/workflows/preview-comment.yml
15+
deploy-preview:
16+
uses: ./.github/workflows/azure-deploy-storybook.yml
9817
with:
18+
environment: preview
9919
pr_number: ${{ github.event.number }}
100-
deployment_type: storybook
101-
deployment_url: https://${{ needs.deploy.outputs.fqdn }}
20+
update_comment: true
21+
secrets:
22+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
23+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
24+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

0 commit comments

Comments
 (0)