Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Build & Upload Docker Image for codebloom-leetcode-auth-service"
description: "Build & (optionally) upload Docker Image to Docker Registry"

inputs:
ENVIRONMENT:
description: "Deployment environment (staging or production)."
required: false
default: production
SECRETS:
description: "Pass toJSON(secrets) from the calling workflow to expose all secrets as env vars."
required: false
DOCKER_UPLOAD:
description: "Boolean indicating whether the image should be uploaded to Docker registry or not."
required: false
default: true
ARCH:
description: "Target architecture to build natively (amd64 or arm64). Each arch pushes to its own Docker repository (codebloom-leetcode-auth-service / codebloom-leetcode-auth-service-arm)."
required: false
default: amd64

outputs:
tag:
description: "Built Docker image tag (git SHA)"
value: ${{ steps.build-image.outputs.tag }}

runs:
using: "composite"
steps:
- name: Setup CI
uses: tahminator/pipeline/actions/setup@a424f92d486342e1255fcdf377a7569eb230aabe
with:
LINT_CI: true
SECRETS: ${{ inputs.SECRETS }}

- name: Run script
id: build-image
shell: bash
run: |
bun run .github/scripts/build-image \
--docker-upload="${{ inputs.DOCKER_UPLOAD }}" \
--getGhaOutput=true \
--type="leetcode-auth-service" \
--arch="${{ inputs.ARCH }}" \
--environment="${{ inputs.ENVIRONMENT }}" \
--prId="${{ github.event.pull_request.number }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Re-Deploy codebloom-leetcode-auth-service to K8s"
description: "Deploy the leetcode auth service to K8s by opening and merging a GitOps image-tag PR."

inputs:
SECRETS:
description: "Pass toJSON(secrets) from the calling workflow to expose all secrets as env vars."
required: false
ENVIRONMENT:
description: '"staging" or "production"'
required: false
default: production
SHA:
description: "Commit SHA of the built image. Defaults to GITHUB_SHA when omitted."
required: false

runs:
using: "composite"
steps:
- name: Setup CI
uses: tahminator/pipeline/actions/setup@a424f92d486342e1255fcdf377a7569eb230aabe
with:
LINT_CI: true
SECRETS: ${{ inputs.SECRETS }}

