aaredb/.gitlab-ci.yml
2024-12-16 14:25:42 +01:00

69 lines
1.9 KiB
YAML

# GitLab CI/CD Configuration for FastAPI
stages:
- test
- deploy
- release
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip_cache"
VIRTUAL_ENV: ".venv"
# Cache for dependencies
cache:
paths:
- .pip_cache/
before_script: # common setup for every job
- python3.8 -m venv $VIRTUAL_ENV
- source $VIRTUAL_ENV/bin/activate
- pip install --upgrade pip
test:
stage: test
script:
- source $VIRTUAL_ENV/bin/activate
- pip install -r requirements.txt
- export PYTHONPATH=$PYTHONPATH:/home/gitlab-runner/builds/t3_38ooWt/0/mx/heidi-v2/backend
- pytest --cov=app --cov-report=xml # Run tests and generate coverage report
lint:
stage: test
script:
- source $VIRTUAL_ENV/bin/activate
- pip install pre-commit black flake8
- >
pre-commit run --all-files || {
echo "Pre-commit formatting failed. Auto-fixing formatting issues with black..." &&
black backend/ &&
exit 0;
}
deploy:
stage: deploy
only:
- main
variables:
CI: "true" # Mark this as a CI run
ENVIRONMENT: dev # Use dev environment settings
PORT: 8081 # Set the port for the application
script:
- echo "Setting up dependencies..."
- source $VIRTUAL_ENV/bin/activate
- pip install -r requirements.txt
- echo "Verifying SSL files..."
- echo "Running the application with dev SSL certificates on port $PORT..."
- cd backend
- python3.8 -m main
release:
stage: release
when: manual
variables:
TWINE_USERNAME: gitlab-ci-token # Keep username same
TWINE_PASSWORD: $CI_JOB_TOKEN # Use PAT stored in GitLab CI/CD Variables
script:
- cd backend/python-client # Navigate to the folder where the package was generated
- python3 -m venv .venv
- source .venv/bin/activate
- pip install -U pip twine
- twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*