Skip to content

Commit 78c8e57

Browse files
committed
Enhance Dockerfile and Build Workflow
- Added support for versioning in Dockerfiles by introducing a build argument `VERSION`, which is set as an environment variable `APP_VERSION` for runtime access. - Updated the build-and-push workflow to inject the version during the Docker image build process, improving traceability of deployed images. - Enhanced logging in the `start.sh` script to provide detailed output during container startup, including dependency checks and migration status. - Added new lines for consistency across multiple files, adhering to coding standards.
1 parent 859368a commit 78c8e57

18 files changed

Lines changed: 77 additions & 8 deletions

.github/workflows/build-and-push.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,23 @@ jobs:
5353
docker buildx build \
5454
--platform linux/amd64 \
5555
-f ${{ steps.extract.outputs.DOCKERFILE }} \
56+
--build-arg VERSION=${{ steps.extract.outputs.VERSION }} \
5657
-t ${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/github-scraper/${{ steps.extract.outputs.SERVICE }}:${{ steps.extract.outputs.VERSION }} \
5758
-t ${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/github-scraper/${{ steps.extract.outputs.SERVICE }}:latest \
5859
--push \
5960
./backend
61+
echo "✅ Image built and pushed: ${{ steps.extract.outputs.SERVICE }}:${{ steps.extract.outputs.VERSION }}"
62+
echo " Version injected via build arg: ${{ steps.extract.outputs.VERSION }}"
6063
6164
- name: Cleanup old images
62-
if: success() # Only run if build succeeded
65+
if: success() # Only run if build succeeded
6366
run: |
6467
# Cleanup old images (keeps last 3 versions + latest + deployed version)
6568
export PROJECT_ID=${{ secrets.PROJECT_ID }}
6669
export REGION=${{ secrets.GCP_REGION }}
6770
export REPOSITORY=github-scraper
6871
./scripts/utils/cleanup-old-images.sh ${{ steps.extract.outputs.SERVICE }} --execute
69-
continue-on-error: true # Don't fail workflow if cleanup fails
72+
continue-on-error: true # Don't fail workflow if cleanup fails
7073

7174
- name: Trigger deployment in infra repo
7275
run: |
@@ -82,4 +85,3 @@ jobs:
8285
}
8386
}'
8487
echo "✅ Deployment triggered for ${{ steps.extract.outputs.SERVICE }}:${{ steps.extract.outputs.VERSION }}"
85-

DOCKER_IMAGE_CLEANUP_PLAN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,4 @@ gcloud run jobs describe ${SERVICE} \
398398

399399
**Cost Savings**: Prevents unbounded storage growth, saves ~$0.36-0.96/month as versions accumulate
400400

401+

backend/Dockerfile.cloudrun-commit-worker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ CMD ["sh", "-c", "npx prisma migrate deploy && npm run start:cloudrun-commit-wor
5050

5151

5252

53+

backend/Dockerfile.cloudrun-user-worker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ CMD ["sh", "-c", "npx prisma migrate deploy && npm run start:cloudrun-user-worke
4646

4747

4848

49+

backend/Dockerfile.commit-worker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ CMD ["sh", "-c", "npx prisma migrate deploy && npm run start:commit-worker"]
4949

5050

5151

52+

backend/Dockerfile.prod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ RUN npx prisma generate && npm run build
2727
# Production stage
2828
FROM node:22.11.0-alpine
2929

30+
# Accept version as build argument
31+
ARG VERSION
32+
# Set as environment variable so it's available at runtime
33+
ENV APP_VERSION=${VERSION}
34+
3035
WORKDIR /app
3136

3237
# Install git and other required tools for git operations

backend/Dockerfile.user-worker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ CMD ["sh", "-c", "npx prisma migrate deploy && npm run start:user-worker"]
4646

4747

4848

49+

backend/prisma/migrations/20250101000000_add_commit_data_and_two_worker_states/migration.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ ALTER TABLE "CommitData" ADD CONSTRAINT "CommitData_repositoryId_fkey" FOREIGN K
3232

3333

3434

35+

backend/scripts/cleanupQueueKeepSpecificRepo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,4 @@ cleanupQueueKeepSpecificRepo();
188188

189189

190190

191+

backend/scripts/refreshContributors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ main();
5757

5858

5959

60+

0 commit comments

Comments
 (0)