-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (115 loc) · 5.04 KB
/
deploy.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
name: Run deploy
on:
workflow_dispatch:
push:
branches:
- develop
paths:
- 'client/**'
- 'cms/**'
- '.github/workflows/*'
env:
PROJECT_NAME: "esa-gda-comms"
IMAGE_REGISTRY: "registry.digitalocean.com/esa-gda-comms"
jobs:
build_client_image:
name: Build Client image and push to DO Container Registry
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Copy env variables to docker
env:
ENVIRONMENT: ${{ steps.extract_branch.outputs.branch == 'main' && 'PROD' || 'STAGING' }}
run: |
echo "${{ secrets[format('{0}_CLIENT_ENV_FILE', env.ENVIRONMENT)] }}" > client/.env.local
- name: Build and tag Client image
env:
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client
run: |
docker build $(cat client/.env.local | xargs -I {} echo --build-arg {}) -f client/Dockerfile.prod -t $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA .
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DO Container Registry
run: doctl registry login --expiry-seconds 600
- name: Push image to DigitalOcean Container Registry
env:
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client
run: docker push $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA
- name: Remove old images from Container Registry
uses: martintomas/docr-image-remove@v1
with:
image_repository: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client
buffer_size: 5
build_cms_image:
name: Build CMS image and push to DO Container Registry
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Copy env variables to docker
env:
ENVIRONMENT: ${{ steps.extract_branch.outputs.branch == 'main' && 'PROD' || 'STAGING' }}
run: |
echo "${{ secrets[format('{0}_CMS_ENV_FILE', env.ENVIRONMENT)] }}" > cms/.env
- name: Build and tag CMS image
env:
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms
run: |
docker build -f cms/Dockerfile.prod -t $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA .
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DO Container Registry
run: doctl registry login --expiry-seconds 600
- name: Push image to DigitalOcean Container Registry
env:
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms
run: docker push $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA
- name: Remove old images from Container Registry
uses: martintomas/docr-image-remove@v1
with:
image_repository: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms
buffer_size: 5
deploy:
name: Deploy Client and CMS to DO APP Platform
needs: [build_client_image, build_cms_image]
runs-on: ubuntu-22.04
steps:
- name: DigitalOcean App Platform deployment
uses: digitalocean/[email protected]
env:
IMAGE_NAME_CLIENT: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client
IMAGE_NAME_CMS: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms
with:
app_name: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
images: '[
{
"name": "${{ env.IMAGE_NAME_CLIENT }}",
"image":{
"registry_type": "DOCR",
"repository": "${{ env.IMAGE_NAME_CLIENT }}",
"tag": "${{ github.sha }}"
}
},
{
"name": "${{ env.IMAGE_NAME_CMS }}",
"image":{
"registry_type": "DOCR",
"repository": "${{ env.IMAGE_NAME_CMS }}",
"tag": "${{ github.sha }}"
}
}
]'