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:
|
2022-08-14 22:20:03 +00:00
|
|
|
types: [ published ]
|
2022-05-28 23:40:37 +00:00
|
|
|
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- 'master'
|
2023-11-21 13:25:13 +00:00
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- 'master'
|
2022-12-26 12:27:12 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
jobs:
|
|
|
|
|
2023-11-21 13:25:13 +00:00
|
|
|
paths-filter:
|
|
|
|
name: Filter
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
outputs:
|
|
|
|
docker: ${{ steps.filter.outputs.docker }}
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
|
|
|
|
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # pin@v2.11.1
|
|
|
|
id: filter
|
|
|
|
with:
|
|
|
|
filters: |
|
|
|
|
docker:
|
|
|
|
- .github/workflows/docker.yaml
|
|
|
|
- docker/**
|
|
|
|
- docker-compose.yml
|
|
|
|
- docker.dev.env
|
|
|
|
- Dockerfile
|
2023-12-04 20:05:48 +00:00
|
|
|
- requirements.txt
|
2023-11-21 13:25:13 +00:00
|
|
|
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Build the docker image
|
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
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 }}
|
2022-10-22 01:45:50 +00:00
|
|
|
python_version: 3.9
|
2022-05-28 23:40:37 +00:00
|
|
|
steps:
|
|
|
|
- name: Check out repo
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
|
2022-10-22 01:45:50 +00:00
|
|
|
- name: Set Up Python ${{ env.python_version }}
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # pin@v4.7.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: |
|
2022-06-06 22:57:51 +00:00
|
|
|
pip install requests
|
2022-12-05 02:10:14 +00:00
|
|
|
pip install pyyaml
|
2022-05-30 23:50:38 +00:00
|
|
|
python3 ci/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
|
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)
|
2022-05-28 23:40:37 +00:00
|
|
|
run: |
|
2022-12-08 13:15:26 +00:00
|
|
|
docker-compose build --no-cache
|
2022-11-22 12:28:16 +00:00
|
|
|
- name: Update Docker Image
|
2022-06-28 03:47:10 +00:00
|
|
|
run: |
|
2022-05-28 23:40:37 +00:00
|
|
|
docker-compose run inventree-dev-server invoke update
|
2022-07-01 11:03:25 +00:00
|
|
|
docker-compose run inventree-dev-server invoke setup-dev
|
2022-05-28 23:40:37 +00:00
|
|
|
docker-compose up -d
|
|
|
|
docker-compose 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 }}" >> docker.dev.env
|
2022-12-08 13:15:26 +00:00
|
|
|
docker-compose run inventree-dev-server invoke test --disable-pty
|
2023-06-23 07:25:59 +00:00
|
|
|
docker-compose run inventree-dev-server invoke test --migrations --disable-pty
|
2022-12-05 02:10:14 +00:00
|
|
|
docker-compose down
|
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'
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # pin@v3.0.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'
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # pin@v3.1.2
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Login to Dockerhub
|
|
|
|
if: github.event_name != 'pull_request'
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # pin@v3.0.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'
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # pin@v3.0.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
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # pin@v5.0.0
|
2022-07-20 08:32:18 +00:00
|
|
|
with:
|
|
|
|
images: |
|
|
|
|
inventree/inventree
|
2023-04-05 12:01:05 +00:00
|
|
|
ghcr.io/inventree/inventree
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Build and Push
|
2022-07-20 06:20:58 +00:00
|
|
|
id: build-and-push
|
2022-05-28 23:40:37 +00:00
|
|
|
if: github.event_name != 'pull_request'
|
2023-10-24 22:18:53 +00:00
|
|
|
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # pin@v5.0.0
|
2022-05-28 23:40:37 +00:00
|
|
|
with:
|
|
|
|
context: .
|
2023-06-05 09:27:27 +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
|
2022-05-30 23:50:38 +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 }}
|
2023-04-05 12:01:05 +00:00
|
|
|
|
2022-07-20 06:20:58 +00:00
|
|
|
- name: Sign the published image
|
2023-01-04 00:21:25 +00:00
|
|
|
if: ${{ false }} # github.event_name != 'pull_request'
|
2022-07-20 06:20:58 +00:00
|
|
|
env:
|
|
|
|
COSIGN_EXPERIMENTAL: "true"
|
2023-10-24 22:18:53 +00:00
|
|
|
run: cosign sign ${{ steps.meta.outputs.tags }}@${{ steps.build-and-push.outputs.digest }}
|