-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (118 loc) · 4.19 KB
/
azure-deploy-dev.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
name: 'App Deploy [Azure - DEV]'
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**/*.md'
- .docker*
- .env.example
- .github
- .gitignore
- .pa11yci
- .tool-versions
- .yardopts
- bin/*
- docker-compose.*
- terraform-azure/**
- uml/*
# Permissions for OIDC authentication
permissions:
id-token: write
contents: write
packages: write
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
DOCKER_IMAGE: ghcr.io/dfe-digital/early-years-foundation-recovery
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: development
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout Code
uses: actions/checkout@v4
# Create and boot Docker image builder
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.9.1
# Login to the container registry
- name: Login to Github Container Registry
uses: docker/#-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push image
- name: Build and push Docker Image
uses: docker/build-push-action@v6
with:
target: app
context: .
push: true
platforms: linux/amd64,linux/arm64
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Early Years Recovery Rails Application
build-args: |
BUILDKIT_INLINE_CACHE=1
SHA=${{ github.sha }}
cache-from: |
${{ env.DOCKER_IMAGE }}:${{ github.sha }}
tags: |
${{ env.DOCKER_IMAGE }}:${{ github.sha }}
${{ env.DOCKER_IMAGE }}:latest
# Login to Azure using OIDC
- name: Login to Azure CLI
uses: azure/#@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Deploy Web Application
- name: Deploy to Azure App Services
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.WEBAPP_NAME }}
images: ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
# Destroy Background Worker
- name: Destroy existing Azure Container Instances
uses: azure/CLI@v2
with:
azcliversion: 2.50.0
inlineScript: |
az container delete --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ vars.WORKERAPP_NAME }} \
--yes
# Deploy Background Worker
- name: Deploy to Azure Container Instances
uses: azure/CLI@v2
with:
azcliversion: 2.50.0
inlineScript: |
az container create --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
--name ${{ vars.WORKERAPP_NAME }} \
--image ${{ env.DOCKER_IMAGE }}:${{ github.sha }} \
--cpu 1 \
--memory 2 \
--command-line "que" \
--restart-policy OnFailure \
--log-analytics-workspace ${{ secrets.AZURE_LOG_ANALYTICS_WORKSPACE }} \
--vnet ${{ secrets.AZURE_VNET }} \
--subnet ${{ secrets.AZURE_WORKER_APP_SUBNET }} \
--ip-address Private \
--output none \
--environment-variables \
EDITOR=vi \
RAILS_ENV=production \
RAILS_LOG_TO_STDOUT=true \
CONTENTFUL_ENVIRONMENT=test \
ENVIRONMENT=${{ vars.ENVIRONMENT }} \
DOMAIN=${{ vars.WEBAPP_CONFIG_DOMAIN }} \
GOOGLE_CLOUD_BUCKET=${{ vars.WEBAPP_CONFIG_GOOGLE_CLOUD_BUCKET }} \
RAILS_MASTER_KEY=${{ secrets.WEBAPP_CONFIG_RAILS_MASTER_KEY }} \
DATABASE_URL=${{ secrets.WEBAPP_DATABASE_URL }} \
GCS_CREDENTIALS=${{ secrets.GCS_CREDENTIALS }} \
SENTRY_TOKEN=${{ secrets.SENTRY_TOKEN }}