Skip to content

Commit

Permalink
ft: add ci build to automate deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshs9 committed Nov 10, 2024
1 parent 824bcdd commit dbce678
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 9 deletions.
79 changes: 79 additions & 0 deletions .github/composite/build-push-gcloud/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "Docker build & push to Artifact Registry"
description: "Builds the docker image and pushes it to Google Artifact Registry"
on:
workflow_call:
inputs:
repo:
description: "Repository name"
required: true
registry:
description: "Google Artifact registry"
required: false
default: "docker.pkg.dev"
dockerfile:
description: "Dockerfile path"
required: false
default: "Dockerfile"
context:
description: "Docker context"
required: false
default: "."
project_id:
description: "Google project ID"
required: true
google_key:
description: "Google service account key in BASE64"
required: true
outputs:
imageid:
description: "Image ID"
value: ${{ jobs.push.outputs.imageid }}
tag:
description: "Image tag"
value: ${{ jobs.push.outputs.tag }}
jobs:
push:
name: "Build & Push"
runs-on: ubuntu-latest
outputs:
imageid:
description: "Image ID"
value: ${{ steps.build.outputs.imageid }}
tag:
description: "Image tag"
value: ${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
steps:
- name: Docker login to Google Cloud
id: vars
run: |
echo "$B64_GOOGLE_KEY" | docker login -u _json_key_base64 --password-stdin https://$REGISTRY
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "branch=$(echo "$branch" | tr '/\' '-')" >> $GITHUB_OUTPUT
shell: bash
env:
B64_GOOGLE_KEY: ${{ inputs.google_key }}
REGISTRY: ${{ inputs.registry }}
# - name: Check image
# id: image_exists
# continue-on-error: true
# uses: cloudposse/github-action-docker-image-exists@main
# with:
# registry: ${{ inputs.registry }}
# image_name: ${{ inputs.project_id }}/${{ inputs.repo }}
# tag: ${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
- uses: docker/setup-buildx-action@v3
if: steps.image_exists.outcome == 'failure'
- uses: docker/build-push-action@v5
# if: steps.image_exists.outcome == 'failure'
id: build
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
push: true
labels: |
ci.run_id=${{ github.run_id }}
tags: |
${{ inputs.registry }}/${{ inputs.project_id }}/${{ inputs.repo }}:${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }}
40 changes: 40 additions & 0 deletions .github/workflows/cd-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CD

on:
push:
branches:
- main
tags:
- v*

jobs:
push-backend:
name: Build backend
runs-on: ubuntu-latest
outputs:
version: ${{ steps.build.outputs.tag }}
steps:
- uses: actions/checkout@v4
- uses: ../composite/build-push-gcloud/action.yaml
id: build
with:
google_key: ${{ secrets.GCLOUD_SECRET_KEY }}
repo: services/whisper-notes-backend
dockerfile: backend.Dockerfile
registry: europe-north1-docker.pkg.dev
project_id: ${{ secrets.GCLOUD_PROJECT }}
push-frontend:
name: Build frontend
runs-on: ubuntu-latest
outputs:
version: ${{ steps.build.outputs.tag }}
steps:
- uses: actions/checkout@v4
- uses: ../composite/build-push-gcloud/action.yaml
id: build
with:
google_key: ${{ secrets.GCLOUD_SECRET_KEY }}
repo: services/whisper-notes-frontend
dockerfile: frontend.Dockerfile
registry: europe-north1-docker.pkg.dev
project_id: ${{ secrets.GCLOUD_PROJECT }}
29 changes: 29 additions & 0 deletions backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:23-alpine AS build

WORKDIR /build
COPY backend .
COPY protos ./protos

RUN yarn --frozen-lockfile

