This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
generated from ieeeuoft/hackathon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (169 loc) · 6.3 KB
/
main.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
name: CI/CD
on:
push:
branches: '**'
env:
IMAGE_ROOT: docker.pkg.github.com/${{ github.repository }}
STACK_NAME: newhacks-site-2020
jobs:
backend-checks:
runs-on: ubuntu-latest
defaults:
run:
working-directory: hackathon_site
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Check formatting with Black
run: |
# Stop the build if there are any formatting issues picked up by Black
black --check .
- name: Tests
env:
SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
DEBUG: 0
run: python manage.py test --settings=hackathon_site.settings.ci
event-checks:
runs-on: ubuntu-latest
defaults:
run:
working-directory: hackathon_site/event
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Install dependencies
run: yarn install
- name: Formatting check
run: yarn prettier --check 'static/**/*.(scss|js)'
dashboard-checks:
runs-on: ubuntu-latest
defaults:
run:
working-directory: hackathon_site/dashboard/frontend
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Install dependencies
run: yarn install
- name: Formatting check
run: yarn prettier --check 'src/**/*.(scss|js)'
- name: Tests
run: yarn test --watchAll=false
build:
runs-on: ubuntu-latest
needs: [ backend-checks, event-checks, dashboard-checks ]
if: github.ref == 'refs/heads/master'
outputs:
GITHUB_SHA_SHORT: ${{ steps.sha7.outputs.GITHUB_SHA_SHORT }}
steps:
- uses: actions/checkout@v2
- name: Get short SHA
id: sha7
run: |
echo "::set-env name=GITHUB_SHA_SHORT::$(echo ${{ github.sha }} | cut -c1-7)"
echo "::set-output name=GITHUB_SHA_SHORT::$(echo ${{ github.sha }} | cut -c1-7)"
- name: Build image
run: docker-compose -f deployment/docker-compose.ci.yml build
- name: Authenticate Docker with GitHub Packages
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: docker-compose -f deployment/docker-compose.ci.yml push
deploy:
runs-on: ubuntu-latest
needs: [ build ]
if: github.ref == 'refs/heads/master'
defaults:
run:
working-directory: deployment
env:
GITHUB_SHA_SHORT: ${{ needs.build.outputs.GITHUB_SHA_SHORT }}
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install python dependencies
working-directory: hackathon_site
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Install nodejs dependencies
working-directory: hackathon_site/event
run: yarn install
- name: Compile scss
working-directory: hackathon_site/event
run: yarn scss
- name: Collect static
working-directory: hackathon_site
env:
SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
run: python manage.py collectstatic
- name: Set environment variables in .env
run: |
echo 'DEBUG=0' >> .env
echo 'SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }}' >> .env
echo 'DB_NAME=${{ secrets.DB_NAME }}' >> .env
echo 'DB_USER=${{ secrets.DB_USER }}' >> .env
echo 'DB_PASSWORD=${{ secrets.DB_PASSWORD }}' >> .env
echo 'DB_HOST=${{ secrets.DB_HOST }}' >> .env
echo 'DB_PORT=${{ secrets.DB_PORT }}' >> .env
echo 'EMAIL_HOST=${{ secrets.EMAIL_HOST }}' >> .env
echo 'EMAIL_PORT=${{ secrets.EMAIL_PORT }}' >> .env
echo 'EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }}' >> .env
echo 'EMAIL_HOST_PASSWORD=${{ secrets.EMAIL_HOST_PASSWORD }}' >> .env
echo 'EMAIL_FROM_ADDRESS=${{ secrets.EMAIL_FROM_ADDRESS }}' >> .env
echo 'REDIS_URI=${{ secrets.REDIS_URI }}' >> .env
- name: Transfer static files to the Swarm manager
uses: appleboy/[email protected]
with:
host: ${{ secrets.SWARM_MANAGER_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
overwrite: true
# scp-action doesn't obey working-directory, runs at repo root
source: "hackathon_site/static/"
target: "/usr/src/${{ github.repository }}"
strip_components: 1
- name: Set up SSH
run: |
mkdir -p ~/.ssh
ssh-keyscan -t rsa ${{ secrets.SWARM_MANAGER_IP }} >> ~/.ssh/known_hosts
echo "${{ secrets.SSH_PRIVATE_KEY }}" >> ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Bring up deployment
env:
DOCKER_HOST: ssh://${{ secrets.SSH_USER }}@${{ secrets.SWARM_MANAGER_IP }}
run: |
curl -s https://raw.githubusercontent.com/sudo-bmitch/docker-stack-wait/main/docker-stack-wait.sh \
-o docker-stack-wait.sh
chmod +x docker-stack-wait.sh
echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
docker stack deploy --with-registry-auth -c docker-compose.prod.yml ${{ env.STACK_NAME }}
echo "Waiting for deployment..."
sleep 30
./docker-stack-wait.sh -t 300 ${{ env.STACK_NAME }}
echo "Running migrations..."
# TODO: This will fail if at least one replica isn't running on the node, will need to
# switch DOCKER_HOST over ssh
service_id=$(docker ps -f "name=${{ env.STACK_NAME }}_django" -q | head -n1)
docker exec $service_id python manage.py migrate
echo "Deployment complete"