From 86a564626e16fa69fd96fa11c74776728ca9a09d Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 18 Nov 2026 05:18:21 +0000 Subject: [PATCH 1/3] ci: verify application and publish container images --- .github/workflows/ci.yml | 75 ++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 552a369..df79996 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,7 @@ on: jobs: build-and-test: runs-on: ubuntu-latest + container: node:20-bookworm services: postgres: image: postgres:16-alpine @@ -16,29 +17,20 @@ jobs: POSTGRES_DB: calendar_run_test POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - ports: - - 5432:5432 options: >- --health-cmd "pg_isready -U postgres -d calendar_run_test" - --health-interval 10s + --health-interval 5s --health-timeout 5s - --health-retries 5 + --health-retries 10 steps: - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 with: - node-version: "20" - cache: "npm" - cache-dependency-path: | - backend/package-lock.json - frontend/package-lock.json - + persist-credentials: false - name: Backend — install, build, test working-directory: backend env: NODE_ENV: test - DB_HOST: 127.0.0.1 + DB_HOST: postgres DB_PORT: "5432" DB_NAME: calendar_run_test DB_USER: postgres @@ -48,7 +40,6 @@ jobs: run: | npm ci npm run build - npm run db:migrate npm test - name: Frontend — install, build @@ -56,3 +47,59 @@ jobs: run: | npm ci npm run build + + images: + if: github.server_url == 'https://git.vakanaut.ru' + needs: build-and-test + runs-on: home-build + strategy: + matrix: + include: + - component: backend + dockerfile: Dockerfile.backend + - component: frontend + dockerfile: Dockerfile.frontend + env: + REGISTRY: git.vakanaut.ru + COMPONENT: ${{ matrix.component }} + DOCKERFILE: ${{ matrix.dockerfile }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Check Docker image build + if: github.event_name == 'pull_request' + shell: bash + run: docker buildx build --file "$DOCKERFILE" --load . + + - name: Publish Docker image and record its digest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/runners-calendar' + shell: bash + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER }} + run: | + set -euo pipefail + : "${REGISTRY_USERNAME:?set REGISTRY_USERNAME}" + : "${REGISTRY_TOKEN:?set REGISTRY_TOKEN}" + owner="${REGISTRY_OWNER:-$REGISTRY_USERNAME}" + [[ "$owner" =~ ^[a-z0-9][a-z0-9_-]*$ ]] + + export DOCKER_CONFIG + DOCKER_CONFIG="$(mktemp -d)" + metadata="$(mktemp)" + trap 'rm -rf -- "$DOCKER_CONFIG"; rm -f -- "$metadata"' EXIT + + image="$REGISTRY/$owner/runners-calendar-$COMPONENT" + printf '%s\n' "$REGISTRY_TOKEN" | docker login "$REGISTRY" --username "$REGISTRY_USERNAME" --password-stdin + docker buildx build --file "$DOCKERFILE" --tag "$image:$GITHUB_SHA" \ + --label "org.opencontainers.image.revision=$GITHUB_SHA" \ + --label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ + --metadata-file "$metadata" --push . + + digest="$(jq -er '."containerimage.digest" | select(test("^sha256:[a-f0-9]{64}$"))' "$metadata")" + printf '%s\n' "$image@$digest" + if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + printf '%s\n' "$image@$digest" >> "$GITHUB_STEP_SUMMARY" + fi -- 2.54.0 From 017887c9e8789566a08700e4b1bd857efe49b1f1 Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 18 Nov 2026 05:21:38 +0000 Subject: [PATCH 2/3] ci: restrict image publication to upstream main --- .github/workflows/ci.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df79996..fe6b4bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,9 +49,9 @@ jobs: npm run build images: - if: github.server_url == 'https://git.vakanaut.ru' + if: github.server_url == 'https://git.vakanaut.ru' && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/runners-calendar' needs: build-and-test - runs-on: home-build + runs-on: home-publish strategy: matrix: include: @@ -67,13 +67,7 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - name: Check Docker image build - if: github.event_name == 'pull_request' - shell: bash - run: docker buildx build --file "$DOCKERFILE" --load . - - name: Publish Docker image and record its digest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/runners-calendar' shell: bash env: REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} -- 2.54.0 From 07e4a61449a73542a186f072173010c40b5a6097 Mon Sep 17 00:00:00 2001 From: codex Date: Tue, 24 Nov 2026 21:44:08 +0000 Subject: [PATCH 3/3] ci: validate final PR head before merge to main --- .github/workflows/ci.yml | 57 +++-------------------------------- .github/workflows/publish.yml | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe6b4bc..a4cfcaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,14 @@ name: CI on: - push: - branches: [main, master] pull_request: - branches: [main, master] + branches: [main] + types: [edited] jobs: build-and-test: + if: >- + contains(github.event.pull_request.body, format('CI-Head: {0}', github.event.pull_request.head.sha)) runs-on: ubuntu-latest container: node:20-bookworm services: @@ -47,53 +48,3 @@ jobs: run: | npm ci npm run build - - images: - if: github.server_url == 'https://git.vakanaut.ru' && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/runners-calendar' - needs: build-and-test - runs-on: home-publish - strategy: - matrix: - include: - - component: backend - dockerfile: Dockerfile.backend - - component: frontend - dockerfile: Dockerfile.frontend - env: - REGISTRY: git.vakanaut.ru - COMPONENT: ${{ matrix.component }} - DOCKERFILE: ${{ matrix.dockerfile }} - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - name: Publish Docker image and record its digest - shell: bash - env: - REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} - REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} - REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER }} - run: | - set -euo pipefail - : "${REGISTRY_USERNAME:?set REGISTRY_USERNAME}" - : "${REGISTRY_TOKEN:?set REGISTRY_TOKEN}" - owner="${REGISTRY_OWNER:-$REGISTRY_USERNAME}" - [[ "$owner" =~ ^[a-z0-9][a-z0-9_-]*$ ]] - - export DOCKER_CONFIG - DOCKER_CONFIG="$(mktemp -d)" - metadata="$(mktemp)" - trap 'rm -rf -- "$DOCKER_CONFIG"; rm -f -- "$metadata"' EXIT - - image="$REGISTRY/$owner/runners-calendar-$COMPONENT" - printf '%s\n' "$REGISTRY_TOKEN" | docker login "$REGISTRY" --username "$REGISTRY_USERNAME" --password-stdin - docker buildx build --file "$DOCKERFILE" --tag "$image:$GITHUB_SHA" \ - --label "org.opencontainers.image.revision=$GITHUB_SHA" \ - --label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ - --metadata-file "$metadata" --push . - - digest="$(jq -er '."containerimage.digest" | select(test("^sha256:[a-f0-9]{64}$"))' "$metadata")" - printf '%s\n' "$image@$digest" - if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then - printf '%s\n' "$image@$digest" >> "$GITHUB_STEP_SUMMARY" - fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..2073728 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,55 @@ +name: Publish images + +on: + push: + branches: [main] + +jobs: + images: + if: github.server_url == 'https://git.vakanaut.ru' && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'admin/runners-calendar' + runs-on: home-publish + strategy: + matrix: + include: + - component: backend + dockerfile: Dockerfile.backend + - component: frontend + dockerfile: Dockerfile.frontend + env: + REGISTRY: git.vakanaut.ru + COMPONENT: ${{ matrix.component }} + DOCKERFILE: ${{ matrix.dockerfile }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Publish Docker image and record its digest + shell: bash + env: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER }} + run: | + set -euo pipefail + : "${REGISTRY_USERNAME:?set REGISTRY_USERNAME}" + : "${REGISTRY_TOKEN:?set REGISTRY_TOKEN}" + owner="${REGISTRY_OWNER:-$REGISTRY_USERNAME}" + [[ "$owner" =~ ^[a-z0-9][a-z0-9_-]*$ ]] + + export DOCKER_CONFIG + DOCKER_CONFIG="$(mktemp -d)" + metadata="$(mktemp)" + trap 'rm -rf -- "$DOCKER_CONFIG"; rm -f -- "$metadata"' EXIT + + image="$REGISTRY/$owner/runners-calendar-$COMPONENT" + printf '%s\n' "$REGISTRY_TOKEN" | docker login "$REGISTRY" --username "$REGISTRY_USERNAME" --password-stdin + docker buildx build --file "$DOCKERFILE" --tag "$image:$GITHUB_SHA" \ + --label "org.opencontainers.image.revision=$GITHUB_SHA" \ + --label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ + --metadata-file "$metadata" --push . + + digest="$(jq -er '."containerimage.digest" | select(test("^sha256:[a-f0-9]{64}$"))' "$metadata")" + printf '%s\n' "$image@$digest" + if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + printf '%s\n' "$image@$digest" >> "$GITHUB_STEP_SUMMARY" + fi -- 2.54.0