feat: SDLC database separation for CI/testing (#35)
## Summary - Fix `isProductionDatabase()` to allow CI database (`euchre_camp_ci`) - Add database schema reset before CI test runs - Create `global.teardown.ts` for cleanup (CI: full reset, dev/prod: selective cleanup) - Add `acceptance-tests` job to PR workflow with CI database - Create `sync-prod-to-dev.js` script for one-way prod→dev sync - Add `just` recipes: `sync-dev`, `test-prod`, `reset-ci-db` - Store credentials in `.credentials` (gitignored) with unique CI user ## Testing Verified against CI database: - Schema reset works - Migrations apply correctly - Test users created successfully - 219 tests pass (slow but working) ## Next Steps - Set `CI_DATABASE_URL` as Gitea repository variable Reviewed-on: #35 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #35.
This commit is contained in:
@@ -5,14 +5,14 @@ on:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'Dockerfile.ci-base'
|
||||
- 'package.json'
|
||||
- 'bun.lock'
|
||||
- '.gitea/workflows/build-ci-images.yml'
|
||||
- "Dockerfile.ci-base"
|
||||
- "package.json"
|
||||
- "bun.lock"
|
||||
- ".gitea/workflows/build-ci-images.yml"
|
||||
schedule:
|
||||
# Weekly rebuild to get latest Playwright/Bun versions
|
||||
- cron: '0 2 * * 0' # Every Sunday at 2 AM
|
||||
workflow_dispatch: # Manual trigger
|
||||
- cron: "0 2 * * 0" # Every Sunday at 2 AM
|
||||
workflow_dispatch: # Manual trigger
|
||||
|
||||
env:
|
||||
REGISTRY: docker.notsosm.art
|
||||
@@ -24,32 +24,32 @@ jobs:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
|
||||
- name: Login to Registry
|
||||
run: |
|
||||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u ${{ secrets.DOCKER_LOGIN }} --password-stdin
|
||||
|
||||
|
||||
- name: Extract metadata for CI base image
|
||||
id: meta
|
||||
run: |
|
||||
# Get Playwright version from package.json
|
||||
PLAYWRIGHT_VERSION=$(grep -o '"@playwright/test": "[^"]*"' package.json | cut -d'"' -f4)
|
||||
PLAYWRIGHT_VERSION=$(grep -o '"@playwright/test": "[^"]*"' package.json | cut -d'"' -f4 | sed 's/^\^//')
|
||||
echo "playwright_version=${PLAYWRIGHT_VERSION}" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
# Get Bun version (latest)
|
||||
BUN_VERSION=$(bun --version 2>/dev/null || echo "latest")
|
||||
echo "bun_version=${BUN_VERSION}" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
# Set tags
|
||||
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:playwright-${PLAYWRIGHT_VERSION},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:${{ github.sha }}" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
- name: Build and push CI base image
|
||||
run: |
|
||||
# Build with multiple tags
|
||||
@@ -58,14 +58,9 @@ jobs:
|
||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:latest \
|
||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:playwright-${{ steps.meta.outputs.playwright_version }} \
|
||||
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:${{ github.sha }} \
|
||||
.
|
||||
|
||||
# Push all tags
|
||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:latest
|
||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:playwright-${{ steps.meta.outputs.playwright_version }}
|
||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ci-base:${{ github.sha }}
|
||||
|
||||
|
||||
- name: Clean up
|
||||
if: always()
|
||||
run: |
|
||||
docker logout ${{ env.REGISTRY }}
|
||||
docker logout ${{ env.REGISTRY }}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
name: Deploy Production
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version tag to deploy (e.g., v0.1.21)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
env:
|
||||
REGISTRY: docker.notsosm.art
|
||||
IMAGE_NAME: euchre-camp
|
||||
PROD_APPS_PATH: /apps/youthful_simon
|
||||
|
||||
jobs:
|
||||
deploy-prod:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: docker.notsosm.art/euchre-camp/ci-base:latest
|
||||
options: --user root
|
||||
|
||||
steps:
|
||||
- name: Deploy to production
|
||||
run: |
|
||||
VERSION="${{ inputs.version }}"
|
||||
COMPOSE_FILE="${{ env.PROD_APPS_PATH }}/docker-compose.yml"
|
||||
|
||||
echo "Deploying ${VERSION} to production..."
|
||||
|
||||
# Update prod compose file with the release tag
|
||||
# Note: Standardizing to docker.notsosm.art registry
|
||||
sed -i "s|image: euchre-camp/euchre-camp:[a-zA-Z0-9.-]*|image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}|" ${COMPOSE_FILE}
|
||||
sed -i "s|image: docker.notsosm.art/euchre-camp:[a-zA-Z0-9.-]*|image: docker.notsosm.art/euchre-camp:${VERSION}|" ${COMPOSE_FILE}
|
||||
|
||||
# Pull and restart the prod container
|
||||
cd ${{ env.PROD_APPS_PATH }}
|
||||
docker compose pull app
|
||||
docker compose up -d app
|
||||
|
||||
# Wait for production site to be healthy
|
||||
echo "Waiting for production site to be healthy..."
|
||||
for i in {1..30}; do
|
||||
if curl -sf https://euchre.notsosm.art/api/health > /dev/null 2>&1; then
|
||||
echo "✅ Production successfully deployed with version ${VERSION}"
|
||||
exit 0
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
echo "❌ Production deployment failed"
|
||||
docker compose logs app
|
||||
exit 1
|
||||
+55
-12
@@ -5,6 +5,10 @@ on:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
REGISTRY: docker.notsosm.art
|
||||
IMAGE_NAME: euchre-camp
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -16,9 +20,6 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Clear Bun cache
|
||||
run: bun pm cache rm || true
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
@@ -30,7 +31,7 @@ jobs:
|
||||
- name: Run unit tests
|
||||
run: bun test src/__tests__/unit/ src/__tests__/*.test.tsx src/__tests__/auth-simple.test.ts
|
||||
|
||||
e2e-tests:
|
||||
build-and-deploy-ci:
|
||||
runs-on: ubuntu-latest
|
||||
needs: unit-tests
|
||||
container:
|
||||
@@ -41,9 +42,6 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Clear Bun cache
|
||||
run: bun pm cache rm || true
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
@@ -52,15 +50,60 @@ jobs:
|
||||
env:
|
||||
DATABASE_URL: postgresql://user:pass@localhost:5432/dummy
|
||||
|
||||
- name: Run E2E tests
|
||||
run: npm run test:acceptance:cucumber:prod
|
||||
- name: Extract PR number and commit info
|
||||
id: info
|
||||
run: |
|
||||
echo "pr_number=$(echo $GITHUB_REF | grep -oP 'refs/pull/\K[0-9]+')" >> $GITHUB_OUTPUT
|
||||
echo "short_sha=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build Docker image for PR
|
||||
run: |
|
||||
IMAGE_TAG="pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }}"
|
||||
docker build \
|
||||
--target runner \
|
||||
--build-arg GIT_COMMIT=$GITHUB_SHA \
|
||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} \
|
||||
.
|
||||
|
||||
- name: Update CI site compose and restart
|
||||
run: |
|
||||
IMAGE_TAG="pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }}"
|
||||
COMPOSE_FILE="/apps/euchre_camp_ci/docker-compose.yml"
|
||||
|
||||
# Update the image tag in the compose file
|
||||
sed -i "s|image: docker.notsosm.art/euchre-camp:[a-zA-Z0-9.-]*|image: docker.notsosm.art/euchre-camp:${IMAGE_TAG}|" ${COMPOSE_FILE}
|
||||
|
||||
# Pull the new image and restart the CI stack
|
||||
cd /apps/euchre_camp_ci
|
||||
docker compose pull app
|
||||
docker compose up -d app
|
||||
|
||||
- name: Wait for CI site to be healthy
|
||||
run: |
|
||||
for i in {1..30}; do
|
||||
if curl -sf https://euchre-ci.notsosm.art/api/health > /dev/null 2>&1; then
|
||||
echo "CI site is healthy"
|
||||
exit 0
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
echo "CI site failed to become healthy after 15 seconds"
|
||||
docker compose -f /apps/euchre_camp_ci/docker-compose.yml logs app
|
||||
exit 1
|
||||
|
||||
- name: Run acceptance tests
|
||||
run: DATABASE_URL="${{ secrets.CI_DATABASE_URL }}" bun test:acceptance
|
||||
env:
|
||||
DATABASE_URL: postgresql://euchre_camp:${{ secrets.DB_PASSWORD }}@dhg.lol:5432/euchre_camp_dev
|
||||
DATABASE_PROVIDER: postgresql
|
||||
CI: true
|
||||
|
||||
- name: Cleanup PR images
|
||||
if: always()
|
||||
run: |
|
||||
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ steps.info.outputs.pr_number }}-${{ steps.info.outputs.short_sha }} || true
|
||||
|
||||
analyze-bump-type:
|
||||
runs-on: ubuntu-latest
|
||||
needs: e2e-tests
|
||||
needs: unit-tests
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
|
||||
@@ -163,32 +163,26 @@ jobs:
|
||||
if: steps.commit.outputs.committed == 'true'
|
||||
run: |
|
||||
echo "Deploying version ${{ steps.version.outputs.new_version }} to dev environment..."
|
||||
|
||||
# Update docker-compose.yml with new image tag using full registry path
|
||||
# The registry is docker.notsosm.art and image is euchre-camp
|
||||
|
||||
# Update dev compose file with new image tag
|
||||
IMAGE_TAG="${{ steps.version.outputs.new_version }}"
|
||||
sed -i "s|image: docker.notsosm.art/euchre-camp:[0-9.]*|image: docker.notsosm.art/euchre-camp:${IMAGE_TAG}|" docker-compose.yml
|
||||
|
||||
# Copy the updated docker-compose.yml to the deployment location
|
||||
# The runners are on the same Docker server where the container is running
|
||||
sudo mkdir -p /home/euchre_camp
|
||||
sudo cp docker-compose.yml /home/euchre_camp/
|
||||
sudo chown -R euchre:euchre /home/euchre_camp
|
||||
|
||||
COMPOSE_FILE="/apps/intelligent_silasak/docker-compose.yml"
|
||||
sed -i "s|image: docker.notsosm.art/euchre-camp:[a-zA-Z0-9.-]*|image: docker.notsosm.art/euchre-camp:${IMAGE_TAG}|" ${COMPOSE_FILE}
|
||||
|
||||
# Pull and restart the dev container
|
||||
cd /home/euchre_camp
|
||||
docker-compose pull app
|
||||
docker-compose up -d app
|
||||
|
||||
cd /apps/intelligent_silasak
|
||||
docker compose pull app
|
||||
docker compose up -d app
|
||||
|
||||
# Wait for container to be healthy
|
||||
echo "Waiting for container to start..."
|
||||
sleep 10
|
||||
|
||||
# Check if container is running
|
||||
if docker ps --filter "name=euchre-camp-app" --format "{{.Status}}" | grep -q "Up"; then
|
||||
echo "✅ Dev environment successfully deployed with version ${{ steps.version.outputs.new_version }}"
|
||||
else
|
||||
echo "❌ Dev environment deployment failed"
|
||||
docker-compose logs app
|
||||
exit 1
|
||||
fi
|
||||
echo "Waiting for dev site to be healthy..."
|
||||
for i in {1..30}; do
|
||||
if curl -sf https://euchre-dev.notsosm.art/api/health > /dev/null 2>&1; then
|
||||
echo "✅ Dev environment successfully deployed with version ${{ steps.version.outputs.new_version }}"
|
||||
exit 0
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
echo "❌ Dev environment deployment failed"
|
||||
docker compose logs app
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user