-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (117 loc) · 5.14 KB
/
pipeline.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
name: Pipeline
on: [push, workflow_dispatch]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PORT: ${{ vars.PORT }}
WASP_WEB_CLIENT_URL: ${{ vars.WASP_WEB_CLIENT_URL }}
BACKEND_DOMAIN: ${{ vars.BACKEND_DOMAIN }}
REACT_APP_API_URL: ${{ vars.REACT_APP_API_URL }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
ADS_SERVER_URL: ${{ vars.ADS_SERVER_URL }}
jobs:
unit_test:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install wasp
run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh
- name: Run client tests
run: wasp test client run --silent
docker_build_push:
runs-on: ubuntu-22.04
needs: [unit_test]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install wasp
run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: docker pull ghcr.io/$GITHUB_REPOSITORY:$GITHUB_REF_NAME || docker pull ghcr.io/$GITHUB_REPOSITORY || true
- name: Build wasp
run: wasp build
- run: docker build --build-arg PORT=$PORT -t ghcr.io/$GITHUB_REPOSITORY:$GITHUB_REF_NAME ./.wasp/build/
- name: Add tag latest if branch is main
if: github.ref_name == 'main'
run: docker tag ghcr.io/$GITHUB_REPOSITORY:$GITHUB_REF_NAME ghcr.io/$GITHUB_REPOSITORY:latest
- name: Push only if branch name is main
if: github.ref_name == 'main'
run: docker push ghcr.io/$GITHUB_REPOSITORY --all-tags
deploy_backend:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
needs: [docker_build_push]
if: github.ref_name == 'main'
container:
image: python:3.7-stretch
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
SSH_KEY: ${{ secrets.SSH_KEY }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
steps:
- uses: actions/checkout@v3
# This is to fix GIT not liking owner of the checkout dir - https://github.com/actions/runner/issues/2033#issuecomment-1204205989
- run: chown -R $(id -u):$(id -g) $PWD
- run: echo "TAG=latest" >> $GITHUB_ENV
# - run: if [[ $GITHUB_REF_NAME == "main" ]]; then printenv PROD_CONFIG > "$(pwd)/.env" ; else printenv STAGING_CONFIG > "$(pwd)/.env" ; fi;
- run: echo "PATH=$PATH:/github/home/.local/bin" >> $GITHUB_ENV
- run: 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- run: eval $(ssh-agent -s)
- run: mkdir -p ~/.ssh
- run: chmod 700 ~/.ssh
- run: ssh-keyscan "$BACKEND_DOMAIN" >> ~/.ssh/known_hosts
- run: chmod 644 ~/.ssh/known_hosts
- run: echo "$SSH_KEY" | base64 --decode > key.pem
- run: chmod 600 key.pem
# - run: if [[ $GITHUB_REF_NAME == "main" ]]; then echo "DOMAIN=api.airt.ai" >> $GITHUB_ENV ; else echo "DOMAIN=api.staging.airt.ai" >> $GITHUB_ENV ; fi;
- run: ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$BACKEND_DOMAIN" "docker images"
- run: sh scripts/deploy_backend.sh
- run: rm key.pem
deploy_frontend:
runs-on: ubuntu-22.04
needs: [docker_build_push]
permissions:
contents: write
if: github.ref_name == 'main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install wasp
run: curl -sSL https://get.wasp-lang.dev/installer.sh | sh
- name: Build wasp
run: wasp build
- name: Build frontend
run: cd .wasp/build/web-app && npm install && REACT_APP_API_URL=$REACT_APP_API_URL npm run build
- name: Copy 404.html
run: cp 404.html .wasp/build/web-app/build
- name: Deploy to github pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: .wasp/build/web-app/build