Skip to content

Commit

Permalink
chore: fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
bacali95 committed Nov 3, 2024
1 parent 1b5ba86 commit 6f51f1c
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 125 deletions.
63 changes: 63 additions & 0 deletions .github/actions/setup-environment/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: 'Setup environment'
description: 'This action will checkout code, setup node and retrieve the cache'

inputs:
skip-install:
description: 'Skip Install1'
required: false
outputs:
version:
description: 'Project version'
value: ${{ steps.version.outputs.version }}
cache-hit:
description: 'A boolean value to indicate an exact match was found for the key'
value: ${{ steps.yarn-cache.outputs.cache-hit }}

runs:
using: composite
steps:
- name: Set Yarn version
shell: bash
run: yarn set version 4.5.1

- name: Install NodeJs 22
uses: actions/setup-node@v4
with:
node-version: 22

- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3

- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Restore yarn cache
uses: actions/cache@v4
id: yarn-cache
if: inputs.skip-install != 'true'
with:
path: |
./.yarn/install-state.gz
~/.cache/Cypress
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-

- name: Yarn Install
shell: bash
run: yarn install --immutable
if: inputs.skip-install != 'true'

- name: Retrieve commit message
id: commit_message
shell: bash
run: |
echo "commit_message=$(git log --no-merges -1 --pretty=format:"%s")" >> $GITHUB_OUTPUT
- name: Retrieve version
id: version
shell: bash
run: |
echo "version=$(node -e 'console.log(require("./package.json").version);')" >> $GITHUB_OUTPUT
166 changes: 166 additions & 0 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: Build & Deploy

on:
push:
branches:
- main
pull_request:

concurrency: ${{ github.ref }}

jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-environment
id: setup

- name: Lint
run: yarn lint

- name: Prettier
run: yarn prettier

- name: Generate Prisma Schema
run: yarn prisma:generate

- name: Build
run: yarn build

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

- name: Build and push Dependencies Docker image
uses: docker/build-push-action@v5
if: steps.setup.outputs.cache-hit != 'true'
with:
context: .
file: docker/Dockerfile
push: true
tags: |
ghcr.io/tun-judge/dependencies:${{ hashFiles('yarn.lock') }}
ghcr.io/tun-judge/dependencies:latest
- name: Run docker compose up
if: false
run: |
docker compose -f docker-compose.test.yaml up -d app
sleep 30s
env:
DEPENDENCIES_TAG: ${{ hashFiles('yarn.lock') }}

- name: Run E2E tests
if: false
shell: bash
run: yarn e2e

- name: Run docker compose down
if: false
run: |
docker compose -f docker-compose.test.yaml logs
docker compose -f docker-compose.test.yaml down
- name: Save Build Output
uses: actions/cache/save@v4
with:
path: dist/apps
key: apps-${{ steps.setup.outputs.version }}

deploy:
runs-on: ubuntu-latest
permissions: write-all
if: startsWith(github.event.head_commit.message, 'release')
needs: build
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-environment
id: setup
with:
skip-install: 'true'

- name: Restore Build Output
uses: actions/cache/restore@v4
with:
path: dist/apps
key: apps-${{ steps.setup.outputs.version }}
fail-on-cache-miss: true

- name: Google Auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: access_token
workload_identity_provider: ${{ vars.WIF_PROVIDER }}
service_account: ${{ vars.WIF_SERVICE_ACCOUNT }}

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

- name: Docker Auth
id: docker-auth
uses: docker/login-action@v3
with:
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
registry: europe-west1-docker.pkg.dev

- name: Build and push Server Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/server/Dockerfile
push: true
tags: |
ghcr.io/tunjudge/server:${{ steps.setup.outputs.version }}
europe-west1-docker.pkg.dev/tun-judge-dev/docker/tun-judge-app:${{ steps.setup.outputs.version }}
build-args: |
DEPENDENCIES_TAG=${{ hashFiles('yarn.lock') }}
- name: Build and push Judge Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/judge/Dockerfile
push: true
tags: ghcr.io/tunjudge/judge:${{ steps.setup.outputs.version }}
build-args: |
DEPENDENCIES_TAG=${{ hashFiles('yarn.lock') }}
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
image: europe-west1-docker.pkg.dev/tun-judge-dev/docker/tun-judge-app:${{ steps.setup.outputs.version }}
service: tun-judge
region: europe-west1
env_vars: |
GOOGLE_PROJECT_ID=tun-judge-dev
GOOGLE_STORAGE_ENABLED=true
GOOGLE_STORAGE_BUCKET_NAME=tun-judge-files
secrets: |
SESSION_SECRET=SESSION_SECRET:latest
DATABASE_URL=TUN_JUDGE_DATABASE_URL:latest
DATABASE_DIRECT_URL=TUN_JUDGE_DATABASE_DIRECT_URL:latest
REDIS_URL=TUN_JUDGE_REDIS_URL:latest
- name: Show Output
shell: bash
run: echo ${{ steps.deploy.outputs.url }}
63 changes: 0 additions & 63 deletions .github/workflows/build.yaml

This file was deleted.

60 changes: 0 additions & 60 deletions .github/workflows/release.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ RUN yarn workspaces focus --production

FROM node:22-alpine as final-stage

ARG PROJECT

RUN apk add --update curl && rm -rf /var/cache/apk/*

WORKDIR /usr/src/app
Expand Down
2 changes: 2 additions & 0 deletions docker/judge/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ COPY --chown=node:node apps/judge/package.json ./package.json
COPY --chown=node:node zenstack/prisma ./prisma
COPY --chown=node:node dist/apps/judge ./judge

RUN yarn prisma generate

ENV ENVIRONMENT=production

EXPOSE 3000
Expand Down

0 comments on commit 6f51f1c

Please sign in to comment.