Compare commits
10 Commits
bcd993d57c
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
| 958c165721 | |||
| 6e835c83eb | |||
| 75924fca84 | |||
| ac9ffddbde | |||
| 4e5a4c645d | |||
| e9678b6736 | |||
| e5e346b26a | |||
| b0e623d68e | |||
| 30dbc13fae | |||
| 31b9a1058a |
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
* text=auto
|
||||||
|
|
||||||
|
Dockerfile text eol=lf
|
||||||
150
.gitea/workflows/ci-build.yml
Normal file
150
.gitea/workflows/ci-build.yml
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
name: CI - Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
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
|
||||||
|
env:
|
||||||
|
DEFAULT_BRANCH: ${{ env.DEFAULT_BRANCH }}
|
||||||
|
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:
|
||||||
|
needs: build
|
||||||
|
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
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.event.head_commit && 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.event.head_commit && 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.event.head_commit && contains(github.event.head_commit.message, '[deploy staging]')
|
||||||
|
run: |
|
||||||
|
kubectl set image deployment/calminer-app calminer=${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest
|
||||||
|
kubectl apply -f k8s/configmap.yaml
|
||||||
|
kubectl apply -f k8s/secret.yaml
|
||||||
|
kubectl rollout status deployment/calminer-app
|
||||||
|
|
||||||
|
- name: Collect staging deployment logs
|
||||||
|
if: github.event.head_commit && 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.event.head_commit && contains(github.event.head_commit.message, '[deploy production]')
|
||||||
|
run: |
|
||||||
|
kubectl set image deployment/calminer-app calminer=${REGISTRY_URL}/allucanget/${REGISTRY_CONTAINER_NAME}:latest
|
||||||
|
kubectl apply -f k8s/configmap.yaml
|
||||||
|
kubectl apply -f k8s/secret.yaml
|
||||||
|
kubectl rollout status deployment/calminer-app
|
||||||
|
|
||||||
|
- name: Collect production deployment logs
|
||||||
|
if: github.event.head_commit && 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
|
||||||
44
.gitea/workflows/ci-lint.yml
Normal file
44
.gitea/workflows/ci-lint.yml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
name: CI - Lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
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: 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
|
||||||
73
.gitea/workflows/ci-test.yml
Normal file
73
.gitea/workflows/ci-test.yml
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
name: CI - Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
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:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
|
||||||
|
- 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
|
||||||
30
.gitea/workflows/ci.yml
Normal file
30
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
- v2
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
uses: ./.gitea/workflows/ci-lint.yml
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
test:
|
||||||
|
needs: lint
|
||||||
|
uses: ./.gitea/workflows/ci-test.yml
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- lint
|
||||||
|
- test
|
||||||
|
uses: ./.gitea/workflows/ci-build.yml
|
||||||
|
secrets: inherit
|
||||||
@@ -1,212 +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: Cache pip dependencies
|
|
||||||
# uses: actions/cache@v4
|
|
||||||
# with:
|
|
||||||
# path: /root/.cache/pip
|
|
||||||
# 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: /root/.cache/pip
|
|
||||||
# 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 --junitxml=pytest-report.xml
|
|
||||||
|
|
||||||
- name: Upload test artifacts
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
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
|
|
||||||
@@ -120,12 +120,6 @@ jobs:
|
|||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
pip install -r requirements-test.txt
|
pip install -r requirements-test.txt
|
||||||
|
|
||||||
- name: Install Playwright system dependencies
|
|
||||||
run: playwright install-deps
|
|
||||||
|
|
||||||
- name: Install Playwright browsers
|
|
||||||
run: playwright install
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
env:
|
env:
|
||||||
DATABASE_DRIVER: ${{ env.DB_DRIVER }}
|
DATABASE_DRIVER: ${{ env.DB_DRIVER }}
|
||||||
@@ -139,7 +133,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Upload test artifacts
|
- name: Upload test artifacts
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: test-artifacts
|
name: test-artifacts
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
42
Dockerfile
42
Dockerfile
@@ -41,8 +41,25 @@ if url:
|
|||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
PY
|
PY
|
||||||
apt-get update
|
APT_PROXY_CONFIG=/etc/apt/apt.conf.d/01proxy
|
||||||
apt-get install -y --no-install-recommends build-essential gcc libpq-dev
|
|
||||||
|
apt_update_with_fallback() {
|
||||||
|
if ! apt-get update; then
|
||||||
|
rm -f "$APT_PROXY_CONFIG"
|
||||||
|
apt-get update
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_install_with_fallback() {
|
||||||
|
if ! apt-get install -y --no-install-recommends "$@"; then
|
||||||
|
rm -f "$APT_PROXY_CONFIG"
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_update_with_fallback
|
||||||
|
apt_install_with_fallback build-essential gcc libpq-dev
|
||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip wheel --no-deps --wheel-dir /wheels -r requirements.txt
|
pip wheel --no-deps --wheel-dir /wheels -r requirements.txt
|
||||||
apt-get purge -y --auto-remove build-essential gcc
|
apt-get purge -y --auto-remove build-essential gcc
|
||||||
@@ -88,8 +105,25 @@ if url:
|
|||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
PY
|
PY
|
||||||
apt-get update
|
APT_PROXY_CONFIG=/etc/apt/apt.conf.d/01proxy
|
||||||
apt-get install -y --no-install-recommends libpq5
|
|
||||||
|
apt_update_with_fallback() {
|
||||||
|
if ! apt-get update; then
|
||||||
|
rm -f "$APT_PROXY_CONFIG"
|
||||||
|
apt-get update
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_install_with_fallback() {
|
||||||
|
if ! apt-get install -y --no-install-recommends "$@"; then
|
||||||
|
rm -f "$APT_PROXY_CONFIG"
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_update_with_fallback
|
||||||
|
apt_install_with_fallback libpq5
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import List, Optional
|
from typing import List
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, PositiveFloat, ValidationError, field_validator
|
from pydantic import BaseModel, Field, PositiveFloat, ValidationError, field_validator
|
||||||
|
|
||||||
|
|||||||
@@ -1102,7 +1102,7 @@ def seed_navigation(engine: Engine, is_sqlite: bool) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
link_insert_sql = text(
|
link_insert_sql = text(
|
||||||
f"""
|
"""
|
||||||
INSERT INTO navigation_links (
|
INSERT INTO navigation_links (
|
||||||
group_id, parent_link_id, slug, label, route_name, href_override,
|
group_id, parent_link_id, slug, label, route_name, href_override,
|
||||||
match_prefix, sort_order, icon, tooltip, required_roles, is_enabled, is_external
|
match_prefix, sort_order, icon, tooltip, required_roles, is_enabled, is_external
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ from schemas.calculations import (
|
|||||||
CapexCalculationResult,
|
CapexCalculationResult,
|
||||||
CapexCategoryBreakdown,
|
CapexCategoryBreakdown,
|
||||||
CapexComponentInput,
|
CapexComponentInput,
|
||||||
CapexParameters,
|
|
||||||
CapexTotals,
|
CapexTotals,
|
||||||
CapexTimelineEntry,
|
CapexTimelineEntry,
|
||||||
CashFlowEntry,
|
CashFlowEntry,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Iterable, List, Optional, Sequence
|
from typing import Iterable, List, Sequence
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
|
|
||||||
from models.navigation import NavigationGroup, NavigationLink
|
from models.navigation import NavigationLink
|
||||||
from services.repositories import NavigationRepository
|
from services.repositories import NavigationRepository
|
||||||
from services.session import AuthSession
|
from services.session import AuthSession
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ class NavigationService:
|
|||||||
) -> List[NavigationLinkDTO]:
|
) -> List[NavigationLinkDTO]:
|
||||||
resolved_roles = tuple(roles)
|
resolved_roles = tuple(roles)
|
||||||
mapped: List[NavigationLinkDTO] = []
|
mapped: List[NavigationLinkDTO] = []
|
||||||
for link in sorted(links, key=lambda l: (l.sort_order, l.id)):
|
for link in sorted(links, key=lambda x: (x.sort_order, x.id)):
|
||||||
if not include_children and link.parent_link_id is not None:
|
if not include_children and link.parent_link_id is not None:
|
||||||
continue
|
continue
|
||||||
if not include_disabled and (not link.is_enabled):
|
if not include_disabled and (not link.is_enabled):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import secrets
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Tuple, cast
|
from typing import Tuple, cast
|
||||||
|
|
||||||
@@ -70,7 +71,8 @@ def navigation_client() -> Tuple[TestClient, StubNavigationService, AuthSession]
|
|||||||
|
|
||||||
user = cast(User, object())
|
user = cast(User, object())
|
||||||
session = AuthSession(
|
session = AuthSession(
|
||||||
tokens=SessionTokens(access_token="token", refresh_token=None),
|
tokens=SessionTokens(
|
||||||
|
access_token=secrets.token_urlsafe(16), refresh_token=None),
|
||||||
user=user,
|
user=user,
|
||||||
role_slugs=("viewer",),
|
role_slugs=("viewer",),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session, sessionmaker
|
from sqlalchemy.orm import Session, sessionmaker
|
||||||
|
|
||||||
from models import Role, User, UserRole
|
from models import Role, User, UserRole
|
||||||
from dependencies import get_auth_session, require_current_user
|
from dependencies import get_auth_session, get_jwt_settings, require_current_user
|
||||||
from services.security import hash_password
|
from services.security import decode_access_token, hash_password
|
||||||
from services.session import AuthSession, SessionTokens
|
from services.session import AuthSession, SessionTokens
|
||||||
from tests.utils.security import random_password, random_token
|
from tests.utils.security import random_password, random_token
|
||||||
|
|
||||||
@@ -334,6 +334,7 @@ class TestLoginFlowEndToEnd:
|
|||||||
|
|
||||||
# Override to anonymous for login
|
# Override to anonymous for login
|
||||||
app = cast(FastAPI, client.app)
|
app = cast(FastAPI, client.app)
|
||||||
|
original_override = app.dependency_overrides.get(get_auth_session)
|
||||||
app.dependency_overrides[get_auth_session] = lambda: AuthSession.anonymous(
|
app.dependency_overrides[get_auth_session] = lambda: AuthSession.anonymous(
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
@@ -347,14 +348,21 @@ class TestLoginFlowEndToEnd:
|
|||||||
"location") == "http://testserver/"
|
"location") == "http://testserver/"
|
||||||
set_cookie_header = login_response.headers.get("set-cookie", "")
|
set_cookie_header = login_response.headers.get("set-cookie", "")
|
||||||
assert "calminer_access_token=" in set_cookie_header
|
assert "calminer_access_token=" in set_cookie_header
|
||||||
|
|
||||||
# Now with cookies, GET / should show dashboard
|
|
||||||
dashboard_response = client.get("/")
|
|
||||||
assert dashboard_response.status_code == 200
|
|
||||||
assert "Dashboard" in dashboard_response.text or "metrics" in dashboard_response.text
|
|
||||||
finally:
|
finally:
|
||||||
app.dependency_overrides.pop(get_auth_session, None)
|
app.dependency_overrides.pop(get_auth_session, None)
|
||||||
|
|
||||||
|
access_cookie = client.cookies.get("calminer_access_token")
|
||||||
|
refresh_cookie = client.cookies.get("calminer_refresh_token")
|
||||||
|
assert access_cookie, "Access token cookie was not set"
|
||||||
|
assert refresh_cookie, "Refresh token cookie was not set"
|
||||||
|
|
||||||
|
jwt_settings = get_jwt_settings()
|
||||||
|
payload = decode_access_token(access_cookie, jwt_settings)
|
||||||
|
assert payload.sub == str(user.id)
|
||||||
|
assert payload.scopes == ["auth"], "Unexpected access token scopes"
|
||||||
|
if original_override is not None:
|
||||||
|
app.dependency_overrides[get_auth_session] = original_override
|
||||||
|
|
||||||
def test_logout_redirects_to_login_and_clears_session(self, client: TestClient) -> None:
|
def test_logout_redirects_to_login_and_clears_session(self, client: TestClient) -> None:
|
||||||
# Assuming authenticated from conftest
|
# Assuming authenticated from conftest
|
||||||
logout_response = client.get("/logout", follow_redirects=False)
|
logout_response = client.get("/logout", follow_redirects=False)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from main import app
|
from main import app
|
||||||
|
from scripts.init_db import init_db
|
||||||
|
|
||||||
|
|
||||||
def test_login_form_post_does_not_trigger_json_error():
|
def test_login_form_post_does_not_trigger_json_error():
|
||||||
@@ -8,6 +9,7 @@ def test_login_form_post_does_not_trigger_json_error():
|
|||||||
the JSON "Invalid JSON payload" error which indicates the middleware
|
the JSON "Invalid JSON payload" error which indicates the middleware
|
||||||
attempted to parse non-JSON bodies.
|
attempted to parse non-JSON bodies.
|
||||||
"""
|
"""
|
||||||
|
init_db()
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
|
|
||||||
resp = client.post(
|
resp = client.post(
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ def session(engine) -> Iterator[Session]:
|
|||||||
def test_project_scenario_cascade_deletes(session: Session) -> None:
|
def test_project_scenario_cascade_deletes(session: Session) -> None:
|
||||||
project = Project(name="Cascade Mine",
|
project = Project(name="Cascade Mine",
|
||||||
operation_type=MiningOperationType.OTHER)
|
operation_type=MiningOperationType.OTHER)
|
||||||
scenario_a = Scenario(
|
Scenario(
|
||||||
name="Base Case", status=ScenarioStatus.DRAFT, project=project)
|
name="Base Case", status=ScenarioStatus.DRAFT, project=project)
|
||||||
scenario_b = Scenario(
|
Scenario(
|
||||||
name="Expansion", status=ScenarioStatus.DRAFT, project=project)
|
name="Expansion", status=ScenarioStatus.DRAFT, project=project)
|
||||||
|
|
||||||
session.add(project)
|
session.add(project)
|
||||||
|
|||||||
Reference in New Issue
Block a user