fix: container/compose/CI overhaul
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
name: Build and Push Docker Image
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Run E2E Tests
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
if: ${{ github.event_name != 'workflow_run' || (
|
||||
github.event.workflow_run.conclusion == 'success' && (
|
||||
github.event.workflow_run.head_branch == 'main' ||
|
||||
github.event.workflow_run.head_branch == 'refs/heads/main' ||
|
||||
(
|
||||
!github.event.workflow_run.head_branch && (
|
||||
github.event.workflow_run.repository.default_branch == 'main' ||
|
||||
github.event.workflow_run.repository.default_branch == 'refs/heads/main' ||
|
||||
github.event.repository.default_branch == 'main' ||
|
||||
github.event.repository.default_branch == 'refs/heads/main'
|
||||
)
|
||||
)
|
||||
) }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DEFAULT_BRANCH: main
|
||||
REGISTRY_ORG: allucanget
|
||||
REGISTRY_IMAGE_NAME: calminer
|
||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
WORKFLOW_RUN_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
|
||||
WORKFLOW_RUN_REPO_DEFAULT_BRANCH: ${{ github.event.workflow_run.repository.default_branch }}
|
||||
REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
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 [ -z "$ref_name" ] && [ -n "${WORKFLOW_RUN_HEAD_BRANCH:-}" ]; then
|
||||
ref_name="${WORKFLOW_RUN_HEAD_BRANCH}"
|
||||
fi
|
||||
|
||||
if [ -z "$ref_name" ] && [ -n "${WORKFLOW_RUN_REPO_DEFAULT_BRANCH:-}" ]; then
|
||||
ref_name="${WORKFLOW_RUN_REPO_DEFAULT_BRANCH}"
|
||||
fi
|
||||
|
||||
if [ -z "$ref_name" ] && [ -n "${REPOSITORY_DEFAULT_BRANCH:-}" ]; then
|
||||
ref_name="${REPOSITORY_DEFAULT_BRANCH}"
|
||||
fi
|
||||
|
||||
if [ -z "$sha" ] && [ -n "${WORKFLOW_RUN_HEAD_SHA:-}" ]; then
|
||||
sha="${WORKFLOW_RUN_HEAD_SHA}"
|
||||
fi
|
||||
|
||||
if [[ "$ref_name" == refs/heads/* ]]; then
|
||||
ref_name="${ref_name#refs/heads/}"
|
||||
fi
|
||||
|
||||
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
|
||||
with:
|
||||
install: false
|
||||
|
||||
- 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 and push Docker image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: ${{ steps.meta.outputs.on_default == 'true' && steps.meta.outputs.event_name != 'pull_request' && (env.REGISTRY_URL != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '') }}
|
||||
tags: |
|
||||
${{ env.REGISTRY_URL }}/${{ env.REGISTRY_ORG }}/${{ env.REGISTRY_IMAGE_NAME }}:latest
|
||||
${{ env.REGISTRY_URL }}/${{ env.REGISTRY_ORG }}/${{ env.REGISTRY_IMAGE_NAME }}:${{ steps.meta.outputs.sha }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
@@ -1,99 +0,0 @@
|
||||
name: Deploy to Server
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Build and Push Docker Image
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
if: ${{ github.event_name != 'workflow_run' || (
|
||||
github.event.workflow_run.conclusion == 'success' && (
|
||||
github.event.workflow_run.head_branch == 'main' ||
|
||||
github.event.workflow_run.head_branch == 'refs/heads/main' ||
|
||||
(
|
||||
!github.event.workflow_run.head_branch && (
|
||||
github.event.workflow_run.repository.default_branch == 'main' ||
|
||||
github.event.workflow_run.repository.default_branch == 'refs/heads/main' ||
|
||||
github.event.repository.default_branch == 'main' ||
|
||||
github.event.repository.default_branch == 'refs/heads/main'
|
||||
)
|
||||
)
|
||||
)
|
||||
) }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DEFAULT_BRANCH: main
|
||||
REGISTRY_ORG: allucanget
|
||||
REGISTRY_IMAGE_NAME: calminer
|
||||
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
|
||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
WORKFLOW_RUN_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
|
||||
WORKFLOW_RUN_REPO_DEFAULT_BRANCH: ${{ github.event.workflow_run.repository.default_branch }}
|
||||
REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
||||
steps:
|
||||
- name: SSH and deploy
|
||||
uses: appleboy/ssh-action@master
|
||||
with:
|
||||
host: ${{ secrets.SSH_HOST }}
|
||||
username: ${{ secrets.SSH_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
IMAGE_SHA="${{ env.WORKFLOW_RUN_HEAD_SHA }}"
|
||||
FALLBACK_BRANCH="${{ env.WORKFLOW_RUN_HEAD_BRANCH }}"
|
||||
IMAGE_TAG="${IMAGE_SHA}"
|
||||
IMAGE_PATH="${{ env.REGISTRY_URL }}/${{ env.REGISTRY_ORG }}/${{ env.REGISTRY_IMAGE_NAME }}"
|
||||
|
||||
if [ -z "$FALLBACK_BRANCH" ]; then
|
||||
FALLBACK_BRANCH="${{ env.WORKFLOW_RUN_REPO_DEFAULT_BRANCH }}"
|
||||
fi
|
||||
|
||||
if [ -z "$FALLBACK_BRANCH" ]; then
|
||||
FALLBACK_BRANCH="${{ env.REPOSITORY_DEFAULT_BRANCH }}"
|
||||
fi
|
||||
|
||||
if [ -z "$IMAGE_TAG" ] && [ -n "$FALLBACK_BRANCH" ]; then
|
||||
case "$FALLBACK_BRANCH" in
|
||||
refs/heads/*)
|
||||
FALLBACK_BRANCH="${FALLBACK_BRANCH#refs/heads/}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$FALLBACK_BRANCH" = "${DEFAULT_BRANCH:-main}" ]; then
|
||||
IMAGE_TAG="latest"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$IMAGE_TAG" ]; then
|
||||
echo "Missing workflow run head SHA and no default-branch fallback available; aborting deployment." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker pull "$IMAGE_PATH:$IMAGE_TAG"
|
||||
docker stop calminer || true
|
||||
docker rm calminer || true
|
||||
docker run -d --name calminer -p 8000:8000 \
|
||||
-e DATABASE_DRIVER=${{ secrets.DATABASE_DRIVER }} \
|
||||
-e DATABASE_HOST=${{ secrets.DATABASE_HOST }} \
|
||||
-e DATABASE_PORT=${{ secrets.DATABASE_PORT }} \
|
||||
-e DATABASE_USER=${{ secrets.DATABASE_USER }} \
|
||||
-e DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }} \
|
||||
-e DATABASE_NAME=${{ secrets.DATABASE_NAME }} \
|
||||
-e DATABASE_SCHEMA=${{ secrets.DATABASE_SCHEMA }} \
|
||||
"$IMAGE_PATH:$IMAGE_TAG"
|
||||
|
||||
for attempt in {1..10}; do
|
||||
if curl -fsS http://localhost:8000/health >/dev/null; then
|
||||
echo "Deployment health check passed"
|
||||
exit 0
|
||||
fi
|
||||
echo "Health check attempt ${attempt} failed; retrying in 3s"
|
||||
sleep 3
|
||||
done
|
||||
|
||||
echo "Deployment health check failed after retries" >&2
|
||||
docker logs calminer >&2 || true
|
||||
exit 1
|
||||
@@ -1,114 +0,0 @@
|
||||
name: Run E2E Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- main
|
||||
- refs/heads/main
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Run Tests
|
||||
types:
|
||||
- completed
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
e2e:
|
||||
name: E2E Tests
|
||||
if: ${{ github.event_name == 'workflow_dispatch' ||
|
||||
github.event_name == 'push' ||
|
||||
(
|
||||
github.event_name == 'workflow_run' &&
|
||||
github.event.workflow_run.conclusion == 'success' &&
|
||||
(
|
||||
github.event.workflow_run.head_branch == 'main' ||
|
||||
github.event.workflow_run.head_branch == 'refs/heads/main' ||
|
||||
(
|
||||
!github.event.workflow_run.head_branch &&
|
||||
(
|
||||
github.event.workflow_run.repository.default_branch == 'main' ||
|
||||
github.event.workflow_run.repository.default_branch == 'refs/heads/main' ||
|
||||
github.event.repository.default_branch == 'main' ||
|
||||
github.event.repository.default_branch == 'refs/heads/main'
|
||||
)
|
||||
)
|
||||
)
|
||||
) }}
|
||||
runs-on: ubuntu-latest
|
||||
container: mcr.microsoft.com/playwright/python:v1.55.0-jammy
|
||||
env:
|
||||
DATABASE_DRIVER: postgresql
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_PORT: '5432'
|
||||
DATABASE_NAME: calminer_ci
|
||||
DATABASE_USER: calminer
|
||||
DATABASE_PASSWORD: secret
|
||||
DATABASE_SCHEMA: public
|
||||
DATABASE_SUPERUSER: calminer
|
||||
DATABASE_SUPERUSER_PASSWORD: secret
|
||||
DATABASE_SUPERUSER_DB: calminer_ci
|
||||
DATABASE_URL: postgresql+psycopg2://calminer:secret@postgres:5432/calminer_ci
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_DB: calminer_ci
|
||||
POSTGRES_USER: calminer
|
||||
POSTGRES_PASSWORD: secret
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U calminer -d calminer_ci"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
steps:
|
||||
- name: Install Node.js runtime
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||
apt-get install -y nodejs
|
||||
|
||||
- name: Checkout code (workflow_run)
|
||||
if: ${{ github.event_name == 'workflow_run' }}
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.workflow_run.head_sha }}
|
||||
|
||||
- name: Checkout code (manual)
|
||||
if: ${{ github.event_name != 'workflow_run' }}
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Export PYTHONPATH
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "PYTHONPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Prepare Python environment
|
||||
uses: ./.gitea/actions/setup-python-env
|
||||
with:
|
||||
use-system-python: 'true'
|
||||
install-playwright: 'true'
|
||||
run-db-setup: 'true'
|
||||
|
||||
- name: Run e2e tests
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p artifacts/pytest
|
||||
pytest tests/e2e --junitxml=artifacts/pytest/e2e-results.xml
|
||||
|
||||
- name: Upload pytest results
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: e2e-pytest-results
|
||||
path: artifacts/pytest/
|
||||
|
||||
- name: Upload Playwright artifacts
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: playwright-artifacts
|
||||
path: playwright-report
|
||||
@@ -1,72 +0,0 @@
|
||||
name: Run Tests
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Export PYTHONPATH
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "PYTHONPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Prepare Python environment
|
||||
uses: ./.gitea/actions/setup-python-env
|
||||
with:
|
||||
use-system-python: 'true'
|
||||
run-db-setup: 'false'
|
||||
create-venv: 'true'
|
||||
|
||||
- name: Run lint checks
|
||||
run: ruff check .
|
||||
|
||||
unit:
|
||||
name: Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DATABASE_DRIVER: postgresql
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_PORT: '5432'
|
||||
DATABASE_NAME: calminer_ci
|
||||
DATABASE_USER: calminer
|
||||
DATABASE_PASSWORD: secret
|
||||
DATABASE_SCHEMA: public
|
||||
DATABASE_SUPERUSER: calminer
|
||||
DATABASE_SUPERUSER_PASSWORD: secret
|
||||
DATABASE_SUPERUSER_DB: calminer_ci
|
||||
DATABASE_URL: postgresql+psycopg2://calminer:secret@postgres:5432/calminer_ci
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_DB: calminer_ci
|
||||
POSTGRES_USER: calminer
|
||||
POSTGRES_PASSWORD: secret
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U calminer -d calminer_ci"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Export PYTHONPATH
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "PYTHONPATH=${{ github.workspace }}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Prepare Python environment
|
||||
uses: ./.gitea/actions/setup-python-env
|
||||
with:
|
||||
use-system-python: 'true'
|
||||
create-venv: 'true'
|
||||
|
||||
- name: Run unit tests
|
||||
run: pytest tests/unit
|
||||
Reference in New Issue
Block a user