This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 10
152 lines (132 loc) · 4.35 KB
/
deploy_reusable.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: 'Container Build & Deploy'
on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
REGISTRY:
required: true
type: string
REPO:
required: true
type: string
REPO_DOCS:
required: true
type: string
APP:
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
jobs:
build:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.ENVIRONMENT }}
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: corretto
cache: gradle
- name: Build JAR
run: ./gradlew clean :app:shadowJar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login via Azure CLI
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Retrieve registry password
id: retrieve-registry-password
uses: azure/CLI@v2
with:
inlineScript: |
ACR_PASSWORD=$(az acr login --name ${{ inputs.REGISTRY }} --expose-token --output tsv --query accessToken)
echo "::add-mask::$ACR_PASSWORD"
echo "ACR_PASSWORD=$ACR_PASSWORD" >> "$GITHUB_OUTPUT"
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.REGISTRY }}
username: 00000000-0000-0000-0000-000000000000
password: ${{ steps.retrieve-registry-password.outputs.ACR_PASSWORD }}
- name: Build and push container image to registry
uses: docker/build-push-action@v5
with:
push: true
tags: '${{ inputs.REGISTRY }}/${{ inputs.REPO }}:${{ github.sha }}'
file: ./Dockerfile
context: .
- name: Build and push documentation container image to registry
uses: docker/build-push-action@v5
with:
push: true
tags: '${{ inputs.REGISTRY }}/${{ inputs.REPO_DOCS }}:${{ github.sha }}'
file: ./ig/Dockerfile
context: ./ig
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ inputs.ENVIRONMENT }}
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write
contents: read
steps:
- name: Login via Azure CLI
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ inputs.APP }}
slot-name: production
images: '${{ inputs.REGISTRY }}/${{ inputs.REPO }}:${{ github.sha }}'
- name: Retrieve registry password
id: retrieve-registry-password
uses: azure/CLI@v2
with:
inlineScript: |
ACR_PASSWORD=$(az acr login --name ${{ inputs.REGISTRY }} --expose-token --output tsv --query accessToken)
echo "::add-mask::$ACR_PASSWORD"
echo "ACR_PASSWORD=$ACR_PASSWORD" >> "$GITHUB_OUTPUT"
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.REGISTRY }}
username: 00000000-0000-0000-0000-000000000000
password: ${{ steps.retrieve-registry-password.outputs.ACR_PASSWORD }}
- name: Extract generated documentation from the documentation image
id: extract
uses: shrink/actions-docker-extract@v3
with:
image: '${{ inputs.REGISTRY }}/${{ inputs.REPO_DOCS }}:${{ github.sha }}'
path: /trusted-intermediary/output/.
- name: Upload docs to blob storage
uses: azure/CLI@v2
with:
inlineScript: |
if [ "${{ inputs.ENVIRONMENT }}" == "pr" ]; then
MODIFIED_ENVIRONMENT=${{ inputs.ENVIRONMENT }}${{ github.event.number }}
else
MODIFIED_ENVIRONMENT=${{ inputs.ENVIRONMENT }}
fi
az storage blob sync --account-name cdcti${MODIFIED_ENVIRONMENT}docs -c '$web' -s ${{ steps.extract.outputs.destination }}