Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up backend tests #1323

Merged
merged 13 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 0 additions & 146 deletions .circleci/config.yml

This file was deleted.

211 changes: 211 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: Build and Deploy

on:
push:
branches:
- "*"

permissions:
packages: write

jobs:
build_api_srv:
runs-on: ubuntu-latest
env:
MACONDO_DATA_PATH: ${{ github.workspace }}/data
TEST_DB_HOST: localhost
TEST_DB_PREFIX: liwords_test
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: pass
DB_SSL_MODE: disable
DB_MIGRATIONS_PATH: file:///${{ github.workspace }}/db/migrations
REDIS_URL: redis://localhost:6379
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 3s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: pass
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432

steps:
- name: Checkout
uses: actions/checkout@v4

# - name: Clone macondo
# uses: actions/checkout@v4
# with:
# repository: domino14/macondo
# path: macondo

# - run: mv $GITHUB_WORKSPACE/macondo /opt/macondo

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ">=1.22"

- name: Build API
run: cd cmd/liwords-api && go build

- name: Test API
run: go test -race ./...

- name: Build Puzzle Generator
run: cd cmd/puzzlegen && go build

- name: Build Maintenance
run: cd cmd/maintenance && go build

- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Backend built successfully for branch {{GITHUB_REF_NAME}}."

deploy_api_docker:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
needs: build_api_srv
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: domino14
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Tag Docker Image
run: cd deploy && ./build-and-tag.sh

- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Backend docker container uploaded; tag = {{GITHUB_REF_NAME}}-gh{{GITHUB_RUN_NUMBER}}"

build_fe:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install Dependencies
run: cd liwords-ui && npm ci

- name: Test Frontend
run: cd liwords-ui && npm run test

- name: Build Frontend
run: cd liwords-ui && npm run build
continue-on-error: true

- name: Persist Dist Directory
uses: actions/upload-artifact@v4
with:
name: dist
path: liwords-ui/dist

- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Front-end built successfully for branch {{GITHUB_REF_NAME}}."

deploy_fe:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
needs: build_fe
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Dist Directory
uses: actions/download-artifact@v4
with:
name: dist
path: /tmp/liwords-ui

- name: Calculate UI Hash
run: |
UI_HASH=$(find /tmp/liwords-ui/dist -type f -exec md5sum {} \; | sort -k 2 | md5sum | head -c 32)
echo $UI_HASH
sed -i "s:unknown:${UI_HASH}:" /tmp/liwords-ui/dist/config.js
echo "export UI_HASH=$UI_HASH" >> $GITHUB_ENV

- name: Install AWS CLI
run: |
sudo apt-get update
sudo apt-get install -y awscli

- name: Sync to S3 (Cache Everything)
run: |
cd /tmp/liwords-ui/dist &&
aws s3 sync --cache-control 'max-age=3024000' \
--exclude index.html --exclude config.js --exclude '*.wasm' \
--metadata FEHash=${UI_HASH} \
. s3://woogles.io

- name: Sync to S3 (No Cache Except Wasm)
run: |
cd /tmp/liwords-ui/dist &&
aws s3 sync --cache-control 'no-cache' --exclude '*.wasm' \
--metadata FEHash=${UI_HASH} \
. s3://woogles.io

- name: Cache Wasm File Separately
run: |
cd /tmp/liwords-ui/dist &&
aws s3 sync --cache-control 'max-age=3024000' --exclude '*' --include '*.wasm' \
--metadata FEHash=${UI_HASH} \
--content-type 'application/wasm' . s3://woogles.io

- name: Update Frontend Hash
run: |
curl -X POST -H "Content-Type: application/json" \
-H "X-Api-Key: $ADMIN_WOOGLES_API_KEY" \
https://woogles.io/api/config_service.ConfigService/SetFEHash \
-d "{\"hash\": \"$UI_HASH\"}"

- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "Front-end deployed successfully for branch {{GITHUB_REF_NAME}}."
11 changes: 1 addition & 10 deletions Dockerfile → deploy/Dockerfile-apiserver
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
FROM golang as build-env

RUN mkdir /opt/program
WORKDIR /opt/program

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
FROM liwords-builder as build-env

WORKDIR /opt/program/cmd/liwords-api

Expand Down
10 changes: 10 additions & 0 deletions deploy/Dockerfile-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang as build-env

RUN mkdir /opt/program
WORKDIR /opt/program

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
Loading