RUN yarn proto-loader-gen-types \
--grpcLib=@grpc/grpc-js \
--outDir=./src/generated/ \
./protos/*.proto

RUN yarn build

FROM node:23-alpine AS app

RUN apk add --no-cache tini

WORKDIR /app
COPY --from=build /build/node_modules ./node_modules
COPY --from=build /build/dist ./dist
COPY --from=build /build/protos ./protos

ENV PROTO_PATH="/app/protos"
EXPOSE 8080

ENTRYPOINT ["/sbin/tini", "--"]
CMD [ "node", "dist/server.js" ]
21 changes: 21 additions & 0 deletions frontend.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:23-alpine AS build

WORKDIR /build
COPY frontend .
COPY protos ./protos

RUN yarn --frozen-lockfile

RUN yarn protoc \
--ts_out src/generated/ \
--ts_opt long_type_string \
--proto_path ./protos \
--ts_opt ts_nocheck \
./protos/*.proto

RUN yarn build

FROM flashspys/nginx-static:latest AS app

COPY --from=build /build/dist /static
EXPOSE 80
3 changes: 2 additions & 1 deletion frontend/src/generated/notes.client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @generated by protobuf-ts 2.9.4 with parameter long_type_string
// @generated by protobuf-ts 2.9.4 with parameter long_type_string,ts_nocheck
// @generated from protobuf file "notes.proto" (package "notes", syntax proto3)
// tslint:disable
// @ts-nocheck
import type { RpcTransport } from "@protobuf-ts/runtime-rpc";
import type { ServiceInfo } from "@protobuf-ts/runtime-rpc";
import { NoteService } from "./notes";
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/generated/notes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @generated by protobuf-ts 2.9.4 with parameter long_type_string
// @generated by protobuf-ts 2.9.4 with parameter long_type_string,ts_nocheck
// @generated from protobuf file "notes.proto" (package "notes", syntax proto3)
// tslint:disable
// @ts-nocheck
import { ServiceType } from "@protobuf-ts/runtime-rpc";
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
import type { IBinaryWriter } from "@protobuf-ts/runtime";
Expand Down
2 changes: 1 addition & 1 deletion frontend/tsconfig.app.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/App.tsx","./src/index.tsx","./src/vite-env.d.ts","./src/components/AudioManager.tsx","./src/components/AudioPlayer.tsx","./src/components/AudioRecorder.tsx","./src/components/Progress.tsx","./src/components/TranscribeButton.tsx","./src/components/Transcript.tsx","./src/components/modal/Modal.tsx","./src/components/modal/UrlInput.tsx","./src/hooks/useTranscriber.ts","./src/hooks/useWorker.ts","./src/utils/AudioUtils.ts","./src/utils/BlobFix.ts","./src/utils/Constants.ts"],"errors":true,"version":"5.6.2"}
{"root":["./src/app.tsx","./src/index.tsx","./src/vite-env.d.ts","./src/components/audiomanager.tsx","./src/components/audioplayer.tsx","./src/components/audiorecorder.tsx","./src/components/progress.tsx","./src/components/transcribebutton.tsx","./src/components/transcript.tsx","./src/components/modal/modal.tsx","./src/components/modal/urlinput.tsx","./src/generated/notes.client.ts","./src/generated/notes.ts","./src/hooks/usetranscriber.ts","./src/hooks/useworker.ts","./src/services/index.ts","./src/utils/audioutils.ts","./src/utils/blobfix.ts","./src/utils/constants.ts"],"version":"5.6.3"}
2 changes: 1 addition & 1 deletion frontend/tsconfig.node.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./vite.config.ts"],"version":"5.6.2"}
{"root":["./vite.config.ts"],"version":"5.6.3"}
11 changes: 6 additions & 5 deletions proto-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Backend
# cd $SCRIPT_DIR/backend
# yarn proto-loader-gen-types \
# --grpcLib=@grpc/grpc-js \
# --outDir=./src/generated/ \
# $SCRIPT_DIR/protos/*.proto
cd $SCRIPT_DIR/backend
yarn proto-loader-gen-types \
--grpcLib=@grpc/grpc-js \
--outDir=./src/generated/ \
$SCRIPT_DIR/protos/*.proto
echo "Backend stubs generated..."

# Frontend
Expand All @@ -22,5 +22,6 @@ npx protoc \
--ts_out src/generated/ \
--ts_opt long_type_string \
--proto_path $SCRIPT_DIR/protos \
--ts_opt ts_nocheck \
$SCRIPT_DIR/protos/*.proto
echo "Frontend Stubs generated..."

0 comments on commit dbce678

Please sign in to comment.