Packaging fixes
This commit is contained in:
parent
fa6103d007
commit
959b06c425
19 changed files with 389 additions and 68 deletions
62
.github/workflows/build.yml
vendored
Normal file
62
.github/workflows/build.yml
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
name: build-image-from-tag
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
jobs:
|
||||
build:
|
||||
# Don't build the image if the registry credentials are not set, the ref is not a tag or it doesn't contain '-v'
|
||||
if: ${{ vars.REGISTRY_USER != '' && secrets.REGISTRY_PASS != '' && startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-v') }}
|
||||
runs-on: docker
|
||||
container:
|
||||
image: git.badblocks.dev/oci/pkmntrade-club_web:latest
|
||||
# Mount the dind socket on the container at the default location
|
||||
options: -v /dind/docker.sock:/var/run/docker.sock
|
||||
steps:
|
||||
- name: Extract image name and tag from git and get registry name from env
|
||||
id: job_data
|
||||
run: |
|
||||
echo "::set-output name=img_name::${GITHUB_REF_NAME%%-v*}"
|
||||
echo "::set-output name=img_tag::${GITHUB_REF_NAME##*-v}"
|
||||
echo "::set-output name=registry::$(
|
||||
echo "${{ github.server_url }}" | sed -e 's%https://%%'
|
||||
)"
|
||||
echo "::set-output name=oci_registry_prefix::$(
|
||||
echo "${{ github.server_url }}/oci" | sed -e 's%https://%%'
|
||||
)"
|
||||
- name: Checkout the repo
|
||||
uses: actions/checkout@v4
|
||||
- name: Export build dir and Dockerfile
|
||||
id: build_data
|
||||
run: |
|
||||
img="${{ steps.job_data.outputs.img_name }}"
|
||||
build_dir="$(pwd)/${img}"
|
||||
dockerfile="${build_dir}/Dockerfile"
|
||||
if [ -f "$dockerfile" ]; then
|
||||
echo "::set-output name=build_dir::$build_dir"
|
||||
echo "::set-output name=dockerfile::$dockerfile"
|
||||
else
|
||||
echo "Couldn't find the Dockerfile for the '$img' image"
|
||||
exit 1
|
||||
fi
|
||||
- name: Login to the Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ steps.job_data.outputs.registry }}
|
||||
username: ${{ vars.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASS }}
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Build and Push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
${{ steps.job_data.outputs.oci_registry_prefix }}/${{ steps.job_data.outputs.img_name }}:${{ steps.job_data.outputs.img_tag }}
|
||||
${{ steps.job_data.outputs.oci_registry_prefix }}/${{ steps.job_data.outputs.img_name }}:latest
|
||||
context: ${{ steps.build_data.outputs.build_dir }}
|
||||
file: ${{ steps.build_data.outputs.dockerfile }}
|
||||
build-args: |
|
||||
OCI_REGISTRY_PREFIX=${{ steps.job_data.outputs.oci_registry_prefix }}/
|
||||
119
.github/workflows/test.yml
vendored
Normal file
119
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
name: Build, Test, and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
python-version: [ 3.13 ]
|
||||
database-name:
|
||||
- test_db
|
||||
database-password:
|
||||
- postgres
|
||||
database-user:
|
||||
- postgres
|
||||
database-host:
|
||||
- 127.0.0.1
|
||||
database-port:
|
||||
- 5432
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
env:
|
||||
POSTGRES_DB: ${{ matrix.database-name }}
|
||||
POSTGRES_USER: ${{ matrix.database-user }}
|
||||
POSTGRES_PASSWORD: ${{ matrix.database-password }}
|
||||
ports:
|
||||
- 5432:5432
|
||||
# Set health checks to wait until postgres has started
|
||||
options:
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2.3.1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Format with black
|
||||
run: |
|
||||
pip install black
|
||||
# format the files with black
|
||||
black .
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
pip install flake8
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
- name: Sort imports
|
||||
run: |
|
||||
pip install isort
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
isort .
|
||||
isort --check --diff .
|
||||
- name: Setup test database
|
||||
env:
|
||||
POSTGRES_DB_NAME: ${{ matrix.database-name }}
|
||||
POSTGRES_USER: ${{ matrix.database-user }}
|
||||
POSTGRES_PASSWORD: ${{ matrix.database-password }}
|
||||
POSTGRES_DB_HOST: ${{ matrix.database-host }}
|
||||
POSTGRES_DB_PORT: ${{ matrix.database-port }}
|
||||
POSTGRES_DB: ${{ matrix.database-name }}
|
||||
run: |
|
||||
export DATABASE_URL=postgres://${{ matrix.database-user }}:${{ matrix.database-password }}@${{ matrix.database-host }}:${{ matrix.database-port }}/${{ matrix.database-name }}
|
||||
export SECRET_KEY=test-secret-key
|
||||
export DEBUG=1
|
||||
- name: Run migrations
|
||||
run: |
|
||||
export DATABASE_URL=postgres://${{ matrix.database-user }}:${{ matrix.database-password }}@${{ matrix.database-host }}:${{ matrix.database-port }}/${{ matrix.database-name }}
|
||||
export SECRET_KEY=test-secret-key
|
||||
export DEBUG=1
|
||||
export ALLOWED_HOSTS=localhost
|
||||
export GITHUB_WORKFLOW=True
|
||||
export MODE=workflow
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
python manage.py migrate --run-syncdb
|
||||
python manage.py check
|
||||
- name: Run tests
|
||||
run: |
|
||||
python manage.py test
|
||||
env:
|
||||
DATABASE_URL: postgres://${{ matrix.database-user }}:${{ matrix.database-password }}@${{ matrix.database-host }}:${{ matrix.database-port }}/${{ matrix.database-name }}
|
||||
SECRET_KEY: test-secret-key
|
||||
DEBUG: 1
|
||||
ALLOWED_HOSTS: localhost
|
||||
GITHUB_WORKFLOW: True
|
||||
MODE: workflow
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- name: Build the images and start the containers
|
||||
run: |
|
||||
export GITHUB_WORKFLOW=True
|
||||
export MODE="Test"
|
||||
docker-compose -f docker-compose.yml build
|
||||
docker-compose -f docker-compose.yml up -d
|
||||
# run: docker-compose up -d --build
|
||||
- name: Stop containers
|
||||
if: always()
|
||||
run: docker-compose -f "docker-compose.yml" down
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue