-
-
Notifications
You must be signed in to change notification settings - Fork 8
144 lines (127 loc) · 4.65 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
138
139
140
141
142
143
144
name: Deploy Changed Project to Azure
on:
workflow_dispatch:
push:
branches:
- main
# pull_request:
# types: [opened, synchronize, reopened, closed]
# branches:
# - main
# Needed for nx-set-shas when run on the main branch
permissions:
actions: read
contents: read
jobs:
identify_affected:
runs-on: ubuntu-latest
outputs:
affected: ${{ steps.set-output.outputs.affected }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: npm ci
- uses: nrwl/nx-set-shas@v4
with:
main-branch-name: 'main'
# This line is needed for nx affected to work when CI is running on a PR
# - run: git branch --track main origin/main
- name: Identify affected projects
run: |
echo "AFFECTED=$(npx nx print-affected --base=${{ env.NX_BASE }} --head=${{ env.NX_HEAD }} | jq -r '.projects | join(" ")')" >> $GITHUB_ENV
- name: Set affected projects as output
id: set-output
run: echo "::set-output name=affected::${{ env.AFFECTED }}"
build_and_deploy_client:
if: contains(needs.identify_affected.outputs.affected, 'client')
needs: identify_affected
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: npm ci
- name: Build Project
run: npm run build:client
- name: Deploy
id: deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: 'upload'
app_location: '/docs' # App source code path
push_and_deploy_server:
if: contains(needs.identify_affected.outputs.affected, 'server')
needs: identify_affected
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: educoder/zip-captions-server
- name: Build and push server Docker image
uses: docker/build-push-action@v4
with:
target: prod_server
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request'}}
tags: educoder/zip-captions-server:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to container app
uses: azure/container-apps-deploy-action@v2
with:
containerAppName: zip-captions-server
resourceGroup: ZipCaptions
imageToDeploy: educoder/zip-captions-server:${{ github.sha }}
targetPort: 3000
disableTelemetry: true
ingress: external
environmentVariables: >
MONGO_DB_USER=secretref:mongo-db-user
MONGO_DB_PASSWORD=secretref:mongo-db-password
MONGO_DB_URL=secretref:mongo-db-url
MONGO_DB_PORT=10255
MONGO_DB_NAME=secretref:mongo-db-name
AZURE_CLIENT_ID=secretref:azure-client-id
AZURE_CLIENT_SECRET=secretref:azure-client-secret
AZURE_REDIRECT_URI=secretref:azure-redirect-url
GOOGLE_CLIENT_ID=secretref:google-client-id
GOOGLE_CLIENT_SECRET=secretref:google-client-secret
GOOGLE_REDIRECT_URI=secretref:google-redirect-uri
SESSION_SECRET=secretref:session-secret
JWT_SECRET=secretref:jwt-secret
APP_ORIGIN=https://zipcaptions.app
PATREON_CLIENT_ID=secretref:patreon-client-id
PATREON_CLIENT_SECRET=secretref:patreon-client-secret
PATREON_REDIRECT_URI=secretref:patreon-redirect-uri
PATREON_SUPPORTER_WEBHOOK_SECRET=secretref:patreon-supporter-webhook-secret
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: 'close'