- name: Run script
shell: bash
run: |
bun run .github/scripts/redeploy \
--environment="${{ inputs.ENVIRONMENT }}" \
--sha="${{ inputs.SHA }}" \
--type="leetcode-auth-service"
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ updates:
patterns: ["*"]
cooldown: { default-days: 7 }
multi-ecosystem-group: main
- package-ecosystem: cargo
directory: /internal/leetcode-auth-service
patterns: ["*"]
cooldown: { default-days: 7 }
multi-ecosystem-group: main
- package-ecosystem: docker
directories:
- /infra
- /internal/leetcode-auth-stealer-service
- /internal/leetcode-auth-service
patterns: ["*"]
cooldown: { default-days: 7 }
multi-ecosystem-group: main
Expand Down
20 changes: 17 additions & 3 deletions .github/scripts/build-image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ const { environment, dockerUpload, getGhaOutput, githubOutputFile, type, arch, p
default: process.env.GITHUB_OUTPUT,
})
.option("type", {
choices: ["standup-bot", "web", "leetcode-auth-stealer-service"] satisfies Type[],
choices: [
"standup-bot",
"web",
"leetcode-auth-stealer-service",
"leetcode-auth-service",
] satisfies Type[],
describe: "Type to build",
demandOption: true,
default: "web" as Type,
Expand Down Expand Up @@ -112,7 +117,9 @@ async function main() {

const buildArgs = {
...(type === "web" ? { COMMIT_SHA: gitSha } : {}),
...(environment === "staging" && type !== "leetcode-auth-stealer-service"
...(environment === "staging" &&
type !== "leetcode-auth-stealer-service" &&
type !== "leetcode-auth-service"
? {
VITE_STAGING: true,
}
Expand All @@ -124,14 +131,20 @@ async function main() {
if (type === "leetcode-auth-stealer-service") {
process.chdir("internal/leetcode-auth-stealer-service");
}
// build.rs also compiles LASS's proto, so the build context is internal/
if (type === "leetcode-auth-service") {
process.chdir("internal");
}
await dockerClient.buildImage({
dockerRepository,
dockerFileLocation:
type === "web"
? "infra/Dockerfile"
: type === "standup-bot"
? "internal/standup-bot/Dockerfile"
: "Dockerfile",
: type === "leetcode-auth-service"
? "leetcode-auth-service/Dockerfile"
: "Dockerfile",
tags,
shouldUpload: dockerUpload,
buildArgs,
Expand Down Expand Up @@ -161,6 +174,7 @@ async function main() {
prId,
owner: "Patina-Network",
repository: "codebloom",
key: `build-${dockerRepository}`,
message: `The image has been uploaded to https://hub.docker.com/r/patinanetwork/${dockerRepository}/tags under the following tags:

${tags.map((t) => `- \`${dockerRepository}:${t}\``).join("\n")}
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@actions/artifact": "^5.0.2",
"@octokit/rest": "^22.0.1",
"@tahminator/pipeline": "1.0.97",
"@tahminator/pipeline": "^1.0.101",
"@types/yargs": "^17.0.35",
"bun": "^1.3.6",
"discord.js": "^14.25.1",
Expand Down
7 changes: 6 additions & 1 deletion .github/scripts/redeploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ const { environment, sha, type } = await yargs(hideBin(process.argv))
default: "",
})
.option("type", {
choices: ["standup-bot", "web", "leetcode-auth-stealer-service"] satisfies Type[],
choices: [
"standup-bot",
"web",
"leetcode-auth-stealer-service",
"leetcode-auth-service",
] satisfies Type[],
describe: "Type to build",
demandOption: true,
default: "web" as Type,
Expand Down
2 changes: 0 additions & 2 deletions .github/scripts/test/run-backend-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ async function main() {

await $`./mvnw -B install -D skipTests --no-transfer-progress`;

await $`./mvnw -B -ntp exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"`;

await $`cd email && pnpm i --frozen-lockfile && ./email.sh && cd ..`;

await $$`./mvnw -B -ntp clean verify -Dspring.profiles.active=ci`;
Expand Down
6 changes: 5 additions & 1 deletion .github/scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ export type Environment = "staging" | "production";

export type Location = "backend" | "frontend";

export type Type = "web" | "standup-bot" | "leetcode-auth-stealer-service";
export type Type =
| "web"
| "standup-bot"
| "leetcode-auth-stealer-service"
| "leetcode-auth-service";
96 changes: 96 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,54 @@ jobs:
ENVIRONMENT: staging
SHA: ${{ github.sha }}

buildStagingLasImage:
name: Build staging image for codebloom-leetcode-auth-service (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}

if: github.event_name == 'pull_request'

strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-26.04
- arch: arm64
runner: ubuntu-26.04-arm

steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}

- name: Run workflow
uses: ./.github/composite/build-image/internal/leetcode-auth-service
with:
SECRETS: ${{ toJSON(secrets) }}
ENVIRONMENT: staging
DOCKER_UPLOAD: "true"
ARCH: ${{ matrix.arch }}

deployStagingLas:
name: Deploy staging codebloom-leetcode-auth-service to K8s
runs-on: ubuntu-26.04
needs: buildStagingLasImage

if: github.event_name == 'pull_request'

steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}

- name: Run workflow
uses: ./.github/composite/redeploy/internal/leetcode-auth-service
with:
SECRETS: ${{ toJSON(secrets) }}
ENVIRONMENT: staging
SHA: ${{ github.sha }}

validateDBSchema:
name: Validate DB Schema on Prod DB
runs-on: ubuntu-26.04
Expand Down Expand Up @@ -294,6 +342,54 @@ jobs:
ENVIRONMENT: production
SHA: ${{ github.sha }}

buildLasImage:
name: Build codebloom-leetcode-auth-service Docker Image & Upload to Registry (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}

if: github.event_name == 'push' && github.ref == 'refs/heads/main'

strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-26.04
- arch: arm64
runner: ubuntu-26.04-arm

steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}

- name: Run workflow
uses: ./.github/composite/build-image/internal/leetcode-auth-service
with:
SECRETS: ${{ toJSON(secrets) }}
ENVIRONMENT: production
DOCKER_UPLOAD: "true"
ARCH: ${{ matrix.arch }}

deployLas:
name: Deploy codebloom-leetcode-auth-service to K8s
runs-on: ubuntu-26.04
needs: buildLasImage

if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}

- name: Run workflow
uses: ./.github/composite/redeploy/internal/leetcode-auth-service
with:
SECRETS: ${{ toJSON(secrets) }}
ENVIRONMENT: production
SHA: ${{ github.sha }}

deploy:
name: deploy codebloom to K8S
runs-on: ubuntu-26.04
Expand Down
40 changes: 10 additions & 30 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,8 @@ DISCORD_REPORTING_CHANNEL_ID=
DISCORD_REPORTING_LOG_GUILD_ID=
DISCORD_REPORTING_LOG_CHANNEL_ID=

# unset will point LASS (Leetcode Auth Stealer Service) to localhost:50051
# uncomment these to use staging LASS (must be on VPN).
# GRPC_LASS_HOST=stg.codebloom-leetcode-auth-stealer-service.vpn.patinanetwork.org:50051
# GRPC_LASS_TLS=true

# default is 2m, can change it if necessary for local dev.
GRPC_LASS_TIMEOUT=

# optional for auth.
# GitHub username and password for the auth token stealer. This GitHub account must
# already have logged into leetcode.com once before.
GH_USERNAME=
GH_PASSWORD=

# optional for auth, can skip
# You must attach the email used for the Github account, as the GitHub page may require a 2FA code.
# As of right now, you must use port 143 as it is configured to use unencrypted IMAP.
#
# TODO - Replace 143 with 993 to be secure.
GH_EMAIL_HOST=
GH_EMAIL_PORT=143
GH_EMAIL_TYPE=IMAP
GH_EMAIL_USERNAME=
GH_EMAIL_PASSWORD=

# required
# This email will be used to send school verification messages. This is separated from Github since
# we only use one official email for sending these messages, but have a variety of GitHub accounts
# between dev, staging, and prod. You must use TLS (port 587) as that is what it is configured for.
# This official email sends school verification messages using TLS (port 587).
CODEBLOOM_EMAIL_HOST=
CODEBLOOM_EMAIL_PORT=587
CODEBLOOM_EMAIL_TYPE=SMTP
Expand All @@ -77,11 +50,18 @@ SECRET_KEY=<changeme>
SERVER_URL=http://localhost:5173

# read by leetcode-auth-service

# leetcode.com username/email and password. LASS logs in with these directly on
# leetcode.com's login form, so they must be LeetCode credentials, not GitHub ones.
LEETCODE_AUTH_USERNAME=
LEETCODE_AUTH_PASSWORD=

REDIS_URL=redis://localhost:6379/0
GPRC_LASS_HOST=localhost:50051
GPRC_LASS_TLS=false
GRPC_LASS_HOST=localhost:50051
GRPC_LASS_TLS=false
# To use staging LASS (must be on VPN), replace the host and TLS values above:
# GRPC_LASS_HOST=stg.codebloom-leetcode-auth-stealer-service.vpn.patinanetwork.org:50051
# GRPC_LASS_TLS=true
GRPC_LASS_TIMEOUT_SECONDS=180
REFRESH_LOCK_TTL_SECONDS=210
REFRESH_CHECK_INTERVAL_SECONDS=900
Expand Down
3 changes: 0 additions & 3 deletions infra/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ FROM mirror.gcr.io/library/eclipse-temurin:25-jre-jammy

WORKDIR /app

COPY mvnw pom.xml ./
COPY .mvn/ .mvn/
RUN ./mvnw -B -ntp exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"
COPY --from=backend-build /app/target/*.jar app.jar

ARG SERVER_PROFILES=prod
Expand Down
Loading
Loading