feat: build test-capable image, run tests, then build production image
Release / build-and-test (push) Has been cancelled

This commit is contained in:
2026-03-31 19:27:59 -07:00
parent d39172ca44
commit 9416159712
2 changed files with 60 additions and 34 deletions
+38 -33
View File
@@ -6,11 +6,11 @@ on:
- main
env:
REGISTRY: euchre-camp
REGISTRY: docker.notsosm.art
IMAGE_NAME: euchre-camp
jobs:
release:
build-and-test:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
@@ -20,18 +20,6 @@ jobs:
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test:run
- name: Get current version
id: version
run: |
@@ -40,33 +28,50 @@ jobs:
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test-capable image
run: |
docker build \
--target test-runner \
--build-arg GIT_COMMIT=${{ github.sha }} \
-t ${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.version }} \
.
- name: Run tests inside test-capable container
run: |
docker run --rm \
-e DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" \
${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.version }} \
npm run test:run
- name: Build production image
run: |
docker build \
--target runner \
--build-arg GIT_COMMIT=${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
.
- name: Configure Git
run: |
git config user.name "Gitea Actions"
git config user.email "actions@gitea.com"
- name: Create git tag for release
run: |
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
# Build with docker.notsosm.art registry
docker build \
--build-arg GIT_COMMIT=${{ github.sha }} \
-t docker.notsosm.art/euchre-camp:${{ steps.version.outputs.version }} \
-t docker.notsosm.art/euchre-camp:latest \
.
- name: Push Docker images
run: |
# Push to docker.notsosm.art registry
echo "Pushing to docker.notsosm.art..."
docker push docker.notsosm.art/euchre-camp:${{ steps.version.outputs.version }}
docker push docker.notsosm.art/euchre-camp:latest
echo "Pushing to ${{ env.REGISTRY }}..."
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Deploy to dev (placeholder)
run: |
echo "Deploying version ${{ steps.version.outputs.new_version }} to dev environment..."
echo "Deploying version ${{ steps.version.outputs.version }} to dev environment..."
# TODO: Add actual deployment steps
# Example: SSH to dev server and update container
# ssh user@dev-server "cd /path/to/app && docker compose pull && docker compose up -d"
+22 -1
View File
@@ -26,7 +26,28 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma genera
ARG GIT_COMMIT=unknown
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" NEXT_PUBLIC_GIT_COMMIT=$GIT_COMMIT npm run build
# Stage 2: Runner
# Stage 2: Test runner (includes dev dependencies for testing)
FROM node:20-alpine AS test-runner
# Install dependencies
RUN apk add --no-cache python3 make g++ git
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install ALL dependencies (including dev dependencies for testing)
RUN npm ci
# Copy source code
COPY . .
# Generate Prisma client
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
# Stage 3: Production runner
FROM node:20-alpine AS runner
# Install dumb-init for proper signal handling