Compare commits
13 Commits
v2
...
ea101d1695
| Author | SHA1 | Date | |
|---|---|---|---|
| ea101d1695 | |||
| 722f93b41c | |||
| e2e5e12f46 | |||
| 4e60168837 | |||
| dae3b59af9 | |||
| 839399363e | |||
| fa8a065138 | |||
| cd0c0ab416 | |||
| 854b1ac713 | |||
| 25fd13ce69 | |||
| 0fec805db1 | |||
| 3746062819 | |||
| edf86a5447 |
@@ -6,6 +6,11 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
outputs:
|
||||||
|
allow_push: ${{ steps.meta.outputs.allow_push }}
|
||||||
|
ref_name: ${{ steps.meta.outputs.ref_name }}
|
||||||
|
event_name: ${{ steps.meta.outputs.event_name }}
|
||||||
|
sha: ${{ steps.meta.outputs.sha }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
DEFAULT_BRANCH: main
|
DEFAULT_BRANCH: main
|
||||||
@@ -23,47 +28,77 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DEFAULT_BRANCH: ${{ env.DEFAULT_BRANCH }}
|
DEFAULT_BRANCH: ${{ env.DEFAULT_BRANCH }}
|
||||||
run: |
|
run: |
|
||||||
ref_name="${GITHUB_REF_NAME:-${GITHUB_REF##*/}}"
|
git_ref="${GITEA_REF:-${GITHUB_REF:-}}"
|
||||||
event_name="${GITHUB_EVENT_NAME:-}"
|
ref_name="${GITEA_REF_NAME:-${GITHUB_REF_NAME:-}}"
|
||||||
sha="${GITHUB_SHA:-}"
|
if [ -z "$ref_name" ] && [ -n "$git_ref" ]; then
|
||||||
|
ref_name="${git_ref##*/}"
|
||||||
|
fi
|
||||||
|
event_name="${GITEA_EVENT_NAME:-${GITHUB_EVENT_NAME:-}}"
|
||||||
|
sha="${GITEA_SHA:-${GITHUB_SHA:-}}"
|
||||||
|
if [ -z "$sha" ]; then
|
||||||
|
sha="$(git rev-parse HEAD)"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$ref_name" = "${DEFAULT_BRANCH:-main}" ]; then
|
if [ "$ref_name" = "${DEFAULT_BRANCH:-main}" ] && [ "$event_name" != "pull_request" ]; then
|
||||||
echo "on_default=true" >> "$GITHUB_OUTPUT"
|
echo "allow_push=true" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "on_default=false" >> "$GITHUB_OUTPUT"
|
echo "allow_push=false" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "ref_name=$ref_name" >> "$GITHUB_OUTPUT"
|
echo "ref_name=$ref_name" >> "$GITHUB_OUTPUT"
|
||||||
echo "event_name=$event_name" >> "$GITHUB_OUTPUT"
|
echo "event_name=$event_name" >> "$GITHUB_OUTPUT"
|
||||||
echo "sha=$sha" >> "$GITHUB_OUTPUT"
|
echo "sha=$sha" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Validate registry configuration
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${REGISTRY_URL}" ]; then
|
||||||
|
echo "::error::REGISTRY_URL secret not configured. Configure it with your Gitea container registry host." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
server_url="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL:-}}"
|
||||||
|
server_host="${server_url#http://}"
|
||||||
|
server_host="${server_host#https://}"
|
||||||
|
server_host="${server_host%%/*}"
|
||||||
|
server_host="${server_host%%:*}"
|
||||||
|
registry_host="${REGISTRY_URL#http://}"
|
||||||
|
registry_host="${registry_host#https://}"
|
||||||
|
registry_host="${registry_host%%/*}"
|
||||||
|
registry_host="${registry_host%%:*}"
|
||||||
|
if [ -n "${server_host}" ] && ! printf '%s' "${registry_host}" | grep -qi "${server_host}"; then
|
||||||
|
echo "::warning::REGISTRY_URL (${REGISTRY_URL}) does not match current Gitea host (${server_host}). Ensure this registry endpoint is managed by Gitea." >&2
|
||||||
|
fi
|
||||||
|
registry_repository="${registry_host}/allucanget/${REGISTRY_CONTAINER_NAME}"
|
||||||
|
echo "REGISTRY_HOST=${registry_host}" >> "$GITHUB_ENV"
|
||||||
|
echo "REGISTRY_REPOSITORY=${registry_repository}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up QEMU and Buildx
|
- name: Set up QEMU and Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to gitea registry
|
- name: Log in to gitea registry
|
||||||
if: ${{ steps.meta.outputs.on_default == 'true' }}
|
if: ${{ steps.meta.outputs.allow_push == 'true' }}
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
continue-on-error: true
|
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY_URL }}
|
registry: ${{ env.REGISTRY_HOST }}
|
||||||
username: ${{ env.REGISTRY_USERNAME }}
|
username: ${{ env.REGISTRY_USERNAME }}
|
||||||
password: ${{ env.REGISTRY_PASSWORD }}
|
password: ${{ env.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Build image
|
- name: Build image
|
||||||
id: build-image
|
id: build-image
|
||||||
env:
|
env:
|
||||||
REGISTRY_URL: ${{ env.REGISTRY_URL }}
|
REGISTRY_REPOSITORY: ${{ env.REGISTRY_REPOSITORY }}
|
||||||
REGISTRY_CONTAINER_NAME: ${{ env.REGISTRY_CONTAINER_NAME }}
|
REGISTRY_CONTAINER_NAME: ${{ env.REGISTRY_CONTAINER_NAME }}
|
||||||
SHA_TAG: ${{ steps.meta.outputs.sha }}
|
SHA_TAG: ${{ steps.meta.outputs.sha }}
|
||||||
PUSH_IMAGE: ${{ steps.meta.outputs.on_default == 'true' && steps.meta.outputs.event_name != 'pull_request' && env.REGISTRY_URL != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '' }}
|
PUSH_IMAGE: ${{ steps.meta.outputs.allow_push == 'true' && env.REGISTRY_HOST != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '' }}
|
||||||
run: |
|
run: |
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
LOG_FILE=build.log
|
LOG_FILE=build.log
|
||||||
if [ "${PUSH_IMAGE}" = "true" ]; then
|
if [ "${PUSH_IMAGE}" = "true" ]; then
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--push \
|
--load \
|
||||||
--tag "${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest" \
|
--tag "${REGISTRY_REPOSITORY}:latest" \
|
||||||
--tag "${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:${SHA_TAG}" \
|
--tag "${REGISTRY_REPOSITORY}:${SHA_TAG}" \
|
||||||
--file Dockerfile \
|
--file Dockerfile \
|
||||||
. 2>&1 | tee "${LOG_FILE}"
|
. 2>&1 | tee "${LOG_FILE}"
|
||||||
else
|
else
|
||||||
@@ -74,6 +109,20 @@ jobs:
|
|||||||
. 2>&1 | tee "${LOG_FILE}"
|
. 2>&1 | tee "${LOG_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: Push image
|
||||||
|
if: ${{ steps.meta.outputs.allow_push == 'true' }}
|
||||||
|
env:
|
||||||
|
REGISTRY_REPOSITORY: ${{ env.REGISTRY_REPOSITORY }}
|
||||||
|
SHA_TAG: ${{ steps.meta.outputs.sha }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${REGISTRY_REPOSITORY}" ]; then
|
||||||
|
echo "::error::REGISTRY_REPOSITORY not defined; cannot push image" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
docker push "${REGISTRY_REPOSITORY}:${SHA_TAG}"
|
||||||
|
docker push "${REGISTRY_REPOSITORY}:latest"
|
||||||
|
|
||||||
- name: Upload docker build logs
|
- name: Upload docker build logs
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
@@ -83,7 +132,7 @@ jobs:
|
|||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: build
|
needs: build
|
||||||
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
|
if: needs.build.outputs.allow_push == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
||||||
@@ -91,34 +140,67 @@ jobs:
|
|||||||
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||||
STAGING_KUBE_CONFIG: ${{ secrets.STAGING_KUBE_CONFIG }}
|
STAGING_KUBE_CONFIG: ${{ secrets.STAGING_KUBE_CONFIG }}
|
||||||
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
|
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
|
||||||
|
K8S_DEPLOY_ENABLED: ${{ secrets.K8S_DEPLOY_ENABLED }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Resolve registry repository
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -z "${REGISTRY_URL}" ]; then
|
||||||
|
echo "::error::REGISTRY_URL secret not configured. Configure it with your Gitea container registry host." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
registry_host="${REGISTRY_URL#http://}"
|
||||||
|
registry_host="${registry_host#https://}"
|
||||||
|
registry_host="${registry_host%%/*}"
|
||||||
|
registry_host="${registry_host%%:*}"
|
||||||
|
registry_repository="${registry_host}/allucanget/${REGISTRY_CONTAINER_NAME}"
|
||||||
|
echo "REGISTRY_HOST=${registry_host}" >> "$GITHUB_ENV"
|
||||||
|
echo "REGISTRY_REPOSITORY=${registry_repository}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Report Kubernetes deployment toggle
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
enabled="${K8S_DEPLOY_ENABLED:-}"
|
||||||
|
if [ "${enabled}" = "true" ]; then
|
||||||
|
echo "Kubernetes deployment is enabled for this run."
|
||||||
|
else
|
||||||
|
echo "::notice::Kubernetes deployment steps are disabled (set secrets.K8S_DEPLOY_ENABLED to 'true' to enable)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Capture commit metadata
|
||||||
|
id: commit_meta
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
message="$(git log -1 --pretty=%B | tr '\n' ' ')"
|
||||||
|
echo "message=$message" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Set up kubectl for staging
|
- name: Set up kubectl for staging
|
||||||
if: github.event.head_commit && contains(github.event.head_commit.message, '[deploy staging]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
||||||
uses: azure/k8s-set-context@v3
|
uses: azure/k8s-set-context@v3
|
||||||
with:
|
with:
|
||||||
method: kubeconfig
|
method: kubeconfig
|
||||||
kubeconfig: ${{ env.STAGING_KUBE_CONFIG }}
|
kubeconfig: ${{ env.STAGING_KUBE_CONFIG }}
|
||||||
|
|
||||||
- name: Set up kubectl for production
|
- name: Set up kubectl for production
|
||||||
if: github.event.head_commit && contains(github.event.head_commit.message, '[deploy production]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
|
||||||
uses: azure/k8s-set-context@v3
|
uses: azure/k8s-set-context@v3
|
||||||
with:
|
with:
|
||||||
method: kubeconfig
|
method: kubeconfig
|
||||||
kubeconfig: ${{ env.PROD_KUBE_CONFIG }}
|
kubeconfig: ${{ env.PROD_KUBE_CONFIG }}
|
||||||
|
|
||||||
- name: Deploy to staging
|
- name: Deploy to staging
|
||||||
if: github.event.head_commit && contains(github.event.head_commit.message, '[deploy staging]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
||||||
run: |
|
run: |
|
||||||
kubectl set image deployment/calminer-app calminer=${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest
|
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
|
||||||
kubectl apply -f k8s/configmap.yaml
|
kubectl apply -f k8s/configmap.yaml
|
||||||
kubectl apply -f k8s/secret.yaml
|
kubectl apply -f k8s/secret.yaml
|
||||||
kubectl rollout status deployment/calminer-app
|
kubectl rollout status deployment/calminer-app
|
||||||
|
|
||||||
- name: Collect staging deployment logs
|
- name: Collect staging deployment logs
|
||||||
if: github.event.head_commit && contains(github.event.head_commit.message, '[deploy staging]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
||||||
run: |
|
run: |
|
||||||
mkdir -p logs/deployment/staging
|
mkdir -p logs/deployment/staging
|
||||||
kubectl get pods -o wide > logs/deployment/staging/pods.txt
|
kubectl get pods -o wide > logs/deployment/staging/pods.txt
|
||||||
@@ -126,15 +208,15 @@ jobs:
|
|||||||
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/staging/calminer-app.log
|
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/staging/calminer-app.log
|
||||||
|
|
||||||
- name: Deploy to production
|
- name: Deploy to production
|
||||||
if: github.event.head_commit && contains(github.event.head_commit.message, '[deploy production]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
|
||||||
run: |
|
run: |
|
||||||
kubectl set image deployment/calminer-app calminer=${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest
|
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
|
||||||
kubectl apply -f k8s/configmap.yaml
|
kubectl apply -f k8s/configmap.yaml
|
||||||
kubectl apply -f k8s/secret.yaml
|
kubectl apply -f k8s/secret.yaml
|
||||||
kubectl rollout status deployment/calminer-app
|
kubectl rollout status deployment/calminer-app
|
||||||
|
|
||||||
- name: Collect production deployment logs
|
- name: Collect production deployment logs
|
||||||
if: github.event.head_commit && contains(github.event.head_commit.message, '[deploy production]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
|
||||||
run: |
|
run: |
|
||||||
mkdir -p logs/deployment/production
|
mkdir -p logs/deployment/production
|
||||||
kubectl get pods -o wide > logs/deployment/production/pods.txt
|
kubectl get pods -o wide > logs/deployment/production/pods.txt
|
||||||
|
|||||||
@@ -1,292 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main, develop, v2]
|
|
||||||
pull_request:
|
|
||||||
branches: [main, develop]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
APT_CACHER_NG: http://192.168.88.14:3142
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.12"
|
|
||||||
|
|
||||||
# - name: Get pip cache dir
|
|
||||||
# id: pip-cache
|
|
||||||
# run: |
|
|
||||||
# echo "path=$(pip cache dir)" >> $GITEA_OUTPUT
|
|
||||||
# echo "Pip cache dir: $(pip cache dir)"
|
|
||||||
|
|
||||||
# - name: Cache pip dependencies
|
|
||||||
# uses: actions/cache@v4
|
|
||||||
# with:
|
|
||||||
# path: ${{ steps.pip-cache.outputs.path }}
|
|
||||||
# key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt', 'requirements-test.txt', 'pyproject.toml') }}
|
|
||||||
# restore-keys: |
|
|
||||||
# ${{ runner.os }}-pip-
|
|
||||||
|
|
||||||
- name: Configure apt proxy
|
|
||||||
run: |
|
|
||||||
if [ -n "${APT_CACHER_NG}" ]; then
|
|
||||||
echo "Acquire::http::Proxy \"${APT_CACHER_NG}\";" | tee /etc/apt/apt.conf.d/01apt-cacher-ng
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Install system packages
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y build-essential libpq-dev
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
pip install -r requirements-test.txt
|
|
||||||
|
|
||||||
- name: Run Ruff
|
|
||||||
run: ruff check .
|
|
||||||
|
|
||||||
- name: Run Black
|
|
||||||
run: black --check .
|
|
||||||
|
|
||||||
- name: Run Bandit
|
|
||||||
run: bandit -c pyproject.toml -r tests
|
|
||||||
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: lint
|
|
||||||
env:
|
|
||||||
APT_CACHER_NG: http://192.168.88.14:3142
|
|
||||||
DB_DRIVER: postgresql+psycopg2
|
|
||||||
DB_HOST: 192.168.88.35
|
|
||||||
DB_NAME: calminer_test
|
|
||||||
DB_USER: calminer
|
|
||||||
DB_PASSWORD: calminer_password
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:17
|
|
||||||
env:
|
|
||||||
POSTGRES_USER: ${{ env.DB_USER }}
|
|
||||||
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
|
|
||||||
POSTGRES_DB: ${{ env.DB_NAME }}
|
|
||||||
options: >-
|
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 10s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 5
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: "3.12"
|
|
||||||
|
|
||||||
# - name: Get pip cache dir
|
|
||||||
# id: pip-cache
|
|
||||||
# run: |
|
|
||||||
# echo "path=$(pip cache dir)" >> $GITEA_OUTPUT
|
|
||||||
# echo "Pip cache dir: $(pip cache dir)"
|
|
||||||
|
|
||||||
# - name: Cache pip dependencies
|
|
||||||
# uses: actions/cache@v4
|
|
||||||
# with:
|
|
||||||
# path: ${{ steps.pip-cache.outputs.path }}
|
|
||||||
# key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt', 'requirements-test.txt', 'pyproject.toml') }}
|
|
||||||
# restore-keys: |
|
|
||||||
# ${{ runner.os }}-pip-
|
|
||||||
|
|
||||||
- name: Configure apt proxy
|
|
||||||
run: |
|
|
||||||
if [ -n "${APT_CACHER_NG}" ]; then
|
|
||||||
echo "Acquire::http::Proxy \"${APT_CACHER_NG}\";" | tee /etc/apt/apt.conf.d/01apt-cacher-ng
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Install system packages
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y build-essential libpq-dev
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
pip install -r requirements-test.txt
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
env:
|
|
||||||
DATABASE_DRIVER: ${{ env.DB_DRIVER }}
|
|
||||||
DATABASE_HOST: postgres
|
|
||||||
DATABASE_PORT: 5432
|
|
||||||
DATABASE_USER: ${{ env.DB_USER }}
|
|
||||||
DATABASE_PASSWORD: ${{ env.DB_PASSWORD }}
|
|
||||||
DATABASE_NAME: ${{ env.DB_NAME }}
|
|
||||||
run: |
|
|
||||||
pytest --cov=. --cov-report=term-missing --cov-report=xml --cov-fail-under=80 --junitxml=pytest-report.xml
|
|
||||||
|
|
||||||
- name: Upload test artifacts
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: test-artifacts
|
|
||||||
path: |
|
|
||||||
coverage.xml
|
|
||||||
pytest-report.xml
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- lint
|
|
||||||
- test
|
|
||||||
env:
|
|
||||||
DEFAULT_BRANCH: main
|
|
||||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
|
||||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
||||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
||||||
REGISTRY_CONTAINER_NAME: calminer
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Collect workflow metadata
|
|
||||||
id: meta
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
ref_name="${GITHUB_REF_NAME:-${GITHUB_REF##*/}}"
|
|
||||||
event_name="${GITHUB_EVENT_NAME:-}"
|
|
||||||
sha="${GITHUB_SHA:-}"
|
|
||||||
|
|
||||||
if [ "$ref_name" = "${DEFAULT_BRANCH:-main}" ]; then
|
|
||||||
echo "on_default=true" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "on_default=false" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "ref_name=$ref_name" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "event_name=$event_name" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "sha=$sha" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Set up QEMU and Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Log in to gitea registry
|
|
||||||
if: ${{ steps.meta.outputs.on_default == 'true' }}
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
continue-on-error: true
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY_URL }}
|
|
||||||
username: ${{ env.REGISTRY_USERNAME }}
|
|
||||||
password: ${{ env.REGISTRY_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Build image
|
|
||||||
id: build-image
|
|
||||||
env:
|
|
||||||
REGISTRY_URL: ${{ env.REGISTRY_URL }}
|
|
||||||
REGISTRY_CONTAINER_NAME: ${{ env.REGISTRY_CONTAINER_NAME }}
|
|
||||||
SHA_TAG: ${{ steps.meta.outputs.sha }}
|
|
||||||
PUSH_IMAGE: ${{ steps.meta.outputs.on_default == 'true' && steps.meta.outputs.event_name != 'pull_request' && env.REGISTRY_URL != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '' }}
|
|
||||||
run: |
|
|
||||||
set -eo pipefail
|
|
||||||
LOG_FILE=build.log
|
|
||||||
if [ "${PUSH_IMAGE}" = "true" ]; then
|
|
||||||
docker buildx build \
|
|
||||||
--push \
|
|
||||||
--tag "${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest" \
|
|
||||||
--tag "${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:${SHA_TAG}" \
|
|
||||||
--file Dockerfile \
|
|
||||||
. 2>&1 | tee "${LOG_FILE}"
|
|
||||||
else
|
|
||||||
docker buildx build \
|
|
||||||
--load \
|
|
||||||
--tag "${REGISTRY_CONTAINER_NAME}:ci" \
|
|
||||||
--file Dockerfile \
|
|
||||||
. 2>&1 | tee "${LOG_FILE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Upload docker build logs
|
|
||||||
if: failure()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: docker-build-logs
|
|
||||||
path: build.log
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build
|
|
||||||
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
|
|
||||||
env:
|
|
||||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
|
||||||
REGISTRY_CONTAINER_NAME: calminer
|
|
||||||
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
|
||||||
STAGING_KUBE_CONFIG: ${{ secrets.STAGING_KUBE_CONFIG }}
|
|
||||||
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up kubectl for staging
|
|
||||||
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[deploy staging]')
|
|
||||||
uses: azure/k8s-set-context@v3
|
|
||||||
with:
|
|
||||||
method: kubeconfig
|
|
||||||
kubeconfig: ${{ env.STAGING_KUBE_CONFIG }}
|
|
||||||
|
|
||||||
- name: Set up kubectl for production
|
|
||||||
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[deploy production]')
|
|
||||||
uses: azure/k8s-set-context@v3
|
|
||||||
with:
|
|
||||||
method: kubeconfig
|
|
||||||
kubeconfig: ${{ env.PROD_KUBE_CONFIG }}
|
|
||||||
|
|
||||||
- name: Deploy to staging
|
|
||||||
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[deploy staging]')
|
|
||||||
run: |
|
|
||||||
# Update image in deployment
|
|
||||||
kubectl set image deployment/calminer-app calminer=${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest
|
|
||||||
# Apply any config changes
|
|
||||||
kubectl apply -f k8s/configmap.yaml
|
|
||||||
kubectl apply -f k8s/secret.yaml
|
|
||||||
# Wait for rollout
|
|
||||||
kubectl rollout status deployment/calminer-app
|
|
||||||
|
|
||||||
- name: Collect staging deployment logs
|
|
||||||
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[deploy staging]')
|
|
||||||
run: |
|
|
||||||
mkdir -p logs/deployment/staging
|
|
||||||
kubectl get pods -o wide > logs/deployment/staging/pods.txt
|
|
||||||
kubectl get deployment calminer-app -o yaml > logs/deployment/staging/deployment.yaml
|
|
||||||
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/staging/calminer-app.log
|
|
||||||
|
|
||||||
- name: Deploy to production
|
|
||||||
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[deploy production]')
|
|
||||||
run: |
|
|
||||||
# Update image in deployment
|
|
||||||
kubectl set image deployment/calminer-app calminer=${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest
|
|
||||||
# Apply any config changes
|
|
||||||
kubectl apply -f k8s/configmap.yaml
|
|
||||||
kubectl apply -f k8s/secret.yaml
|
|
||||||
# Wait for rollout
|
|
||||||
kubectl rollout status deployment/calminer-app
|
|
||||||
|
|
||||||
- name: Collect production deployment logs
|
|
||||||
if: github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, '[deploy production]')
|
|
||||||
run: |
|
|
||||||
mkdir -p logs/deployment/production
|
|
||||||
kubectl get pods -o wide > logs/deployment/production/pods.txt
|
|
||||||
kubectl get deployment calminer-app -o yaml > logs/deployment/production/deployment.yaml
|
|
||||||
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/production/calminer-app.log
|
|
||||||
|
|
||||||
- name: Upload deployment logs
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deployment-logs
|
|
||||||
path: logs/deployment
|
|
||||||
if-no-files-found: ignore
|
|
||||||
78
.gitea/workflows/deploy-coolify.yml
Normal file
78
.gitea/workflows/deploy-coolify.yml
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
name: Deploy - Coolify
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
COOLIFY_BASE_URL: ${{ secrets.COOLIFY_BASE_URL }}
|
||||||
|
COOLIFY_API_TOKEN: ${{ secrets.COOLIFY_API_TOKEN }}
|
||||||
|
COOLIFY_APPLICATION_ID: ${{ secrets.COOLIFY_APPLICATION_ID }}
|
||||||
|
COOLIFY_DEPLOY_ENV: ${{ secrets.COOLIFY_DEPLOY_ENV }}
|
||||||
|
DOCKER_COMPOSE_PATH: docker-compose.prod.yml
|
||||||
|
ENV_FILE_PATH: deploy/.env
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Prepare compose bundle
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
mkdir -p deploy
|
||||||
|
cp "$DOCKER_COMPOSE_PATH" deploy/docker-compose.yml
|
||||||
|
if [ -n "$COOLIFY_DEPLOY_ENV" ]; then
|
||||||
|
printf '%s\n' "$COOLIFY_DEPLOY_ENV" > "$ENV_FILE_PATH"
|
||||||
|
elif [ ! -f "$ENV_FILE_PATH" ]; then
|
||||||
|
echo "::error::COOLIFY_DEPLOY_ENV secret not configured and deploy/.env missing" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Validate Coolify secrets
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
missing=0
|
||||||
|
for var in COOLIFY_BASE_URL COOLIFY_API_TOKEN COOLIFY_APPLICATION_ID; do
|
||||||
|
if [ -z "${!var}" ]; then
|
||||||
|
echo "::error::Missing required secret: $var"
|
||||||
|
missing=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$missing" -eq 1 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Trigger deployment via Coolify API
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
api_url="$COOLIFY_BASE_URL/api/v1/deploy"
|
||||||
|
payload=$(jq -n --arg uuid "$COOLIFY_APPLICATION_ID" '{ uuid: $uuid }')
|
||||||
|
response=$(curl -sS -w '\n%{http_code}' \
|
||||||
|
-X POST "$api_url" \
|
||||||
|
-H "Authorization: Bearer $COOLIFY_API_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$payload")
|
||||||
|
body=$(echo "$response" | head -n -1)
|
||||||
|
status=$(echo "$response" | tail -n1)
|
||||||
|
echo "Deploy response status: $status"
|
||||||
|
echo "$body"
|
||||||
|
printf '%s' "$body" > deploy/coolify-response.json
|
||||||
|
if [ "$status" -ge 400 ]; then
|
||||||
|
echo "::error::Deployment request failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload deployment bundle
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: coolify-deploy-bundle
|
||||||
|
path: |
|
||||||
|
deploy/docker-compose.yml
|
||||||
|
deploy/.env
|
||||||
|
deploy/coolify-response.json
|
||||||
|
if-no-files-found: warn
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-11-14
|
||||||
|
|
||||||
|
- Finalised Coolify automation by stabilising `.gitea/workflows/deploy-coolify.yml` on a `push` trigger to `main`, calculating branch/commit context via Gitea-first environment variables, and bundling compose/env artifacts for traceability.
|
||||||
|
- Hardened the build workflow so registry authentication normalises the `git.allucanget.biz` host, loads tagged images locally, and pushes both `latest` and commit SHA tags before deployment, with deploy/k8s jobs reusing the resolved repository path.
|
||||||
|
- Updated `docker-compose.prod.yml` and Coolify documentation so production pulls `git.allucanget.biz/allucanget/calminer:latest`, added secret/registry guidance plus runner DNS notes to `calminer-docs/CONTRIBUTING.md`, and recorded the completion in `.github/instructions/DONE.md`.
|
||||||
|
- Introduced the `K8S_DEPLOY_ENABLED` toggle so CI can default to skipping Kubernetes rollouts unless explicitly enabled, guarded all kubectl steps behind the flag, surfaced a notice when disabled, and documented the secret for operators.
|
||||||
|
|
||||||
## 2025-11-13
|
## 2025-11-13
|
||||||
|
|
||||||
- Completed the UI alignment initiative by consolidating shared form and button styles into `static/css/forms.css` and `static/css/main.css`, introducing the semantic palette in `static/css/theme-default.css`, and spot-checking key pages plus contrast reports.
|
- Completed the UI alignment initiative by consolidating shared form and button styles into `static/css/forms.css` and `static/css/main.css`, introducing the semantic palette in `static/css/theme-default.css`, and spot-checking key pages plus contrast reports.
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ version: "3.8"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build:
|
image: git.allucanget.biz/allucanget/calminer:latest
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
APT_CACHE_URL: ${APT_CACHE_URL:-}
|
|
||||||
environment:
|
environment:
|
||||||
- ENVIRONMENT=production
|
- ENVIRONMENT=production
|
||||||
- DEBUG=false
|
- DEBUG=false
|
||||||
|
|||||||
Reference in New Issue
Block a user