Skip to content

Merge pull request #884 from NoodleOfDeath/dev #1882

Merge pull request #884 from NoodleOfDeath/dev

Merge pull request #884 from NoodleOfDeath/dev #1882

Workflow file for this run

name: API CI
on:
push:
branches:
- main
- dev
concurrency:
group: ${{ github.ref }}-api
cancel-in-progress: true
env:
IMAGE: ${{ github.event.repository.name }}-api-${{ fromJSON('{"main":"prod"}')[github.ref_name] || github.ref_name }}
REGISTRY: ${{ vars.REGISTRY }}
jobs:
build-api:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, '~api') || contains(github.event.head_commit.message, '~deploy') }}
environment: ${{ fromJSON('{"main":"prod"}')[github.ref_name] || github.ref_name }}
steps:
- name: Print Job Description
run: |
echo building \"$IMAGE\" from branch \"${{ github.ref_name }}\"
- name: Git Checkout
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.GIT_SSH_KEY }}
submodules: recursive
- name: Build
run: |
docker build . \
--file Dockerfile.api \
--tag $IMAGE:latest
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to doctl
run: doctl registry login --expiry-seconds 600
- name: Tag Docker Image
run: docker tag $IMAGE:latest $REGISTRY/$IMAGE:latest
- name: Push Docker Image
run: docker push $REGISTRY/$IMAGE:latest
deploy-api:
needs: build-api
runs-on: ubuntu-latest
environment: ${{ fromJSON('{"main":"prod"}')[github.ref_name] || github.ref_name }}
env:
API_RATE_LIMIT: ${{ vars.API_RATE_LIMIT }}
API_RATE_LIMIT_DURATION: ${{ vars.API_RATE_LIMIT_DURATION }}
APPLE_SECRET_KEY: ${{ secrets.APPLE_SECRET_KEY }}
BASE_DOMAIN: ${{ vars.BASE_DOMAIN }}
CACHE_LIFESPAN: ${{ vars.CACHE_LIFESPAN }}
CORS_ORIGIN: ${{ vars.CORS_ORIGIN }}
ENABLED_FEATURES: ${{ vars.ENABLED_FEATURES }}
FIREBASE_CREDENTIALS: ${{ secrets.FIREBASE_CREDENTIALS }}
GOOGLE_CLIENT_ID: ${{ vars.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_MEASUREMENT_API_SECRET: ${{ secrets.GOOGLE_MEASUREMENT_API_SECRET }}
GOOGLE_MEASUREMENT_CLIENT_ID: ${{ vars.GOOGLE_MEASUREMENT_CLIENT_ID }}
GOOGLE_MEASUREMENT_ID: ${{ vars.GOOGLE_MEASUREMENT_ID }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
JWT_TOKEN_LIFESPAN: ${{ vars.JWT_TOKEN_LIFESPAN }}
K8S_NAMESPACE: ${{ secrets.K8S_NAMESPACE }}
K8S_MEMORY_REQUESTS: ${{ vars.K8S_MEMORY_REQUESTS }}
K8S_CPU_REQUESTS: ${{ vars.K8S_CPU_REQUESTS }}
K8S_MEMORY_LIMITS: ${{ vars.K8S_MEMORY_LIMITS }}
K8S_CPU_LIMITS: ${{ vars.K8S_CPU_LIMITS }}
K8S_REPLICA_COUNT_API: ${{ vars.K8S_REPLICA_COUNT_API }}
MAIL_HOST: ${{ vars.MAIL_HOST }}
MAIL_PASS: ${{ secrets.MAIL_PASS }}
MAIL_PORT: ${{ vars.MAIL_PORT }}
MAIL_REPLY_TO: ${{ vars.MAIL_REPLY_TO }}
MAIL_USER: ${{ secrets.MAIL_USER }}
NEXT_PUBLIC_GOOGLE_MEASUREMENT_ID: ${{ vars.NEXT_PUBLIC_GOOGLE_MEASUREMENT_ID }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
PG_CONNECTION_STRING: ${{ secrets.PG_CONNECTION_STRING }}
PLAY_HT_SECRET_KEY: ${{ secrets.PLAY_HT_SECRET_KEY }}
PLAY_HT_USER_ID: ${{ secrets.PLAY_HT_USER_ID }}
PORT: ${{ vars.PORT }}
RECAPTCHA_SECRET_KEY: ${{ secrets.RECAPTCHA_SECRET_KEY }}
REGISTRATION_PRIVATE_KEY: ${{ secrets.REGISTRATION_PRIVATE_KEY }}
S3_BUCKET: ${{ vars.S3_BUCKET }}
S3_KEY: ${{ secrets.S3_KEY }}
S3_SECRET: ${{ secrets.S3_SECRET }}
SSL: ${{ vars.SSL }}
TRUSTED_PROXIES: ${{ secrets.TRUSTED_PROXIES }}
steps:
- name: Print Job Description
run: |
echo deploying \"$IMAGE\" from branch \"${{ github.ref_name }}\"
- name: Git Checkout
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.GIT_SSH_KEY }}
submodules: recursive
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Add kubectl cert
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.K8S_CLUSTER_ID }}
- name: Apply deployment changes
run: envsubst < $GITHUB_WORKSPACE/k8s/api-deploy.yaml | kubectl apply -f -
- name: Deploy Rollout
run: kubectl rollout restart deployment/$IMAGE --namespace $K8S_NAMESPACE
- name: Verify deployment
run: kubectl rollout status deployment/$IMAGE --namespace $K8S_NAMESPACE