sharenet/.forgejo/workflows/ci.yml
continuist 6624c2a340
Some checks are pending
CI/CD Pipeline with Secure Ephemeral PiP / test-backend (push) Waiting to run
CI/CD Pipeline with Secure Ephemeral PiP / test-frontend (push) Blocked by required conditions
CI/CD Pipeline with Secure Ephemeral PiP / build-backend (push) Blocked by required conditions
CI/CD Pipeline with Secure Ephemeral PiP / build-frontend (push) Blocked by required conditions
CI/CD Pipeline with Secure Ephemeral PiP / cleanup (push) Blocked by required conditions
Security improvements #1
2025-09-04 22:15:49 -04:00

183 lines
No EOL
5.6 KiB
YAML

name: CI/CD Pipeline with Secure Ephemeral PiP
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
REGISTRY: ${{ secrets.REGISTRY_HOST }}
APP_NAME: ${{ secrets.APP_NAME }}
IMAGE_TAG: ${{ github.sha }}
RUN_ID: ${{ github.run_id }}
jobs:
test-backend:
runs-on: [self-hosted, ci]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ephemeral PiP container
run: |
chmod +x ./secure_pip_setup.sh
./secure_pip_setup.sh
- name: Wait for PiP readiness
run: |
chmod +x ./pip_ready.sh
./pip_ready.sh
- name: Setup SSH with pinned known_hosts
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Create integration test network
run: |
podman exec ci-pip-$RUN_ID podman network create integ-$RUN_ID
- name: Start PostgreSQL on internal network
run: |
podman exec ci-pip-$RUN_ID podman run -d \
--name test-postgres \
--network integ-$RUN_ID \
-e POSTGRES_PASSWORD=testpassword \
-e POSTGRES_USER=testuser \
-e POSTGRES_DB=testdb \
postgres:15-alpine
- name: Wait for PostgreSQL to be ready
run: |
podman exec ci-pip-$RUN_ID timeout 60 bash -c 'until podman exec test-postgres pg_isready -h test-postgres -p 5432 -U testuser; do sleep 1; done'
- name: Run backend unit tests
run: |
podman exec ci-pip-$RUN_ID podman run --rm \
-v $(pwd):/workspace \
-w /workspace \
rust:latest \
sh -c "cargo test --lib -- --test-threads=1"
- name: Run backend integration tests
run: |
podman exec ci-pip-$RUN_ID podman run --rm \
-v $(pwd):/workspace \
-w /workspace \
-e DATABASE_URL=postgres://testuser:testpassword@test-postgres:5432/testdb \
rust:latest \
sh -c "cargo test --test '*' -- --test-threads=1"
- name: Cleanup test resources
if: always()
run: |
podman exec ci-pip-$RUN_ID podman stop test-postgres 2>/dev/null || true
podman exec ci-pip-$RUN_ID podman rm test-postgres 2>/dev/null || true
podman exec ci-pip-$RUN_ID podman network rm integ-$RUN_ID 2>/dev/null || true
test-frontend:
runs-on: [self-hosted, ci]
needs: test-backend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ephemeral PiP container
run: |
chmod +x ./secure_pip_setup.sh
./secure_pip_setup.sh
- name: Wait for PiP readiness
run: |
chmod +x ./pip_ready.sh
./pip_ready.sh
- name: Run frontend tests in PiP
run: |
podman exec ci-pip-$RUN_ID podman run --rm \
-v $(pwd):/workspace \
-w /workspace \
node:20 \
sh -c "npm ci && npm run test"
build-backend:
runs-on: [self-hosted, ci]
needs: test-frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ephemeral PiP container
run: |
chmod +x ./secure_pip_setup.sh
./secure_pip_setup.sh
- name: Wait for PiP readiness
run: |
chmod +x ./pip_ready.sh
./pip_ready.sh
- name: Login to Forgejo Container Registry securely
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | podman exec -i ci-pip-$RUN_ID podman login ${{ secrets.REGISTRY_HOST }} \
-u ${{ secrets.REGISTRY_USERNAME }} \
--password-stdin
- name: Build backend image
run: |
podman exec ci-pip-$RUN_ID podman build \
-t ${{ secrets.REGISTRY_HOST }}/${{ secrets.APP_NAME }}/backend:${{ github.sha }} \
-f Dockerfile.backend .
- name: Push backend image
run: |
podman exec ci-pip-$RUN_ID podman push \
${{ secrets.REGISTRY_HOST }}/${{ secrets.APP_NAME }}/backend:${{ github.sha }}
build-frontend:
runs-on: [self-hosted, ci]
needs: test-frontend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ephemeral PiP container
run: |
chmod +x ./secure_pip_setup.sh
./secure_pip_setup.sh
- name: Wait for PiP readiness
run: |
chmod +x ./pip_ready.sh
./pip_ready.sh
- name: Login to Forgejo Container Registry securely
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | podman exec -i ci-pip-$RUN_ID podman login ${{ secrets.REGISTRY_HOST }} \
-u ${{ secrets.REGISTRY_USERNAME }} \
--password-stdin
- name: Build frontend image
run: |
podman exec ci-pip-$RUN_ID podman build \
-t ${{ secrets.REGISTRY_HOST }}/${{ secrets.APP_NAME }}/frontend:${{ github.sha }} \
-f Dockerfile.frontend .
- name: Push frontend image
run: |
podman exec ci-pip-$RUN_ID podman push \
${{ secrets.REGISTRY_HOST }}/${{ secrets.APP_NAME }}/frontend:${{ github.sha }}
cleanup:
runs-on: [self-hosted, ci]
needs: [build-backend, build-frontend]
if: always()
steps:
- name: Cleanup PiP container and socket
run: |
podman rm -f ci-pip-$RUN_ID 2>/dev/null || true
rm -f ${XDG_RUNTIME_DIR}/podman-host/podman.sock 2>/dev/null || true