-
Notifications
You must be signed in to change notification settings - Fork 15
71 lines (58 loc) · 2.34 KB
/
pr-preview.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
name: Launch preview environment
on:
pull_request:
types: [labeled]
jobs:
preview:
runs-on: ubuntu-latest
if: ${{ github.event.label.name == 'preview' }}
env:
IMAGE_NAME: incidental/backend
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build image
uses: docker/build-push-action@v4
with:
context: backend
tags: ${{env.IMAGE_NAME}}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker
- name: Copy env file
run: cp backend/.env.example backend/.env
- name: Create the docker compose stack
run: docker compose -f backend/docker-compose.yml up -d
- name: Check local running docker containers
run: docker ps -a
- name: Migrate db
run: docker compose -f backend/docker-compose.yml exec -T backend sh -c "alembic upgrade head"
- name: Get short commit SHA, display tunnel URL and IP Address of the worker node
id: get-subdomain
run: |
subdomain="pr-$(git rev-parse --short HEAD)"
echo "URL for tunnelling: https://$subdomain.loca.lt"
echo "subdomain=$subdomain" >> $GITHUB_OUTPUT
worker_ip="$(curl -4 -s ipconfig.io/ip)"
echo "Worker node IP address: $worker_ip"
- name: Start tunnel
env:
SUBDOMAIN: ${{ steps.get-subdomain.outputs.subdomain }}
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
run: |
curl -O https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
sudo tar -xvzf ./ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin
ngrok config add-authtoken ${NGROK_AUTH_TOKEN}
ngrok http 5000 --domain ${SUBDOMAIN}.ngrok.io