feat(backend): build identity в health, VERSION bake и auto stage по sha-*
CI / test (push) Successful in 28m3s

This commit is contained in:
2026-07-14 21:25:40 +03:00
parent ff4ab23264
commit 2eeda5c4c4
8 changed files with 99 additions and 31 deletions
+6
View File
@@ -54,11 +54,17 @@ jobs:
- name: Build eventhub image - name: Build eventhub image
run: | run: |
set -euo pipefail 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 -- \ bash scripts/retry-docker-build.sh 5 60 -- \
docker buildx build \ docker buildx build \
--network=host \ --network=host \
--pull \ --pull \
--file docker/Dockerfile \ --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 \ --tag eventhub:latest \
--load \ --load \
--provenance=false \ --provenance=false \
+37 -22
View File
@@ -1,40 +1,45 @@
name: Deploy stage (core) name: Deploy stage (core)
# Auto после успешного CI на master: тот же sha-*, плюс floating :stage.
on: on:
push: workflow_run:
tags: workflows: [CI]
- 'v*' types: [completed]
branches: [master, main]
workflow_dispatch: workflow_dispatch:
inputs:
release_tag: concurrency:
description: 'Release tag (например v0.1.1)' group: eventhub-back-deploy-stage
required: true cancel-in-progress: false
default: 'v0.1.1'
sha_tag:
description: 'Образ sha-* (например sha-3f5dde498652)'
required: true
default: 'sha-3f5dde498652'
env: env:
REGISTRY: git.sabilin.com/eventhub REGISTRY: git.sabilin.com/eventhub
BUILDKIT_PROGRESS: quiet
DOCKER_BUILDKIT: 1
jobs: jobs:
deploy-stage-core: deploy-stage-core:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 90
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
fetch-depth: 2
- name: Compute image tags - name: Compute image tag
id: meta id: meta
run: | run: |
set -euo pipefail set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then if [ "${{ github.event_name }}" = "workflow_run" ]; then
echo "sha_tag=${{ github.event.inputs.sha_tag }}" >> "$GITHUB_OUTPUT" SHA="${{ github.event.workflow_run.head_sha }}"
echo "release_tag=${{ github.event.inputs.release_tag }}" >> "$GITHUB_OUTPUT"
else else
echo "sha_tag=sha-${GITHUB_SHA::12}" >> "$GITHUB_OUTPUT" SHA="${GITHUB_SHA}"
echo "release_tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi fi
echo "tag=sha-${SHA:0:12}" >> "$GITHUB_OUTPUT"
- name: Wait for Docker daemon - name: Wait for Docker daemon
run: bash scripts/ensure-docker-daemon.sh 240 run: bash scripts/ensure-docker-daemon.sh 240
@@ -49,14 +54,24 @@ jobs:
username: ${{ secrets.REGISTRY_USER }} username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Promote images (no rebuild) - 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} не найден — CI push не завершился."
exit 1
fi
echo "OK: eventhub:${TAG}"
- name: Promote sha → :stage (no rebuild)
env: env:
REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: | run: |
bash scripts/clone-devops-run.sh scripts/promote-images.sh \ bash scripts/clone-devops-run.sh scripts/promote-images.sh \
"${{ steps.meta.outputs.sha_tag }}" \ "${{ steps.meta.outputs.tag }}" \
"${{ steps.meta.outputs.release_tag }}" \ "${{ steps.meta.outputs.tag }}" \
stage \ stage \
eventhub traefik-coraza fallback bot-emulator-users observer-web logrotate eventhub traefik-coraza fallback bot-emulator-users observer-web logrotate
@@ -69,7 +84,7 @@ jobs:
script: | script: |
export REGISTRY_USER='${{ secrets.REGISTRY_USER }}' export REGISTRY_USER='${{ secrets.REGISTRY_USER }}'
export REGISTRY_PASSWORD='${{ secrets.REGISTRY_PASSWORD }}' export REGISTRY_PASSWORD='${{ secrets.REGISTRY_PASSWORD }}'
bash /opt/eventhub-stage/devops/scripts/deploy-service.sh stage core ${{ steps.meta.outputs.release_tag }} bash /opt/eventhub-stage/devops/scripts/deploy-service.sh stage core ${{ steps.meta.outputs.tag }}
- name: Prune old registry images - name: Prune old registry images
continue-on-error: true continue-on-error: true
+1
View File
@@ -0,0 +1 @@
0.1
+8
View File
@@ -35,6 +35,14 @@ RUN collect-runtime-libs.sh /app/release /opt/runtime-libs
# ============================================================ # ============================================================
FROM ${ERLANG_RUNTIME_IMAGE} FROM ${ERLANG_RUNTIME_IMAGE}
ARG EVENTHUB_VERSION=0.0
ARG EVENTHUB_GIT_SHA=unknown
ARG EVENTHUB_BUILT_AT=
ENV EVENTHUB_VERSION=${EVENTHUB_VERSION} \
EVENTHUB_GIT_SHA=${EVENTHUB_GIT_SHA} \
EVENTHUB_BUILT_AT=${EVENTHUB_BUILT_AT}
COPY --from=builder /app/release /app COPY --from=builder /app/release /app
# Доп. .so, если версия apk-openssl на runtime не совпала с builder (страховка) # Доп. .so, если версия apk-openssl на runtime не совпала с builder (страховка)
COPY --from=builder /opt/runtime-libs/ / COPY --from=builder /opt/runtime-libs/ /
+1
View File
@@ -119,6 +119,7 @@ start_admin_http() ->
{'_', [ {'_', [
% ================== БАЗОВЫЕ ================== % ================== БАЗОВЫЕ ==================
{"/admin/health", admin_handler_health, []}, {"/admin/health", admin_handler_health, []},
{"/v1/admin/health", admin_handler_health, []},
{"/v1/admin/stats", admin_handler_stats, []}, {"/v1/admin/stats", admin_handler_stats, []},
{"/v1/admin/nodes/metrics", admin_handler_node_metrics, []}, {"/v1/admin/nodes/metrics", admin_handler_node_metrics, []},
{"/v1/admin/login", admin_handler_login, []}, {"/v1/admin/login", admin_handler_login, []},
+7 -3
View File
@@ -8,7 +8,7 @@
init(Req, _State) -> init(Req, _State) ->
case cowboy_req:method(Req) of case cowboy_req:method(Req) of
<<"GET">> -> <<"GET">> ->
handler_utils:send_json(Req, 200, #{status => <<"ok">>}); handler_utils:send_json(Req, 200, eventhub_build_info:info());
_ -> _ ->
handler_utils:send_error(Req, 405, <<"Method not allowed">>) handler_utils:send_error(Req, 405, <<"Method not allowed">>)
end. end.
@@ -19,7 +19,7 @@ trails() ->
#{ #{
path => <<"/admin/health">>, path => <<"/admin/health">>,
method => <<"GET">>, method => <<"GET">>,
description => <<"Admin API health check">>, description => <<"Admin API health check with build identity">>,
tags => [<<"Health">>], tags => [<<"Health">>],
responses => #{ responses => #{
200 => #{ 200 => #{
@@ -27,7 +27,11 @@ trails() ->
content => #{<<"application/json">> => #{schema => #{ content => #{<<"application/json">> => #{schema => #{
type => object, type => object,
properties => #{ properties => #{
status => #{type => string} status => #{type => string},
service => #{type => string},
version => #{type => string},
git_sha => #{type => string},
built_at => #{type => string}
} }
}}} }}}
} }
+8 -4
View File
@@ -1,6 +1,6 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
%%% @doc Обработчик проверки здоровья клиентского API. %%% @doc Обработчик проверки здоровья клиентского API.
%%% GET – возвращает статус сервера. %%% GET – возвращает статус сервера и build identity.
%%% @end %%% @end
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(handler_health). -module(handler_health).
@@ -21,7 +21,7 @@ trails() ->
#{ #{
path => <<"/health">>, path => <<"/health">>,
method => <<"GET">>, method => <<"GET">>,
description => <<"API health check">>, description => <<"API health check with build identity">>,
tags => [<<"Health">>], tags => [<<"Health">>],
responses => #{ responses => #{
200 => #{ 200 => #{
@@ -29,7 +29,11 @@ trails() ->
content => #{<<"application/json">> => #{schema => #{ content => #{<<"application/json">> => #{schema => #{
type => object, type => object,
properties => #{ properties => #{
status => #{type => string} status => #{type => string},
service => #{type => string},
version => #{type => string},
git_sha => #{type => string},
built_at => #{type => string}
} }
}}} }}}
} }
@@ -46,7 +50,7 @@ trails() ->
handle(Req, _Opts) -> handle(Req, _Opts) ->
case cowboy_req:method(Req) of case cowboy_req:method(Req) of
<<"GET">> -> <<"GET">> ->
handler_utils:send_json(Req, 200, #{status => <<"ok">>}); handler_utils:send_json(Req, 200, eventhub_build_info:info());
_ -> _ ->
handler_utils:send_error(Req, 405, <<"Method not allowed">>) handler_utils:send_error(Req, 405, <<"Method not allowed">>)
end. end.
+29
View File
@@ -0,0 +1,29 @@
-module(eventhub_build_info).
-export([info/0, version/0, git_sha/0, built_at/0]).
%% @doc Runtime build identity from env (baked at image build or set in compose).
-spec info() -> map().
info() ->
#{
status => <<"ok">>,
service => <<"eventhub">>,
version => version(),
git_sha => git_sha(),
built_at => built_at()
}.
-spec version() -> binary().
version() -> env("EVENTHUB_VERSION", <<"0.0">>).
-spec git_sha() -> binary().
git_sha() -> env("EVENTHUB_GIT_SHA", <<"unknown">>).
-spec built_at() -> binary().
built_at() -> env("EVENTHUB_BUILT_AT", <<"">>).
env(Name, Default) ->
case os:getenv(Name) of
false -> Default;
[] -> Default;
Value -> unicode:characters_to_binary(Value)
end.