Enhance Docker workflow with gated publish
Expand workflow triggers to push/pull_request on main and dev and to PR reviews. Run lint/test only for non-review events or when a review is approved. Add a docker-test job that smoke-tests the built image. Add a docker-publish job that resolves SHA and stable tags (latest/dev), builds the releasable image, and optionally pushes when PUSH_IMAGE=true. Update docs/deployment.md
This commit is contained in:
@@ -1,74 +1,129 @@
|
|||||||
name: docker
|
name: docker
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
branches:
|
||||||
|
- main
|
||||||
|
- dev
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- dev
|
||||||
|
pull_request_review:
|
||||||
|
types:
|
||||||
|
- submitted
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
if: ${{ github.event_name != 'pull_request_review' || github.event.review.state == 'approved' }}
|
||||||
steps:
|
runs-on: ubuntu-latest
|
||||||
- name: Checkout
|
steps:
|
||||||
uses: actions/checkout@v4
|
- name: Checkout
|
||||||
- name: Set up Python
|
uses: actions/checkout@v4
|
||||||
uses: actions/setup-python@v5
|
- name: Set up Python
|
||||||
with:
|
uses: actions/setup-python@v5
|
||||||
python-version: '3.12'
|
with:
|
||||||
- name: Install dependencies
|
python-version: "3.12"
|
||||||
run: |
|
- name: Install dependencies
|
||||||
python -m pip install --upgrade pip
|
run: |
|
||||||
pip install -r requirements-dev.txt
|
python -m pip install --upgrade pip
|
||||||
- name: Run lint
|
pip install -r requirements-dev.txt
|
||||||
run: |
|
- name: Run lint
|
||||||
ruff check src tests
|
run: |
|
||||||
ruff format --check src tests
|
ruff check src tests
|
||||||
black --check src tests
|
ruff format --check src tests
|
||||||
mypy src
|
black --check src tests
|
||||||
|
mypy src
|
||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
if: ${{ github.event_name != 'pull_request_review' || github.event.review.state == 'approved' }}
|
||||||
steps:
|
runs-on: ubuntu-latest
|
||||||
- name: Checkout
|
steps:
|
||||||
uses: actions/checkout@v4
|
- name: Checkout
|
||||||
- name: Set up Python
|
uses: actions/checkout@v4
|
||||||
uses: actions/setup-python@v5
|
- name: Set up Python
|
||||||
with:
|
uses: actions/setup-python@v5
|
||||||
python-version: '3.12'
|
with:
|
||||||
- name: Install dependencies
|
python-version: "3.12"
|
||||||
run: |
|
- name: Install dependencies
|
||||||
python -m pip install --upgrade pip
|
run: |
|
||||||
pip install -r requirements-dev.txt
|
python -m pip install --upgrade pip
|
||||||
- name: Run tests
|
pip install -r requirements-dev.txt
|
||||||
run: pytest --cov=aegis_gitea_mcp --cov-report=term-missing --cov-fail-under=80
|
- name: Run tests
|
||||||
|
run: pytest --cov=aegis_gitea_mcp --cov-report=term-missing --cov-fail-under=80
|
||||||
|
|
||||||
docker-build:
|
docker-test:
|
||||||
runs-on: ubuntu-latest
|
if: ${{ github.event_name != 'pull_request_review' || github.event.review.state == 'approved' }}
|
||||||
needs: [lint, test]
|
runs-on: ubuntu-latest
|
||||||
env:
|
needs: [lint, test]
|
||||||
IMAGE_NAME: aegis-gitea-mcp
|
env:
|
||||||
steps:
|
IMAGE_NAME: aegis-gitea-mcp
|
||||||
- name: Checkout
|
steps:
|
||||||
uses: actions/checkout@v4
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build image tagged with commit SHA
|
- name: Build candidate image
|
||||||
run: |
|
run: |
|
||||||
SHA_TAG="${GITHUB_SHA:-${CI_COMMIT_SHA:-local}}"
|
SHA_TAG="${GITHUB_SHA:-${CI_COMMIT_SHA:-local}}"
|
||||||
docker build -f docker/Dockerfile -t ${IMAGE_NAME}:${SHA_TAG} .
|
docker build -f docker/Dockerfile -t ${IMAGE_NAME}:${SHA_TAG} .
|
||||||
|
|
||||||
- name: Tag latest on main
|
- name: Smoke-test image
|
||||||
run: |
|
run: |
|
||||||
REF_NAME="${GITHUB_REF_NAME:-${CI_COMMIT_REF_NAME:-}}"
|
SHA_TAG="${GITHUB_SHA:-${CI_COMMIT_SHA:-local}}"
|
||||||
SHA_TAG="${GITHUB_SHA:-${CI_COMMIT_SHA:-local}}"
|
docker run --rm --entrypoint python ${IMAGE_NAME}:${SHA_TAG} -c "import aegis_gitea_mcp"
|
||||||
if [ "${REF_NAME}" = "main" ]; then
|
|
||||||
docker tag ${IMAGE_NAME}:${SHA_TAG} ${IMAGE_NAME}:latest
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Optional registry push
|
docker-publish:
|
||||||
if: ${{ vars.PUSH_IMAGE == 'true' }}
|
runs-on: ubuntu-latest
|
||||||
run: |
|
needs: [lint, test, docker-test]
|
||||||
SHA_TAG="${GITHUB_SHA:-${CI_COMMIT_SHA:-local}}"
|
if: >-
|
||||||
docker push ${IMAGE_NAME}:${SHA_TAG}
|
(github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev')) ||
|
||||||
REF_NAME="${GITHUB_REF_NAME:-${CI_COMMIT_REF_NAME:-}}"
|
(github.event_name == 'pull_request_review' &&
|
||||||
if [ "${REF_NAME}" = "main" ]; then
|
github.event.review.state == 'approved' &&
|
||||||
docker push ${IMAGE_NAME}:latest
|
(github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'dev'))
|
||||||
fi
|
env:
|
||||||
|
IMAGE_NAME: aegis-gitea-mcp
|
||||||
|
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||||
|
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||||
|
|
||||||
|
- name: Resolve tags
|
||||||
|
id: tags
|
||||||
|
run: |
|
||||||
|
EVENT_NAME="${GITHUB_EVENT_NAME:-${CI_EVENT_NAME:-}}"
|
||||||
|
REF_NAME="${GITHUB_REF_NAME:-${CI_COMMIT_REF_NAME:-}}"
|
||||||
|
BASE_REF="${PR_BASE_REF:-${GITHUB_BASE_REF:-${CI_BASE_REF:-}}}"
|
||||||
|
SHA_TAG="${GITHUB_SHA:-${CI_COMMIT_SHA:-local}}"
|
||||||
|
|
||||||
|
if [ "${EVENT_NAME}" = "pull_request_review" ]; then
|
||||||
|
TARGET_BRANCH="${BASE_REF}"
|
||||||
|
SHA_TAG="${PR_HEAD_SHA:-$SHA_TAG}"
|
||||||
|
else
|
||||||
|
TARGET_BRANCH="${REF_NAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TARGET_BRANCH}" = "main" ]; then
|
||||||
|
STABLE_TAG="latest"
|
||||||
|
elif [ "${TARGET_BRANCH}" = "dev" ]; then
|
||||||
|
STABLE_TAG="dev"
|
||||||
|
else
|
||||||
|
echo "Unsupported target branch '${TARGET_BRANCH}'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "sha_tag=${SHA_TAG}" >> "${GITHUB_OUTPUT}"
|
||||||
|
echo "stable_tag=${STABLE_TAG}" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
- name: Build releasable image
|
||||||
|
run: |
|
||||||
|
docker build -f docker/Dockerfile -t ${IMAGE_NAME}:${{ steps.tags.outputs.sha_tag }} .
|
||||||
|
docker tag ${IMAGE_NAME}:${{ steps.tags.outputs.sha_tag }} ${IMAGE_NAME}:${{ steps.tags.outputs.stable_tag }}
|
||||||
|
|
||||||
|
- name: Optional registry push
|
||||||
|
if: ${{ vars.PUSH_IMAGE == 'true' }}
|
||||||
|
run: |
|
||||||
|
docker push ${IMAGE_NAME}:${{ steps.tags.outputs.sha_tag }}
|
||||||
|
docker push ${IMAGE_NAME}:${{ steps.tags.outputs.stable_tag }}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Workflows live in `.gitea/workflows/`:
|
|||||||
|
|
||||||
- `lint.yml`: ruff + format checks + mypy.
|
- `lint.yml`: ruff + format checks + mypy.
|
||||||
- `test.yml`: lint + tests + coverage fail-under `80`.
|
- `test.yml`: lint + tests + coverage fail-under `80`.
|
||||||
- `docker.yml`: gated Docker build (depends on lint+test), SHA tag, `latest` on `main`.
|
- `docker.yml`: lint + test + docker smoke-test gating; image publish on push to `main`/`dev` and on approved PR review targeting `main`/`dev`; tags include commit SHA plus `latest` (`main`) or `dev` (`dev`).
|
||||||
|
|
||||||
## Production Recommendations
|
## Production Recommendations
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user