build(api): set production NODE_ENV when migrating in prod #149
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: Default | |
on: | |
push: | |
branches: [master] | |
pull_request: | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:15.2-alpine | |
env: | |
POSTGRES_USER: serieslist | |
POSTGRES_PASSWORD: serieslist | |
POSTGRES_DB: serieslist_test | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# We need to fetch all branches and commits so that Nx affected has a base to compare against. | |
fetch-depth: 0 | |
- uses: nrwl/nx-set-shas@v3 | |
with: | |
main-branch-name: 'master' | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
cache: 'pnpm' | |
- name: Setup | |
run: | | |
cp .env.example .env | |
bash bin/generate-secret-token.sh | |
- name: Installing dependencies | |
run: | | |
pnpm install | |
pnpm exec nx affected -t install-deps:e2e | |
- name: Checks | |
run: | | |
pnpm install | |
pnpm exec nx affected -t migrate:test | |
pnpm exec nx affected -t lint,tsc,test:coverage,build --verbose | |
- name: E2E tests | |
run: | | |
pnpm exec nx affected -t test:e2e | |
- uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: playwright-report | |
path: apps/e2e/playwright-report/ | |
retention-days: 30 | |
deploy: | |
runs-on: ubuntu-latest | |
environment: | |
name: production | |
url: https://serieslist.joosep.xyz | |
needs: check | |
if: ${{ github.ref == 'refs/heads/master' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup | |
run: | | |
cp .env.example .env | |
- name: Build containers | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
sed -i.bak -e "s/VITE_API_HOST=.*/VITE_API_HOST=api.serieslist.joosep.xyz/" .env | |
sed -i.bak -e "s/VITE_API_URL=.*/VITE_API_URL=https:\/\/\$VITE_API_HOST/" .env | |
docker compose -f docker-compose.production.yml pull webapp api || true | |
docker compose -f docker-compose.production.yml build webapp api | |
docker compose -f docker-compose.production.yml push | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.DEPLOYMENT_SSH_PRIVATE_KEY }} | |
known_hosts: 'just-a-placeholder-so-we-dont-get-errors' | |
- name: Adding Known Hosts | |
run: ssh-keyscan -H ${{ secrets.DEPLOYMENT_SSH_HOST }} >> ~/.ssh/known_hosts | |
- name: Updating deployment in server | |
run: bash bin/update-deployment.sh | |
env: | |
DEPLOYMENT_SSH_HOST: ${{ secrets.DEPLOYMENT_SSH_HOST }} | |
DEPLOYMENT_SSH_USER: ${{ secrets.DEPLOYMENT_SSH_USER }} |