generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 5
112 lines (97 loc) · 2.95 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
name: 'Container Build & Deploy'
on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
REGISTRY:
required: true
type: string
REPO:
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@v6
with:
push: true
tags: '${{ inputs.REGISTRY }}/${{ inputs.REPO }}:${{ github.sha }}'
file: ./Dockerfile
context: .
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: pre-live
images: '${{ inputs.REGISTRY }}/${{ inputs.REPO }}:${{ github.sha }}'
- name: Azure Swap Slots
uses: azure/CLI@v2
with:
inlineScript: |
az webapp deployment slot swap -n ${{ inputs.APP }} --slot pre-live --resource-group csels-rsti-${{ inputs.ENVIRONMENT }}${{ github.event.number }}-moderate-rg