From 1c9b4848a9694b10e7dc93ec2df0f73258f95c91 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Sat, 13 Jun 2026 18:31:34 +0530 Subject: [PATCH] feat: Add Dockerfiles for jobs/leads services and build scripts Add build-images.yaml for Forgejo CI tmp build.yaml Add Dockerfiles for jobs and leads services Add build-all.sh script for batch building --- .forgejo/workflows/build-images.yaml | 19 +++++ .gitea/workflows/build.yaml | 116 +++++++++++++++++++++++++++ apps/jobs/Dockerfile | 28 +++++++ apps/leads/Dockerfile | 28 +++++++ scripts/build-all.sh | 113 ++++++++++++++++++++++++++ 5 files changed, 304 insertions(+) create mode 100644 .forgejo/workflows/build-images.yaml create mode 100644 .gitea/workflows/build.yaml create mode 100644 apps/jobs/Dockerfile create mode 100644 apps/leads/Dockerfile create mode 100755 scripts/build-all.sh diff --git a/.forgejo/workflows/build-images.yaml b/.forgejo/workflows/build-images.yaml new file mode 100644 index 0000000..1c327c8 --- /dev/null +++ b/.forgejo/workflows/build-images.yaml @@ -0,0 +1,19 @@ +name: build-images + +on: + push: + branches: + - high-performance + +jobs: + gateway: + runs-on: ubuntu-latest + container: + image: registry.nxtgauge.com/rust:alpine + steps: + - name: checkout + run: apk add --no-cache git && git clone --depth 1 http://forgejo-http.forgejo.svc.cluster.local:3000/ashwin/nxtgauge-backend-rust.git /src + - name: build + run: cd /src && cargo build --release --bin gateway + - name: package + run: cp /src/target/release/gateway /gateway && echo "Gateway built" diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..63d94c8 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,116 @@ +name: Build Backend And Update GitOps + +on: + push: + branches: + - main + - high-performance + +jobs: + build: + runs-on: ubuntu-latest + env: + DOCKER_HOST: unix:///var/run/docker.sock + strategy: + fail-fast: false + matrix: + include: + - app_dir: apps/catering_services + image: registry.nxtgauge.com/nxtgauge-rust-catering-services + - app_dir: apps/companies + image: registry.nxtgauge.com/nxtgauge-rust-companies + - app_dir: apps/cron + image: registry.nxtgauge.com/nxtgauge-rust-cron + - app_dir: apps/customers + image: registry.nxtgauge.com/nxtgauge-rust-customers + - app_dir: apps/developers + image: registry.nxtgauge.com/nxtgauge-rust-developers + - app_dir: apps/employees + image: registry.nxtgauge.com/nxtgauge-rust-employees + - app_dir: apps/fitness_trainers + image: registry.nxtgauge.com/nxtgauge-rust-fitness-trainers + - app_dir: apps/gateway + image: registry.nxtgauge.com/nxtgauge-rust-gateway + - app_dir: apps/graphic_designers + image: registry.nxtgauge.com/nxtgauge-rust-graphic-designers + - app_dir: apps/jobs + image: registry.nxtgauge.com/nxtgauge-rust-jobs + - app_dir: apps/job_seekers + image: registry.nxtgauge.com/nxtgauge-rust-job-seekers + - app_dir: apps/leads + image: registry.nxtgauge.com/nxtgauge-rust-leads + - app_dir: apps/makeup_artists + image: registry.nxtgauge.com/nxtgauge-rust-makeup-artists + - app_dir: apps/payments + image: registry.nxtgauge.com/nxtgauge-rust-payments + - app_dir: apps/photographers + image: registry.nxtgauge.com/nxtgauge-rust-photographers + - app_dir: apps/social_media_managers + image: registry.nxtgauge.com/nxtgauge-rust-social-media-managers + - app_dir: apps/tutors + image: registry.nxtgauge.com/nxtgauge-rust-tutors + - app_dir: apps/ugc_content_creators + image: registry.nxtgauge.com/nxtgauge-rust-ugc-content-creators + - app_dir: apps/users + image: registry.nxtgauge.com/nxtgauge-rust-users + - app_dir: apps/video_editors + image: registry.nxtgauge.com/nxtgauge-rust-video-editors + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Docker CLI + run: | + apt-get update + apt-get install -y docker.io + + - name: Log in to registry + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.nxtgauge.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin + + - name: Build and push backend service image + run: | + set -euo pipefail + IMAGE_SHA="${{ matrix.image }}:${{ github.sha }}" + IMAGE_LATEST="${{ matrix.image }}:latest" + docker build -f "${{ matrix.app_dir }}/Dockerfile" -t "${IMAGE_SHA}" -t "${IMAGE_LATEST}" . + docker push "${IMAGE_SHA}" + docker push "${IMAGE_LATEST}" + + update-gitops: + needs: build + runs-on: ubuntu-latest + steps: + - name: Update GitOps backend tags + env: + GITOPS_USERNAME: ${{ secrets.GITOPS_GITHUB_USERNAME || 'Traceworks2023' }} + GITOPS_PASSWORD: ${{ secrets.GITOPS_GITHUB_TOKEN || secrets.GITOPS_PAT }} + GITOPS_REPO: https://github.com/Traceworks2023/nxtgauge-gitops.git + IMAGE_TAG: ${{ github.sha }} + run: | + set -euo pipefail + test -n "${GITOPS_PASSWORD:-}" || { echo "GITOPS_PASSWORD is empty"; exit 1; } + AUTH="$(printf '%s' "${GITOPS_USERNAME}:${GITOPS_PASSWORD}" | base64 -w0)" + TMP_DIR="$(mktemp -d)" + git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" clone --branch main "${GITOPS_REPO}" "${TMP_DIR}" + cd "${TMP_DIR}" + python3 - <<'PY' +from pathlib import Path +import os +path = Path('apps/nxtgauge-backend-rust/overlays/prod/kustomization.yaml') +lines = path.read_text().splitlines() +out = [] +for line in lines: + if line.strip().startswith('newTag:'): + indent = line[:len(line) - len(line.lstrip())] + out.append(f"{indent}newTag: {os.environ['IMAGE_TAG']}") + else: + out.append(line) +path.write_text('\n'.join(out) + '\n') +PY + git config user.name "forgejo-actions" + git config user.email "forgejo-actions@nxtgauge.com" + git add apps/nxtgauge-backend-rust/overlays/prod/kustomization.yaml + git diff --cached --quiet && exit 0 + git commit -m "chore(gitops): update backend images to ${IMAGE_TAG}" + git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push origin main diff --git a/apps/jobs/Dockerfile b/apps/jobs/Dockerfile new file mode 100644 index 0000000..282d968 --- /dev/null +++ b/apps/jobs/Dockerfile @@ -0,0 +1,28 @@ +FROM rust:alpine AS builder + +WORKDIR /usr/src/app + +RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static && \ + rustup target add x86_64-unknown-linux-musl + +COPY Cargo.toml Cargo.lock ./ +COPY crates ./crates +COPY apps ./apps + +ENV RUSTFLAGS='-C target-feature=+crt-static' +ENV OPENSSL_STATIC=1 +ENV OPENSSL_DIR=/usr +RUN cargo build --release --bin jobs --target x86_64-unknown-linux-musl + +FROM alpine:latest AS runtime + +RUN apk add --no-cache ca-certificates + +RUN adduser -D -u 1000 appuser +WORKDIR /app + +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/jobs ./jobs + +USER appuser + +CMD ["./jobs"] diff --git a/apps/leads/Dockerfile b/apps/leads/Dockerfile new file mode 100644 index 0000000..9009c94 --- /dev/null +++ b/apps/leads/Dockerfile @@ -0,0 +1,28 @@ +FROM rust:alpine AS builder + +WORKDIR /usr/src/app + +RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static && \ + rustup target add x86_64-unknown-linux-musl + +COPY Cargo.toml Cargo.lock ./ +COPY crates ./crates +COPY apps ./apps + +ENV RUSTFLAGS='-C target-feature=+crt-static' +ENV OPENSSL_STATIC=1 +ENV OPENSSL_DIR=/usr +RUN cargo build --release --bin leads --target x86_64-unknown-linux-musl + +FROM alpine:latest AS runtime + +RUN apk add --no-cache ca-certificates + +RUN adduser -D -u 1000 appuser +WORKDIR /app + +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/leads ./leads + +USER appuser + +CMD ["./leads"] diff --git a/scripts/build-all.sh b/scripts/build-all.sh new file mode 100755 index 0000000..f79ce65 --- /dev/null +++ b/scripts/build-all.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# build-all.sh - Build all nxtgauge backend services and push to registry +# Usage: ./scripts/build-all.sh [TAG] + +set -e + +REGISTRY="registry.nxtgauge.com" +TAG=${1:-$(git rev-parse --short HEAD)} +DOCKERFILE="Dockerfile.simple" + +echo "============================================" +echo "🚀 NXTGAUGE Full Rebuild Script" +echo "============================================" +echo "Registry: ${REGISTRY}" +echo "Tag: ${TAG}" +echo "Dockerfile: ${DOCKERFILE}" +echo "" + +# Services list with underscores (matching Cargo.toml bin names) +SERVICES=( + "gateway" + "users" + "companies" + "job_seekers" + "customers" + "photographers" + "makeup_artists" + "tutors" + "developers" + "video_editors" + "graphic_designers" + "social_media_managers" + "fitness_trainers" + "catering_services" + "ugc_content_creators" + "employees" + "payments" + "jobs" + "leads" + "cron" +) + +# Also need service names with hyphens for image names +declare -A SERVICE_IMAGE_NAMES=( + ["gateway"]="nxtgauge-rust-gateway" + ["users"]="nxtgauge-rust-users" + ["companies"]="nxtgauge-rust-companies" + ["job_seekers"]="nxtgauge-rust-job-seekers" + ["customers"]="nxtgauge-rust-customers" + ["photographers"]="nxtgauge-rust-photographers" + ["makeup_artists"]="nxtgauge-rust-makeup-artists" + ["tutors"]="nxtgauge-rust-tutors" + ["developers"]="nxtgauge-rust-developers" + ["video_editors"]="nxtgauge-rust-video-editors" + ["graphic_designers"]="nxtgauge-rust-graphic-designers" + ["social_media_managers"]="nxtgauge-rust-social-media-managers" + ["fitness_trainers"]="nxtgauge-rust-fitness-trainers" + ["catering_services"]="nxtgauge-rust-catering-services" + ["ugc_content_creators"]="nxtgauge-rust-ugc-content-creators" + ["employees"]="nxtgauge-rust-employees" + ["payments"]="nxtgauge-rust-payments" + ["jobs"]="nxtgauge-rust-jobs" + ["leads"]="nxtgauge-rust-leads" + ["cron"]="nxtgauge-rust-cron" +) + +TOTAL=${#SERVICES[@]} +CURRENT=0 + +build_service() { + local service=$1 + local image_name=${SERVICE_IMAGE_NAMES[$service]} + local tag="${REGISTRY}/${image_name}:${TAG}" + local latest="${REGISTRY}/${image_name}:latest" + + CURRENT=$((CURRENT + 1)) + echo "" + echo "[$CURRENT/$TOTAL] Building ${image_name}..." + echo " Service: ${service}" + echo " Tag: ${tag}" + + # Build + docker build \ + --build-arg SERVICE_NAME=${service} \ + -f ${DOCKERFILE} \ + -t ${tag} \ + -t ${latest} \ + . 2>&1 | tail -5 + + # Push + echo " Pushing..." + docker push ${tag} + docker push ${latest} + + echo " ✅ ${image_name} complete" +} + +# Build all services +for service in "${SERVICES[@]}"; do + build_service "${service}" +done + +echo "" +echo "============================================" +echo "🎉 All services built and pushed!" +echo "============================================" +echo "Tag used: ${TAG}" +echo "" +echo "Update kustomization.yaml with:" +for service in "${SERVICES[@]}"; do + local image_name=${SERVICE_IMAGE_NAMES[$service]} + echo " ${image_name}: ${TAG}" +done