238 lines
8.3 KiB
YAML
238 lines
8.3 KiB
YAML
name: API Gateway CI
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
push:
|
|
branches: [main, deploy-notification-service]
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: oudelaa-api-ci-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
quality-and-tests:
|
|
name: Build, lint, and test
|
|
runs-on: ghaymah2
|
|
container:
|
|
image: node:20-bookworm
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 20
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
cache: npm
|
|
|
|
- name: Verify Node.js 20
|
|
run: node -e "if (process.versions.node.split('.')[0] !== '20') process.exit(1)"
|
|
|
|
- name: Install locked dependencies
|
|
run: npm ci
|
|
|
|
- name: Install MongoDB for isolated replica-set tests
|
|
run: |
|
|
apt-get update
|
|
apt-get install --yes ca-certificates curl gnupg ffmpeg
|
|
curl --fail --silent --show-error https://pgp.mongodb.com/server-7.0.asc | gpg --dearmor --output /usr/share/keyrings/mongodb-server-7.0.gpg
|
|
echo "deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" > /etc/apt/sources.list.d/mongodb-org-7.0.list
|
|
apt-get update
|
|
apt-get install --yes mongodb-org-server
|
|
|
|
- name: Build API Gateway and project artifacts
|
|
run: npm run build
|
|
|
|
- name: Lint
|
|
run: npm run lint
|
|
|
|
- name: Unit and coverage tests
|
|
run: npm run test:coverage
|
|
|
|
- name: Performance tooling tests
|
|
run: npm run test:perf
|
|
|
|
- name: Feed query and hydration regression checks
|
|
run: npm run perf:isolated -- --database-only --posts 6000 --output ci-feed-query-plans.json
|
|
|
|
- name: End-to-end tests on isolated MongoDB replica sets
|
|
run: npm run test:e2e
|
|
|
|
- name: Install locked dashboard dependencies
|
|
working-directory: oudelaa_dashboard
|
|
run: npm ci
|
|
|
|
- name: Build dashboard
|
|
working-directory: oudelaa_dashboard
|
|
run: npm run build
|
|
|
|
- name: Test dashboard
|
|
working-directory: oudelaa_dashboard
|
|
run: npm test
|
|
|
|
- name: Dependency security audit
|
|
run: npm audit --audit-level=high
|
|
|
|
verify-image:
|
|
name: Build API Gateway image
|
|
needs: quality-and-tests
|
|
runs-on: ghaymah2
|
|
container:
|
|
image: docker.gitea.com/runner-images:ubuntu-22.04
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Verify Docker runner access
|
|
run: docker info
|
|
|
|
- name: Build CI image locally
|
|
run: docker build --build-arg BUILD_REVISION=${{ github.sha }} --build-arg BUILD_IMAGE=oudelaa-api:${{ github.sha }} --tag oudelaa-api:${{ github.sha }} .
|
|
|
|
- name: Verify image entrypoint and media tools
|
|
run: |
|
|
docker image inspect oudelaa-api:${{ github.sha }} --format '{{json .Config.Cmd}}' | grep -F 'dist/apps/api-gateway/apps/api-gateway/src/main.js'
|
|
docker run --rm --entrypoint ffmpeg oudelaa-api:${{ github.sha }} -version
|
|
docker run --rm --entrypoint ffprobe oudelaa-api:${{ github.sha }} -version
|
|
|
|
- name: Check GitPasha Container Registry is enabled
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
REGISTRY_USER: ${{ vars.GITPASHA_REGISTRY_USER }}
|
|
REGISTRY_TOKEN: ${{ secrets.GITPASHA_PACKAGES_TOKEN }}
|
|
run: |
|
|
test -n "$REGISTRY" && test -n "$REGISTRY_USER" && test -n "$REGISTRY_TOKEN"
|
|
status=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' "https://${REGISTRY}/v2/")
|
|
case "$status" in
|
|
200|401) echo "Registry endpoint is available (HTTP $status)" ;;
|
|
*) echo "Registry endpoint unavailable (HTTP $status). Enable the GitPasha Container Registry before publishing." >&2; exit 1 ;;
|
|
esac
|
|
|
|
- name: Log in to GitPasha Container Registry
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
REGISTRY_USER: ${{ vars.GITPASHA_REGISTRY_USER }}
|
|
REGISTRY_TOKEN: ${{ secrets.GITPASHA_PACKAGES_TOKEN }}
|
|
run: printf '%s' "$REGISTRY_TOKEN" | docker login "$REGISTRY" --username "$REGISTRY_USER" --password-stdin
|
|
|
|
- name: Push verified image with commit SHA tag
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
IMAGE_OWNER: ${{ github.repository_owner }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
owner=$(printf '%s' "$IMAGE_OWNER" | tr '[:upper:]' '[:lower:]')
|
|
image="${REGISTRY}/${owner}/oudelaa-api:${COMMIT_SHA}"
|
|
docker tag "oudelaa-api:${COMMIT_SHA}" "$image"
|
|
docker push "$image"
|
|
echo "Published $image"
|
|
|
|
- name: Verify published image can be pulled
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
IMAGE_OWNER: ${{ github.repository_owner }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
owner=$(printf '%s' "$IMAGE_OWNER" | tr '[:upper:]' '[:lower:]')
|
|
image="${REGISTRY}/${owner}/oudelaa-api:${COMMIT_SHA}"
|
|
docker image rm "$image"
|
|
docker pull "$image"
|
|
docker image inspect "$image" --format '{{json .Config.Cmd}}' | grep -F 'dist/apps/api-gateway/apps/api-gateway/src/main.js'
|
|
|
|
notification-image:
|
|
name: Build Notification Service image
|
|
needs: quality-and-tests
|
|
runs-on: ghaymah2
|
|
container:
|
|
image: docker.gitea.com/runner-images:ubuntu-22.04
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Verify Docker runner access
|
|
run: docker info
|
|
|
|
- name: Build Notification Service Docker image
|
|
run: |
|
|
docker build \
|
|
--file Dockerfile.notification \
|
|
--tag oudelaa-notification-service:${{ github.sha }} \
|
|
.
|
|
|
|
- name: Verify Notification Service entrypoint
|
|
run: |
|
|
docker image inspect \
|
|
oudelaa-notification-service:${{ github.sha }} \
|
|
--format '{{json .Config.Cmd}}' \
|
|
| grep -F 'notification-service'
|
|
|
|
- name: Check registry credentials
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
REGISTRY_USER: ${{ vars.GITPASHA_REGISTRY_USER }}
|
|
REGISTRY_TOKEN: ${{ secrets.GITPASHA_PACKAGES_TOKEN }}
|
|
run: |
|
|
test -n "$REGISTRY"
|
|
test -n "$REGISTRY_USER"
|
|
test -n "$REGISTRY_TOKEN"
|
|
|
|
- name: Log in to GitPasha Container Registry
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
REGISTRY_USER: ${{ vars.GITPASHA_REGISTRY_USER }}
|
|
REGISTRY_TOKEN: ${{ secrets.GITPASHA_PACKAGES_TOKEN }}
|
|
run: |
|
|
printf '%s' "$REGISTRY_TOKEN" |
|
|
docker login "$REGISTRY" \
|
|
--username "$REGISTRY_USER" \
|
|
--password-stdin
|
|
|
|
- name: Publish Notification Service image
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
IMAGE_OWNER: ${{ github.repository_owner }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
owner=$(printf '%s' "$IMAGE_OWNER" | tr '[:upper:]' '[:lower:]')
|
|
image="${REGISTRY}/${owner}/oudelaa-notification-service:${COMMIT_SHA}"
|
|
|
|
docker tag \
|
|
"oudelaa-notification-service:${COMMIT_SHA}" \
|
|
"$image"
|
|
|
|
docker push "$image"
|
|
|
|
echo "Published $image"
|
|
|
|
- name: Verify published image can be pulled
|
|
if: github.event_name == 'workflow_dispatch'
|
|
env:
|
|
REGISTRY: ${{ vars.GITPASHA_REGISTRY }}
|
|
IMAGE_OWNER: ${{ github.repository_owner }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
owner=$(printf '%s' "$IMAGE_OWNER" | tr '[:upper:]' '[:lower:]')
|
|
image="${REGISTRY}/${owner}/oudelaa-notification-service:${COMMIT_SHA}"
|
|
|
|
docker image rm "$image"
|
|
docker pull "$image"
|
|
docker image inspect "$image" --format '{{json .Config.Cmd}}' |
|
|
grep -F 'notification-service'
|
|
|
|
echo "Verified $image"
|
|
|
|
|