-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (182 loc) · 6.63 KB
/
test_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Test and Deploy the Application
on: [push]
env:
terraform_version: 0.14.3
TF_WORKSPACE: production
TF_VAR_do_token: ${{ secrets.DO_ACCESS_TOKEN }}
TF_VAR_spaces_access_id: ${{ secrets.DO_SPACES_ACCESS_ID }}
TF_VAR_spaces_secret_key: ${{ secrets.DO_SPACES_SECRET_KEY }}
jobs:
ansible_lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
env:
working_directory: ./deploy
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Cache poetry environments
uses: actions/cache@v1
with:
path: ~/.cache/pypoetry/virtualenvs # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-python-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.OS }}-python-${{ hashFiles('**/poetry.lock') }}
${{ runner.OS }}-python-
${{ runner.OS }}-
- name: Install dependencies with poetry
run: poetry install
working-directory: ${{env.working_directory}}
- name: Lint the ansible file
run: poetry run ansible-lint -x 403,701 site.ymlk
working-directory: ${{env.working_directory}}
frontend_tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.cache/yarn # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-frontend-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-node-frontend-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-node-frontend-
${{ runner.OS }}-
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run tests
run: CI=true yarn lerna run test
backend_tests:
runs-on: ubuntu-latest
env:
working_directory: ./apps/api
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.cache/yarn # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-backend-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-node-backend-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-node-backend-
${{ runner.OS }}-
- name: Install dependencies
run: yarn --frozen-lockfile
working-directory: ${{env.working_directory}}
- name: Run tests
run: CI=true yarn test --passWithNoTests
working-directory: ${{env.working_directory}}
docker_publish:
needs: [backend_tests]
runs-on: ubuntu-latest
env:
IMAGE_NAME: acmweb/api
working_directory: ./apps/api/
DOCKERHUB_USERNAME: acmwebbuilder
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag image
working-directory: ${{env.working_directory}}
- name: Log into registry
run: echo "${{ secrets.DOCKERHUB_PASS }}" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- name: Push image
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_NAME=$IMAGE_NAME
echo VERSION=$VERSION
docker tag image $IMAGE_NAME:$VERSION
docker push $IMAGE_NAME:$VERSION
deploy:
needs: [docker_publish, frontend_tests, ansible_lint]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
env:
working_directory: ./deploy
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Cache poetry environments
uses: actions/cache@v1
with:
path: ~/.cache/pypoetry/virtualenvs # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-python-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.OS }}-python-${{ hashFiles('**/poetry.lock') }}
${{ runner.OS }}-python-
${{ runner.OS }}-
- name: Install dependencies with poetry
run: poetry install
working-directory: ${{ env.working_directory }}
- uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.terraform_version }}
cli_config_credentials_token: ${{ secrets.TF_CLOUD_TOKEN }}
- run: terraform init -input=false
working-directory: ${{ env.working_directory }}
- run: terraform apply -auto-approve
working-directory: ${{ env.working_directory }}
- name: Setup deployment SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIV_KEY }}
- name: Create vault password file
run: echo ${{ secrets.ANSIBLE_VAULT_PASSWORD }} > ~/.vault_pass
working-directory: ${{ env.working_directory }}
- name: Copy digital_ocean.examples.ini
run: cp digital_ocean.examples.ini digital_ocean.ini
working-directory: ${{ env.working_directory }}
- name: Deploy application with ansible
run: poetry run ansible-playbook -i digital_ocean.py site.yml --vault-password-file ~/.vault_pass
working-directory: ${{ env.working_directory }}
env:
DO_API_TOKEN: ${{ secrets.DO_ACCESS_TOKEN }}