2022-05-28 23:40:37 +00:00
|
|
|
# Build, test and push InvenTree docker image
|
|
|
|
# This workflow runs under any of the following conditions:
|
|
|
|
#
|
|
|
|
# - Push to the master branch
|
|
|
|
# - Publish release
|
|
|
|
#
|
|
|
|
# The following actions are performed:
|
|
|
|
#
|
|
|
|
# - Check that the version number matches the current branch or tag
|
|
|
|
# - Build the InvenTree docker image
|
|
|
|
# - Run suite of unit tests against the build image
|
|
|
|
# - Push the compiled, tested image to dockerhub
|
|
|
|
|
|
|
|
name: Docker
|
|
|
|
|
|
|
|
on:
|
|
|
|
release:
|
2024-04-21 12:20:13 +00:00
|
|
|
types: [published]
|
2022-05-28 23:40:37 +00:00
|
|
|
|
|
|
|
push:
|
|
|
|
branches:
|
2024-04-21 12:20:13 +00:00
|
|
|
- "master"
|
2023-11-21 13:25:13 +00:00
|
|
|
pull_request:
|
|
|
|
branches:
|
2024-04-21 12:20:13 +00:00
|
|
|
- "master"
|
|
|
|
|
2024-03-20 23:11:49 +00:00
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
jobs:
|
2023-11-21 13:25:13 +00:00
|
|
|
paths-filter:
|
2024-03-20 23:11:49 +00:00
|
|
|
permissions:
|
2024-04-21 12:20:13 +00:00
|
|
|
contents: read # for dorny/paths-filter to fetch a list of changed files
|
|
|
|
pull-requests: read # for dorny/paths-filter to read pull requests
|
2023-11-21 13:25:13 +00:00
|
|
|
name: Filter
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
outputs:
|
|
|
|
docker: ${{ steps.filter.outputs.docker }}
|
|
|
|
|
|
|
|
steps:
|
2024-05-08 21:04:38 +00:00
|
|
|
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # pin@v4.1.5
|
2024-03-20 23:50:28 +00:00
|
|
|
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # pin@v3.0.2
|
2023-11-21 13:25:13 +00:00
|
|
|
id: filter
|
|
|
|
with:
|
|
|
|
filters: |
|
|
|
|
docker:
|
|
|
|
- .github/workflows/docker.yaml
|
2024-04-27 00:51:42 +00:00
|
|
|
- contrib/container/**
|
|
|
|
- src/backend/InvenTree/InvenTree/settings.py
|
|
|
|
- src/backend/requirements.txt
|
2024-02-01 01:25:24 +00:00
|
|
|
- tasks.py
|
2023-11-21 13:25:13 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Build the docker image
|
|
|
|
build:
|
2023-11-21 13:25:13 +00:00
|
|
|
needs: paths-filter
|
|
|
|
if: needs.paths-filter.outputs.docker == 'true' || github.event_name == 'release' || github.event_name == 'push'
|
2022-07-20 06:20:58 +00:00
|
|
|
permissions:
|
2023-04-05 12:01:05 +00:00
|
|
|
contents: read
|
|
|
|
packages: write
|
2022-07-20 06:20:58 +00:00
|
|
|
id-token: write
|
2022-05-30 23:50:38 +00:00
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
2024-02-26 22:50:44 +00:00
|
|
|
python_version: "3.11"
|
2024-04-21 12:20:13 +00:00
|
|
|
runs-on: ubuntu-latest # in the future we can try to use alternative runners here
|
2024-02-26 22:50:44 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
steps:
|
|
|
|
- name: Check out repo
|
2024-05-08 21:04:38 +00:00
|
|
|
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # pin@v4.1.5
|
2022-10-22 01:45:50 +00:00
|
|
|
- name: Set Up Python ${{ env.python_version }}
|
2024-03-26 20:11:37 +00:00
|
|
|
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # pin@v5.1.0
|
2022-10-22 01:45:50 +00:00
|
|
|
with:
|
|
|
|
python-version: ${{ env.python_version }}
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Version Check
|
|
|
|
run: |
|
2024-04-23 07:15:52 +00:00
|
|
|
pip install --require-hashes -r .github/requirements.txt
|
2022-05-30 23:50:38 +00:00
|
|
|
python3 .github/scripts/version_check.py
|
2022-05-28 23:40:37 +00:00
|
|
|
echo "git_commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
|
|
|
echo "git_commit_date=$(git show -s --format=%ci)" >> $GITHUB_ENV
|
2024-03-04 11:50:00 +00:00
|
|
|
- name: Test Docker Image
|
|
|
|
id: test-docker
|
|
|
|
run: |
|
|
|
|
docker build . --target production --tag inventree-test -f contrib/container/Dockerfile
|
|
|
|
docker run --rm inventree-test invoke --version
|
|
|
|
docker run --rm inventree-test invoke --list
|
|
|
|
docker run --rm inventree-test gunicorn --version
|
|
|
|
docker run --rm inventree-test pg_dump --version
|
2024-05-14 23:24:22 +00:00
|
|
|
docker run --rm inventree-test test -f /home/inventree/init.sh
|
|
|
|
docker run --rm inventree-test test -f /home/inventree/tasks.py
|
|
|
|
docker run --rm inventree-test test -f /home/inventree/gunicorn.conf.py
|
|
|
|
docker run --rm inventree-test test -f /home/inventree/src/backend/requirements.txt
|
2024-04-04 12:55:55 +00:00
|
|
|
docker run --rm inventree-test test -f /home/inventree/src/backend/InvenTree/manage.py
|
2022-06-28 03:47:10 +00:00
|
|
|
- name: Build Docker Image
|
2022-07-26 21:50:54 +00:00
|
|
|
# Build the development docker image (using docker-compose.yml)
|
2024-02-26 22:50:44 +00:00
|
|
|
run: docker compose --project-directory . -f contrib/container/dev-docker-compose.yml build --no-cache
|
2022-11-22 12:28:16 +00:00
|
|
|
- name: Update Docker Image
|
2022-06-28 03:47:10 +00:00
|
|
|
run: |
|
2024-05-14 23:24:22 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke install
|
2022-05-28 23:40:37 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke update
|
2022-07-01 11:03:25 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke setup-dev
|
2022-05-28 23:40:37 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml up -d
|
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke wait
|
2022-07-26 21:50:54 +00:00
|
|
|
- name: Check Data Directory
|
|
|
|
# The following file structure should have been created by the docker image
|
|
|
|
run: |
|
|
|
|
test -d data
|
|
|
|
test -d data/env
|
|
|
|
test -d data/pgdb
|
|
|
|
test -d data/media
|
|
|
|
test -d data/static
|
|
|
|
test -d data/plugins
|
|
|
|
test -f data/config.yaml
|
|
|
|
test -f data/plugins.txt
|
|
|
|
test -f data/secret_key.txt
|
2022-12-05 02:10:14 +00:00
|
|
|
- name: Run Unit Tests
|
|
|
|
run: |
|
2022-12-26 12:27:12 +00:00
|
|
|
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> contrib/container/docker.dev.env
|
2022-12-08 13:15:26 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke test --disable-pty
|
2023-06-23 07:25:59 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke test --migrations --disable-pty
|
2022-12-05 02:10:14 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml down
|
2024-02-26 00:23:49 +00:00
|
|
|
- name: Clean up test folder
|
|
|
|
run: |
|
|
|
|
rm -rf InvenTree/_testfolder
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Set up QEMU
|
|
|
|
if: github.event_name != 'pull_request'
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # pin@v3.0.0
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-04-29 21:47:18 +00:00
|
|
|
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # pin@v3.3.0
|
2022-07-20 06:20:58 +00:00
|
|
|
- name: Set up cosign
|
2022-07-26 21:50:54 +00:00
|
|
|
if: github.event_name != 'pull_request'
|
2024-04-15 23:56:34 +00:00
|
|
|
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # pin@v3.5.0
|
2024-03-21 22:08:24 +00:00
|
|
|
- name: Check if Dockerhub login is required
|
|
|
|
id: docker_login
|
|
|
|
run: |
|
|
|
|
if [ -z "${{ secrets.DOCKER_USERNAME }}" ]; then
|
|
|
|
echo "skip_dockerhub_login=true" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "skip_dockerhub_login=false" >> $GITHUB_ENV
|
|
|
|
fi
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Login to Dockerhub
|
2024-03-21 22:08:24 +00:00
|
|
|
if: github.event_name != 'pull_request' && steps.docker_login.outputs.skip_dockerhub_login != 'true'
|
2024-03-23 07:11:47 +00:00
|
|
|
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # pin@v3.1.0
|
2022-05-28 23:40:37 +00:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
2023-04-05 12:01:05 +00:00
|
|
|
|
|
|
|
- name: Log into registry ghcr.io
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-03-23 07:11:47 +00:00
|
|
|
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # pin@v3.1.0
|
2023-04-05 12:01:05 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2022-07-20 06:20:58 +00:00
|
|
|
- name: Extract Docker metadata
|
2022-07-26 21:50:54 +00:00
|
|
|
if: github.event_name != 'pull_request'
|
2022-07-20 06:20:58 +00:00
|
|
|
id: meta
|
2024-03-20 23:50:49 +00:00
|
|
|
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # pin@v5.5.1
|
2022-07-20 08:32:18 +00:00
|
|
|
with:
|
|
|
|
images: |
|
|
|
|
inventree/inventree
|
2024-03-21 22:08:24 +00:00
|
|
|
ghcr.io/${{ github.repository }}
|
2023-04-05 12:01:05 +00:00
|
|
|
|
2024-03-04 11:50:00 +00:00
|
|
|
- name: Push Docker Images
|
|
|
|
id: push-docker
|
2022-05-28 23:40:37 +00:00
|
|
|
if: github.event_name != 'pull_request'
|
2024-03-20 23:59:04 +00:00
|
|
|
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # pin@v5.3.0
|
2022-05-28 23:40:37 +00:00
|
|
|
with:
|
|
|
|
context: .
|
2024-04-03 08:58:17 +00:00
|
|
|
file: ./contrib/container/Dockerfile
|
2024-03-02 00:29:20 +00:00
|
|
|
platforms: linux/amd64,linux/arm64
|
2022-05-29 03:47:29 +00:00
|
|
|
push: true
|
2023-06-11 13:37:03 +00:00
|
|
|
sbom: true
|
|
|
|
provenance: false
|
2022-05-28 23:40:37 +00:00
|
|
|
target: production
|
2024-02-29 20:01:46 +00:00
|
|
|
tags: ${{ env.docker_tags }}
|
2022-05-31 04:26:35 +00:00
|
|
|
build-args: |
|
|
|
|
commit_hash=${{ env.git_commit_hash }}
|
|
|
|
commit_date=${{ env.git_commit_date }}
|