-
Notifications
You must be signed in to change notification settings - Fork 4
178 lines (148 loc) · 5.27 KB
/
deploy.production.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Deploy to Production
on:
release:
types: [released]
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: './app/workers'
AZURE_WEBAPP_PACKAGE_PATH: './app/next-client-app'
PYTHON_VERSION: '3.11'
NODE_VERSION: 20
jobs:
build-and-publish-workers:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4
- name: Setup Python ${{ env.PYTHON_VERSION }} Environment
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 'Install Poetry'
uses: snok/install-poetry@v1
- name: 'Resolve Project Dependencies Using Poetry'
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
poetry config virtualenvs.create false
poetry export --format requirements.txt --output requirements.txt --without-hashes
popd
shell: bash
- name: 'Install Dependencies Using Pip'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: functionsapp
path: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
include-hidden-files: true
build-and-publish-web:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ccomreg.azurecr.io
username: ${{ secrets.REGISTRY_USERNAME_DEV }}
password: ${{ secrets.REGISTRY_PASSWORD_DEV }}
- name: Build and push container image to registry
uses: docker/build-push-action@v5
with:
push: true
tags: ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}
file: ./app/Dockerfile.deploy
build-and-publish-next-app:
runs-on: ubuntu-latest
environment: dev
env:
BACKEND_ORIGIN: ${{ secrets.BACKEND_ORIGIN }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm install and build
run: |
npm i --workspaces=false
working-directory: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Cache .next/cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.next/cache
key: nextjs | $(Agent.OS) | ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/package-lock.json
- name: Build
run: npm run build --workspaces=false
working-directory: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Copy Static Assets
run: |
cp -r .next/static .next/standalone/.next/
cp -r public .next/standalone/
working-directory: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Publish webapp artifact
uses: actions/upload-artifact@v4
with:
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.next/standalone
name: frontendwebapp
include-hidden-files: true
# Deploy Workers Production
deploy-workers-production:
runs-on: ubuntu-latest
needs: build-and-publish-workers
environment: production
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
path: functionsapp
name: functionsapp
- name: 'Run Azure Functions Action'
uses: Azure/[email protected]
id: fa
with:
app-name: ${{ vars.AZURE_FUNCTIONS_NAME }}
slot-name: 'production'
package: ${{ github.workspace }}/functionsapp
publish-profile: ${{ secrets.AZURE_FUNCAPP_PUBLISH_PROFILE }}
# Deploy Web App Production
deploy-web-production:
runs-on: ubuntu-latest
needs: [build-and-publish-web, deploy-workers-production]
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
slot-name: 'production'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: 'ccomreg.azurecr.io/${{ secrets.REGISTRY_USERNAME_DEV }}/latest:${{ github.sha }}'
# Deploy Next.js Client App Production
deploy-next-production:
runs-on: ubuntu-latest
needs: [build-and-publish-next-app, deploy-web-production]
environment: production
steps:
- uses: actions/checkout@v4
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
path: frontendwebapp
name: frontendwebapp
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.AZURE_WEBAPP_NEXT_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }}
package: ${{ github.workspace }}/frontendwebapp