385 lines
14 KiB
YAML
385 lines
14 KiB
YAML
name: CI
|
|
|
|
# PR / push: test (+ push образа на push).
|
|
# push master/main: test → deploy IFT → E2E IFT → deploy stage → E2E stage (один run).
|
|
# workflow_dispatch: выбор фазы (см. input pipeline).
|
|
on:
|
|
push:
|
|
branches: [master, main]
|
|
pull_request:
|
|
workflow_dispatch:
|
|
inputs:
|
|
pipeline:
|
|
description: "Режим (push master = full автоматически)"
|
|
required: false
|
|
default: full
|
|
type: choice
|
|
options:
|
|
- full
|
|
- test-only
|
|
- deploy-ift
|
|
- e2e-ift
|
|
- deploy-stage
|
|
- e2e-stage
|
|
|
|
concurrency:
|
|
group: eventhub-back-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
BUILDKIT_PROGRESS: quiet
|
|
DOCKER_BUILDKIT: 1
|
|
REGISTRY: git.sabilin.com/eventhub
|
|
|
|
jobs:
|
|
test:
|
|
if: |
|
|
github.event_name == 'pull_request' ||
|
|
github.event_name == 'push' ||
|
|
(github.event_name == 'workflow_dispatch' && (github.event.inputs.pipeline == 'full' || github.event.inputs.pipeline == 'test-only'))
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 60
|
|
outputs:
|
|
ci_test_ok: ${{ steps.mark_test.outputs.ok }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Wait for Docker daemon
|
|
run: bash scripts/ensure-docker-daemon.sh 240
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to registry
|
|
if: github.event_name == 'push'
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
run: |
|
|
bash scripts/retry-docker-build.sh 5 30 -- \
|
|
bash -c 'echo "${REGISTRY_PASSWORD}" | docker login git.sabilin.com -u "${REGISTRY_USER}" --password-stdin'
|
|
|
|
- name: Ensure Erlang base images (registry :latest)
|
|
run: |
|
|
set -euo pipefail
|
|
FORCE=""
|
|
if CHANGED="$(git diff --name-only HEAD~1..HEAD 2>/dev/null || true)" \
|
|
&& echo "${CHANGED}" | grep -q '^docker/erlang/'; then
|
|
FORCE="--force-build"
|
|
fi
|
|
bash scripts/build-erlang-base-images.sh ${FORCE}
|
|
|
|
- name: Push Erlang base images
|
|
if: github.event_name == 'push'
|
|
run: bash scripts/build-erlang-base-images.sh --push
|
|
|
|
- name: Build eventhub image
|
|
run: |
|
|
set -euo pipefail
|
|
APP_VERSION="$(tr -d '[:space:]' < VERSION 2>/dev/null || echo 0.0)"
|
|
GIT_SHA="${GITHUB_SHA:0:12}"
|
|
BUILT_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
bash scripts/retry-docker-build.sh 5 60 -- \
|
|
docker buildx build \
|
|
--network=host \
|
|
--pull \
|
|
--file docker/Dockerfile \
|
|
--build-arg "EVENTHUB_VERSION=${APP_VERSION}" \
|
|
--build-arg "EVENTHUB_GIT_SHA=${GIT_SHA}" \
|
|
--build-arg "EVENTHUB_BUILT_AT=${BUILT_AT}" \
|
|
--tag eventhub:latest \
|
|
--load \
|
|
--provenance=false \
|
|
--sbom=false \
|
|
.
|
|
|
|
- name: Build API test image
|
|
run: |
|
|
set -euo pipefail
|
|
bash scripts/retry-docker-build.sh 5 60 -- \
|
|
docker buildx build \
|
|
--network=host \
|
|
--pull \
|
|
--file docker/ApiTests.Dockerfile \
|
|
--tag eventhub-api-tests:latest \
|
|
--load \
|
|
--provenance=false \
|
|
--sbom=false \
|
|
.
|
|
|
|
- name: Run API tests (local CT)
|
|
run: docker run --rm eventhub-api-tests:latest
|
|
|
|
- name: Push tested eventhub image
|
|
if: github.event_name == 'push'
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="sha-${GITHUB_SHA:0:12}"
|
|
docker tag eventhub:latest "${REGISTRY}/eventhub:${TAG}"
|
|
docker tag eventhub:latest "${REGISTRY}/eventhub:ift"
|
|
docker tag eventhub:latest "${REGISTRY}/eventhub:dev"
|
|
bash scripts/retry-docker-build.sh 5 30 -- docker push "${REGISTRY}/eventhub:${TAG}"
|
|
bash scripts/retry-docker-build.sh 5 30 -- docker push "${REGISTRY}/eventhub:ift"
|
|
bash scripts/retry-docker-build.sh 5 30 -- docker push "${REGISTRY}/eventhub:dev"
|
|
|
|
- name: Prune old registry images
|
|
if: github.event_name == 'push'
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
run: bash scripts/run-registry-prune.sh
|
|
|
|
- name: Mark test complete
|
|
id: mark_test
|
|
if: success()
|
|
run: echo "ok=1" >> "$GITHUB_OUTPUT"
|
|
|
|
deploy-ift:
|
|
needs: test
|
|
if: |
|
|
always() && (
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'deploy-ift') ||
|
|
(
|
|
needs.test.result == 'success' &&
|
|
(
|
|
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')) ||
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'full')
|
|
)
|
|
)
|
|
)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 90
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 2
|
|
|
|
- name: Compute image tag
|
|
id: meta
|
|
run: echo "tag=sha-${GITHUB_SHA:0:12}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Wait for Docker daemon
|
|
run: bash scripts/ensure-docker-daemon.sh 240
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: git.sabilin.com
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Verify eventhub image from CI
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ steps.meta.outputs.tag }}"
|
|
if ! docker buildx imagetools inspect "${REGISTRY}/eventhub:${TAG}" >/dev/null 2>&1; then
|
|
echo "Образ eventhub:${TAG} не найден — сначала должен пройти test (build + push)."
|
|
exit 1
|
|
fi
|
|
echo "OK: eventhub:${TAG}"
|
|
|
|
- name: Publish auxiliary images
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ steps.meta.outputs.tag }}"
|
|
FILES="$(git diff --name-only HEAD^ HEAD 2>/dev/null || git show --pretty="" --name-only HEAD)"
|
|
bash scripts/publish-ift-aux-images.sh "${REGISTRY}" "${TAG}" "${FILES}"
|
|
|
|
- name: Bootstrap optional aux images on IFT server
|
|
uses: appleboy/ssh-action@v0.1.5
|
|
with:
|
|
host: ${{ secrets.IFT_SSH_HOST }}
|
|
username: ${{ secrets.IFT_SSH_USER }}
|
|
key: ${{ secrets.IFT_SSH_PRIVATE_KEY }}
|
|
script: |
|
|
export REGISTRY_USER='${{ secrets.REGISTRY_USER }}'
|
|
export REGISTRY_PASSWORD='${{ secrets.REGISTRY_PASSWORD }}'
|
|
echo "${REGISTRY_PASSWORD}" | docker login git.sabilin.com -u "${REGISTRY_USER}" --password-stdin
|
|
COMMIT="${GITHUB_SHA}"
|
|
WORKDIR="$(mktemp -d)"
|
|
git clone --depth 1 "https://${REGISTRY_USER}:${REGISTRY_PASSWORD}@git.sabilin.com/EventHub/EventHubBack.git" "${WORKDIR}/back"
|
|
git -C "${WORKDIR}/back" fetch --depth 1 origin "${COMMIT}"
|
|
git -C "${WORKDIR}/back" checkout "${COMMIT}"
|
|
BACK_DIR="${WORKDIR}/back" bash "${WORKDIR}/back/scripts/build-optional-aux-on-server.sh" "${REGISTRY}" "${{ steps.meta.outputs.tag }}" "${COMMIT}"
|
|
rm -rf "${WORKDIR}"
|
|
|
|
- name: Deploy core on IFT via SSH
|
|
uses: appleboy/ssh-action@v0.1.5
|
|
with:
|
|
host: ${{ secrets.IFT_SSH_HOST }}
|
|
username: ${{ secrets.IFT_SSH_USER }}
|
|
key: ${{ secrets.IFT_SSH_PRIVATE_KEY }}
|
|
script: |
|
|
export REGISTRY_USER='${{ secrets.REGISTRY_USER }}'
|
|
export REGISTRY_PASSWORD='${{ secrets.REGISTRY_PASSWORD }}'
|
|
bash /opt/eventhub-ift/devops/scripts/deploy-service.sh ift core ${{ steps.meta.outputs.tag }}
|
|
|
|
- name: Prune old registry images
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
run: bash scripts/run-registry-prune.sh
|
|
|
|
e2e-ift:
|
|
needs: deploy-ift
|
|
if: |
|
|
always() && (
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'e2e-ift') ||
|
|
(
|
|
needs.deploy-ift.result == 'success' &&
|
|
(
|
|
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')) ||
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'full')
|
|
)
|
|
)
|
|
)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 90
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Wait for Docker daemon
|
|
run: bash scripts/ensure-docker-daemon.sh 240
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Load API test credentials from IFT .env
|
|
env:
|
|
SSH_HOST: ${{ secrets.IFT_SSH_HOST }}
|
|
SSH_USER: ${{ secrets.IFT_SSH_USER }}
|
|
SSH_KEY: ${{ secrets.IFT_SSH_PRIVATE_KEY }}
|
|
run: bash scripts/load-stand-api-env.sh ift
|
|
|
|
- name: E2E IFT (full API suite)
|
|
env:
|
|
SSH_HOST: ${{ secrets.IFT_SSH_HOST }}
|
|
SSH_USER: ${{ secrets.IFT_SSH_USER }}
|
|
SSH_KEY: ${{ secrets.IFT_SSH_PRIVATE_KEY }}
|
|
API_HOST: ${{ secrets.E2E_IFT_API_HOST }}
|
|
ADMIN_API_HOST: ${{ secrets.E2E_IFT_ADMIN_API_HOST }}
|
|
WS_HOST: ${{ secrets.E2E_IFT_WS_HOST }}
|
|
ADMIN_WS_HOST: ${{ secrets.E2E_IFT_ADMIN_WS_HOST }}
|
|
run: bash scripts/run-stand-api-tests.sh ift
|
|
|
|
deploy-stage:
|
|
needs: e2e-ift
|
|
if: |
|
|
always() && (
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'deploy-stage') ||
|
|
(
|
|
needs.e2e-ift.result == 'success' &&
|
|
(
|
|
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')) ||
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'full')
|
|
)
|
|
)
|
|
)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 90
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 2
|
|
|
|
- name: Compute image tag
|
|
id: meta
|
|
run: echo "tag=sha-${GITHUB_SHA:0:12}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Wait for Docker daemon
|
|
run: bash scripts/ensure-docker-daemon.sh 240
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: git.sabilin.com
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Verify core image from CI
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ steps.meta.outputs.tag }}"
|
|
if ! docker buildx imagetools inspect "${REGISTRY}/eventhub:${TAG}" >/dev/null 2>&1; then
|
|
echo "Образ eventhub:${TAG} не найден — test push не завершился."
|
|
exit 1
|
|
fi
|
|
echo "OK: eventhub:${TAG}"
|
|
|
|
- name: Promote sha → :stage (no rebuild)
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
run: |
|
|
bash scripts/clone-devops-run.sh scripts/promote-images.sh \
|
|
"${{ steps.meta.outputs.tag }}" \
|
|
"${{ steps.meta.outputs.tag }}" \
|
|
stage \
|
|
eventhub traefik-coraza fallback bot-emulator-users observer-web logrotate
|
|
|
|
- name: Deploy core on stage via SSH
|
|
uses: appleboy/ssh-action@v0.1.5
|
|
with:
|
|
host: ${{ secrets.STAGE_SSH_HOST }}
|
|
username: ${{ secrets.STAGE_SSH_USER }}
|
|
key: ${{ secrets.STAGE_SSH_PRIVATE_KEY }}
|
|
script: |
|
|
export REGISTRY_USER='${{ secrets.REGISTRY_USER }}'
|
|
export REGISTRY_PASSWORD='${{ secrets.REGISTRY_PASSWORD }}'
|
|
bash /opt/eventhub-stage/devops/scripts/deploy-service.sh stage core ${{ steps.meta.outputs.tag }}
|
|
|
|
- name: Prune old registry images
|
|
continue-on-error: true
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
run: bash scripts/clone-devops-run.sh scripts/prune-registry-images.sh
|
|
|
|
e2e-stage:
|
|
needs: deploy-stage
|
|
if: |
|
|
always() && (
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'e2e-stage') ||
|
|
(
|
|
needs.deploy-stage.result == 'success' &&
|
|
(
|
|
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')) ||
|
|
(github.event_name == 'workflow_dispatch' && github.event.inputs.pipeline == 'full')
|
|
)
|
|
)
|
|
)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 90
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Wait for Docker daemon
|
|
run: bash scripts/ensure-docker-daemon.sh 240
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Load API test credentials from stage .env
|
|
env:
|
|
SSH_HOST: ${{ secrets.STAGE_SSH_HOST }}
|
|
SSH_USER: ${{ secrets.STAGE_SSH_USER }}
|
|
SSH_KEY: ${{ secrets.STAGE_SSH_PRIVATE_KEY }}
|
|
run: bash scripts/load-stand-api-env.sh stage
|
|
|
|
- name: E2E stage (full API suite)
|
|
env:
|
|
SSH_HOST: ${{ secrets.STAGE_SSH_HOST }}
|
|
SSH_USER: ${{ secrets.STAGE_SSH_USER }}
|
|
SSH_KEY: ${{ secrets.STAGE_SSH_PRIVATE_KEY }}
|
|
API_HOST: ${{ secrets.E2E_STAGE_API_HOST }}
|
|
ADMIN_API_HOST: ${{ secrets.E2E_STAGE_ADMIN_API_HOST }}
|
|
WS_HOST: ${{ secrets.E2E_STAGE_WS_HOST }}
|
|
ADMIN_WS_HOST: ${{ secrets.E2E_STAGE_ADMIN_WS_HOST }}
|
|
run: bash scripts/run-stand-api-tests.sh stage
|