ENG-88: Adds preview environment #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_frontend="frontend-pr-$(git rev-parse --short HEAD)" | |
subdomain_backend="backend-pr-$(git rev-parse --short HEAD)" | |
echo "Preview frontend url: https://${subdomain_frontend}.ngrok.io" | |
echo "subdomain=$subdomain" >> $GITHUB_OUTPUT | |
worker_ip="$(curl -4 -s ipconfig.io/ip)" | |
echo "Worker node IP address: $worker_ip" | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: "frontend/.nvmrc" | |
- name: Install deps | |
run: | | |
cd frontend | |
npm install -g pnpm | |
pnpm install | |
- name: Run frontend | |
env: | |
VITE_API_BASE_URL: https://${{ steps.get-subdomain.outputs.subdomain_backend}} | |
run: | | |
cd frontend | |
pnpm dev | |
- name: Start tunnel | |
env: | |
SUBDOMAIN_BACKEND: ${{ steps.get-subdomain.outputs.subdomain_backend }} | |
SUBDOMAIN_FRONTEND: ${{ steps.get-subdomain.outputs.subdomain_frontend }} | |
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} | |
echo "Starting tunnels.." | |
ngrok http 5000 --domain ${SUBDOMAIN_BACKEND}.ngrok.io & | |
ngrok http 3000 --domain ${SUBDOMAIN_FRONTEND}.ngrok.io |