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-06-18 13:42:05 +00:00
|
|
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4.1.7
|
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-06-18 13:42:05 +00:00
|
|
|
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4.1.7
|
2022-10-22 01:45:50 +00:00
|
|
|
- name: Set Up Python ${{ env.python_version }}
|
2024-07-15 23:44:07 +00:00
|
|
|
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # pin@v5.1.1
|
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-05-27 07:49:05 +00:00
|
|
|
pip install --require-hashes -r contrib/dev_reqs/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:19:35 +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:19:35 +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
|
2024-06-19 04:38:46 +00:00
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke test --disable-pty
|
|
|
|
- name: Run Migration Tests
|
|
|
|
run: |
|
|
|
|
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke test --migrations
|
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'
|
2024-07-24 04:09:36 +00:00
|
|
|
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # pin@v3.2.0
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-08-09 22:13:43 +00:00
|
|
|
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # pin@v3.6.1
|
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-08-12 23:43:07 +00:00
|
|
|
uses: sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # pin@v3.6.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
|
2024-08-11 01:03:18 +00:00
|
|
|
echo "skip_dockerhub_login=true" >> $GITHUB_OUTPUT
|
2024-03-21 22:08:24 +00:00
|
|
|
else
|
2024-08-11 01:03:18 +00:00
|
|
|
echo "skip_dockerhub_login=false" >> $GITHUB_OUTPUT
|
2024-03-21 22:08:24 +00:00
|
|
|
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-07-24 04:09:36 +00:00
|
|
|
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # pin@v3.3.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-07-24 04:09:36 +00:00
|
|
|
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # pin@v3.3.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-08-19 23:38:02 +00:00
|
|
|
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # pin@v6.7.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 }}
|