-
-
Notifications
You must be signed in to change notification settings - Fork 53
169 lines (147 loc) · 5.14 KB
/
build_and_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
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
name: Build and Deploy
on:
# Push includes PR merge
push:
branches:
- main
- staging
- development
paths:
# Workflow is triggered only if src changes
- src/**
# Allow manual trigger
workflow_dispatch:
jobs:
pytest:
uses: ./.github/workflows/r-pytest.yml
with:
image_tag: ci-${{ github.ref_name }}
frontend-tests:
uses: ./.github/workflows/r-frontend_tests.yml
extract-vars:
needs:
- pytest
- frontend-tests
uses: ./.github/workflows/r-extract_vars.yml
with:
environment: ${{ github.ref_name }}
backend-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
context: src/backend
dockerfile: src/backend/Dockerfile
build_target: prod
image_tags: |
"ghcr.io/hotosm/fmtm/backend:${{ needs.extract-vars.outputs.api_version }}-${{ github.ref_name }}"
"ghcr.io/hotosm/fmtm/backend:latest"
build_args: |
APP_VERSION=${{ needs.extract-vars.outputs.api_version }}
frontend-main-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
context: src/frontend
dockerfile: src/frontend/prod.dockerfile
build_target: prod
image_tags: |
"ghcr.io/hotosm/fmtm/frontend:${{ needs.extract-vars.outputs.frontend_main_version }}-${{ github.ref_name }}"
"ghcr.io/hotosm/fmtm/frontend:latest"
build_args: |
APP_VERSION=${{ needs.extract-vars.outputs.frontend_main_version }}
API_URL=${{ needs.extract-vars.outputs.api_url }}
FRONTEND_MAIN_URL=${{ needs.extract-vars.outputs.frontend_main_url }}
smoke-test-backend:
runs-on: ubuntu-latest
needs:
- extract-vars
- backend-build
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Environment to .env
env:
GIT_BRANCH: ${{ github.ref_name }}
API_VERSION: ${{ needs.extract-vars.outputs.api_version }}
FRONTEND_MAIN_VERSION: ${{ needs.extract-vars.outputs.frontend_main_version }}
run: |
echo "${{ secrets.DOTENV }}" > .env
echo "GIT_BRANCH=${GIT_BRANCH}" >> .env
echo "API_VERSION=${API_VERSION}" >> .env
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env
- name: Backend smoke test
run: |
echo "Not implemented"
# source .env
# docker network create fmtm
# docker pull "postgis/postgis:14-3.3-alpine"
# docker run --rm -d \
# --name=fmtm-db \
# --network=fmtm \
# -e POSTGRES_USER=fmtm \
# -e POSTGRES_PASSWORD=fmtm \
# -e POSTGRES_DB=fmtm \
# "postgis/postgis:14-3.3-alpine"
# docker pull "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}"
# docker run --rm -d \
# --network=fmtm \
# -p 8080:8080 \
# -e FRONTEND_MAIN_URL="http://test.com" \
# -e OSM_CLIENT_ID="test" \
# -e OSM_CLIENT_SECRET="test" \
# -e OSM_SECRET_KEY="test" \
# "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}"
# # First wait 10 seconds for API
# sleep 10
# # Check the exit status of curl and exit the job if it fails
# if ! curl -f http://localhost:8080/docs; then
# echo "curl failed to access http://localhost:8080/docs"
# exit 1
# fi
smoke-test-frontend:
runs-on: ubuntu-latest
needs:
- extract-vars
- frontend-main-build
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Frontend smoke test
run: echo "Not implemented"
deploy-containers:
runs-on: ubuntu-latest
needs:
- extract-vars
- smoke-test-backend
- smoke-test-frontend
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Environment to .env
env:
GIT_BRANCH: ${{ github.ref_name }}
API_VERSION: ${{ needs.extract-vars.outputs.api_version }}
FRONTEND_MAIN_VERSION: ${{ needs.extract-vars.outputs.frontend_main_version }}
run: |
echo "${{ secrets.DOTENV }}" > .env
echo "GIT_BRANCH=${GIT_BRANCH}" >> .env
echo "API_VERSION=${API_VERSION}" >> .env
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Disable Host key verification
# Hack to prevent "Host key verification failed". Should be replaced with a ssh-keyscan based solution
run: echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Deploy
run: |
docker compose --file docker-compose.deploy.yml pull
docker compose --file docker-compose.deploy.yml up --detach
env:
DOCKER_HOST: ${{ vars.DOCKER_HOST }}