Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b445d9044a | |||
| 81c93bafc1 | |||
| ba180ae6e1 | |||
| c611c68822 | |||
| 4c2687498f | |||
| 3983049d2c | |||
| 941d857feb | |||
| b686c3673e | |||
| dfd66cde0b |
@@ -0,0 +1,80 @@
|
|||||||
|
# CI Image Builder Workflow
|
||||||
|
# Automatically builds and pushes CI images when dependencies change
|
||||||
|
# Uses GitHub Container Registry (GHCR) or any container registry
|
||||||
|
|
||||||
|
name: CI Image Builder
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
- 'Dockerfile.ci'
|
||||||
|
- '.gitea/workflows/ci-image-builder.yml'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
force_rebuild:
|
||||||
|
description: 'Force rebuild even if no changes detected'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
type: boolean
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Use your existing Docker registry
|
||||||
|
REGISTRY: docker.notsosm.art
|
||||||
|
IMAGE_NAME: euchre-camp-ci-runner
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-ci-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# Skip if this is an auto-generated version bump commit
|
||||||
|
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build CI image
|
||||||
|
run: |
|
||||||
|
docker build \
|
||||||
|
-f Dockerfile.ci \
|
||||||
|
-t ${{ env.IMAGE_NAME }}:latest \
|
||||||
|
-t ${{ env.IMAGE_NAME }}:$(git rev-parse --short HEAD) \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Test CI image
|
||||||
|
run: |
|
||||||
|
docker run --rm \
|
||||||
|
${{ env.IMAGE_NAME }}:latest \
|
||||||
|
sh -c "node --version && npm --version && npx prisma --version"
|
||||||
|
|
||||||
|
- name: Push to registry
|
||||||
|
run: |
|
||||||
|
echo "Pushing to ${{ env.REGISTRY }}..."
|
||||||
|
# Check if we can authenticate to the registry using DOCKER_LOGIN and DOCKER_PASSWORD secrets
|
||||||
|
if [ -n "${{ secrets.DOCKER_LOGIN }}" ] && [ -n "${{ secrets.DOCKER_PASSWORD }}" ]; then
|
||||||
|
if docker login ${{ env.REGISTRY }} -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWORD }} 2>/dev/null; then
|
||||||
|
docker tag ${{ env.IMAGE_NAME }}:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
echo "Successfully pushed CI image to ${{ env.REGISTRY }}"
|
||||||
|
else
|
||||||
|
echo "Warning: Docker login failed with provided credentials"
|
||||||
|
echo "CI image built locally but not pushed to registry"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Warning: DOCKER_LOGIN or DOCKER_PASSWORD secrets not configured"
|
||||||
|
echo "CI image built locally but not pushed to registry"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Show usage instructions
|
||||||
|
run: |
|
||||||
|
echo "CI Image built successfully!"
|
||||||
|
echo ""
|
||||||
|
echo "To use in workflows:"
|
||||||
|
echo " container:"
|
||||||
|
echo " image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
|
||||||
+5
-19
@@ -9,20 +9,15 @@ jobs:
|
|||||||
unit-tests:
|
unit-tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: node:20-alpine
|
image: docker.notsosm.art/euchre-camp-ci-runner:latest
|
||||||
options: --user root
|
options: --user root
|
||||||
|
env:
|
||||||
|
NODE_PATH: /workspace/node_modules
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install system dependencies
|
|
||||||
run: |
|
|
||||||
apk add --no-cache bash git
|
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: npm run test:run
|
run: npm run test:run
|
||||||
|
|
||||||
@@ -30,27 +25,18 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: unit-tests
|
needs: unit-tests
|
||||||
container:
|
container:
|
||||||
image: node:20-alpine
|
image: docker.notsosm.art/euchre-camp-ci-runner:latest
|
||||||
options: --user root
|
options: --user root
|
||||||
env:
|
env:
|
||||||
DATABASE_PROVIDER: sqlite
|
DATABASE_PROVIDER: sqlite
|
||||||
DATABASE_URL: file:./prisma/ci.db
|
DATABASE_URL: file:./prisma/ci.db
|
||||||
BETTER_AUTH_SECRET: test-secret-key-for-ci-only
|
BETTER_AUTH_SECRET: test-secret-key-for-ci-only
|
||||||
|
NODE_PATH: /workspace/node_modules
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install system dependencies
|
|
||||||
run: |
|
|
||||||
apk add --no-cache bash git
|
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Generate Prisma client
|
|
||||||
run: npx prisma generate
|
|
||||||
|
|
||||||
- name: Setup SQLite database
|
- name: Setup SQLite database
|
||||||
run: |
|
run: |
|
||||||
# Create SQLite database file
|
# Create SQLite database file
|
||||||
|
|||||||
@@ -9,21 +9,16 @@ jobs:
|
|||||||
unit-tests:
|
unit-tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: node:20-alpine
|
image: docker.notsosm.art/euchre-camp-ci-runner:latest
|
||||||
options: --user root
|
options: --user root
|
||||||
# Skip if this is an auto-generated version bump commit (handled by release workflow)
|
# Skip if this is an auto-generated version bump commit (handled by release workflow)
|
||||||
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
|
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
|
||||||
|
env:
|
||||||
|
NODE_PATH: /workspace/node_modules
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install system dependencies
|
|
||||||
run: |
|
|
||||||
apk add --no-cache bash git
|
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: npm run test:run
|
run: npm run test:run
|
||||||
|
|||||||
@@ -127,6 +127,26 @@ npm run db:setup-postgres
|
|||||||
DATABASE_PROVIDER=sqlite DATABASE_URL=file:./prisma/ci.db npm run test:acceptance
|
DATABASE_PROVIDER=sqlite DATABASE_URL=file:./prisma/ci.db npm run test:acceptance
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### CI Runner Image
|
||||||
|
|
||||||
|
To speed up CI runs, the project uses a pre-built CI runner image with all dependencies pre-installed.
|
||||||
|
|
||||||
|
**Building the CI image locally:**
|
||||||
|
```bash
|
||||||
|
./scripts/build-ci-image.sh [tag]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Using the CI image:**
|
||||||
|
- Workflows automatically use `ghcr.io/<repo>/ci-runner:latest` when available
|
||||||
|
- Falls back to `node:20-alpine` if image is not found
|
||||||
|
- Image is automatically rebuilt when `package.json` changes
|
||||||
|
|
||||||
|
**CI Image contains:**
|
||||||
|
- Node.js 20 Alpine
|
||||||
|
- All npm dependencies pre-installed
|
||||||
|
- Prisma client pre-generated
|
||||||
|
- System tools (bash, git, python, make, g++)
|
||||||
|
|
||||||
### CI/CD Pipeline
|
### CI/CD Pipeline
|
||||||
The project uses Gitea Actions for continuous integration:
|
The project uses Gitea Actions for continuous integration:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# CI Runner Image for EuchreCamp
|
||||||
|
# Pre-installed with all dependencies to speed up CI runs
|
||||||
|
# This image is rebuilt automatically when package.json changes
|
||||||
|
|
||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
# Install system dependencies needed for various tasks
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
bash \
|
||||||
|
git \
|
||||||
|
curl \
|
||||||
|
python3 \
|
||||||
|
make \
|
||||||
|
g++ \
|
||||||
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files first (for better caching)
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install ALL dependencies including dev dependencies
|
||||||
|
# This is done at image build time, not at CI runtime
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy Prisma schema (needed for Prisma client generation)
|
||||||
|
COPY prisma/schema.prisma ./prisma/
|
||||||
|
|
||||||
|
# Generate Prisma client
|
||||||
|
RUN npx prisma generate
|
||||||
|
|
||||||
|
# Copy the rest of the application
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Set environment variables for CI environment
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV DATABASE_PROVIDER=sqlite
|
||||||
|
ENV DATABASE_URL=file:./prisma/ci.db
|
||||||
|
ENV BETTER_AUTH_SECRET=test-secret-key-for-ci-only
|
||||||
|
|
||||||
|
# Verify installations
|
||||||
|
RUN node --version && npm --version && git --version && npx prisma --version
|
||||||
|
|
||||||
|
# Default command
|
||||||
|
CMD ["/bin/sh"]
|
||||||
@@ -373,6 +373,31 @@ The application uses Gitea Actions for continuous integration and deployment:
|
|||||||
- Docker image building and testing
|
- Docker image building and testing
|
||||||
- Registry push and deployment
|
- Registry push and deployment
|
||||||
|
|
||||||
|
4. **CI Image Builder** (`.gitea/workflows/ci-image-builder.yml`): Runs when dependencies change
|
||||||
|
- Automatically builds CI runner image with all dependencies pre-installed
|
||||||
|
- Triggered by changes to `package.json`, `package-lock.json`, or `Dockerfile.ci`
|
||||||
|
|
||||||
|
### CI Runner Image
|
||||||
|
|
||||||
|
To avoid installing dependencies on every workflow run, we use a pre-built CI runner image:
|
||||||
|
|
||||||
|
**Dockerfile.ci** - Contains:
|
||||||
|
- Node.js 20 Alpine
|
||||||
|
- All npm dependencies pre-installed
|
||||||
|
- Prisma client pre-generated
|
||||||
|
- System tools (bash, git, python, make, g++)
|
||||||
|
|
||||||
|
**Automatic Rebuilding:**
|
||||||
|
- The CI image is automatically rebuilt when `package.json` or `package-lock.json` changes
|
||||||
|
- Images are tagged with commit SHA for traceability
|
||||||
|
- Falls back to `node:20-alpine` if custom image is not available
|
||||||
|
|
||||||
|
**Manual Build:**
|
||||||
|
```bash
|
||||||
|
docker build -f Dockerfile.ci -t euchre-camp-ci:latest .
|
||||||
|
docker run --rm euchre-camp-ci:latest node --version
|
||||||
|
```
|
||||||
|
|
||||||
### Database Strategy for CI
|
### Database Strategy for CI
|
||||||
- **CI Tests**: SQLite database (fast, no server required)
|
- **CI Tests**: SQLite database (fast, no server required)
|
||||||
- **Production**: PostgreSQL (production-like environment)
|
- **Production**: PostgreSQL (production-like environment)
|
||||||
@@ -385,6 +410,9 @@ npm run test:run
|
|||||||
|
|
||||||
# Run acceptance tests with SQLite
|
# Run acceptance tests with SQLite
|
||||||
DATABASE_PROVIDER=sqlite DATABASE_URL=file:./prisma/ci.db npm run test:acceptance
|
DATABASE_PROVIDER=sqlite DATABASE_URL=file:./prisma/ci.db npm run test:acceptance
|
||||||
|
|
||||||
|
# Run tests in CI container (if built)
|
||||||
|
docker run --rm -v $(pwd):/app -w /app euchre-camp-ci:latest npm run test:run
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker Deployment
|
## Docker Deployment
|
||||||
|
|||||||
@@ -173,6 +173,16 @@ pr-validate: lint typecheck test-unit test-acceptance-sqlite
|
|||||||
ci-postgres: lint typecheck test-unit test-acceptance-postgres docker-build
|
ci-postgres: lint typecheck test-unit test-acceptance-postgres docker-build
|
||||||
@echo "CI Pipeline with PostgreSQL completed successfully!"
|
@echo "CI Pipeline with PostgreSQL completed successfully!"
|
||||||
|
|
||||||
|
# --- CI Image ---
|
||||||
|
|
||||||
|
# Build CI runner image locally
|
||||||
|
ci-build:
|
||||||
|
@./scripts/build-ci-image.sh
|
||||||
|
|
||||||
|
# Build CI runner image with custom tag
|
||||||
|
ci-build-tag TAG:
|
||||||
|
@./scripts/build-ci-image.sh {{TAG}}
|
||||||
|
|
||||||
# --- Utilities ---
|
# --- Utilities ---
|
||||||
|
|
||||||
# Show help information
|
# Show help information
|
||||||
|
|||||||
Executable
+44
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Build and test the CI runner image locally
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
IMAGE_NAME="euchre-camp-ci-runner"
|
||||||
|
TAG="${1:-latest}"
|
||||||
|
|
||||||
|
echo "Building CI runner image..."
|
||||||
|
echo "Image: ${IMAGE_NAME}:${TAG}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Build the image
|
||||||
|
docker build \
|
||||||
|
-f Dockerfile.ci \
|
||||||
|
-t ${IMAGE_NAME}:${TAG} \
|
||||||
|
.
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "✅ Image built successfully!"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test the image
|
||||||
|
echo "Testing CI image..."
|
||||||
|
docker run --rm ${IMAGE_NAME}:${TAG} sh -c "
|
||||||
|
echo 'Node.js version:' && node --version
|
||||||
|
echo 'npm version:' && npm --version
|
||||||
|
echo 'Git version:' && git --version
|
||||||
|
echo 'Prisma version:' && npx prisma --version
|
||||||
|
echo ''
|
||||||
|
echo 'Installed packages (top 10):'
|
||||||
|
npm list --depth=0 | head -10
|
||||||
|
"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "✅ CI image is ready to use!"
|
||||||
|
echo ""
|
||||||
|
echo "To use in GitHub Actions/Gitea Actions:"
|
||||||
|
echo " container:"
|
||||||
|
echo " image: docker.notsosm.art/${IMAGE_NAME}:${TAG}"
|
||||||
|
echo ""
|
||||||
|
echo "To push to registry:"
|
||||||
|
echo " docker tag ${IMAGE_NAME}:${TAG} docker.notsosm.art/${IMAGE_NAME}:${TAG}"
|
||||||
|
echo " docker push docker.notsosm.art/${IMAGE_NAME}:${TAG}"
|
||||||
Reference in New Issue
Block a user