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'
|
|
|
|
|
2022-12-26 12:27:12 +00:00
|
|
|
# pull_request:
|
|
|
|
# branches:
|
|
|
|
# - 'master'
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
jobs:
|
|
|
|
|
|
|
|
# Build the docker image
|
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
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
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3.1.0
|
2022-10-22 01:45:50 +00:00
|
|
|
- name: Set Up Python ${{ env.python_version }}
|
|
|
|
uses: actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984 # pin@v4.3.0
|
|
|
|
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
|
2022-12-15 20:42:07 +00:00
|
|
|
docker-compose run inventree-dev-server pip install --upgrade setuptools
|
2022-05-28 23:40:37 +00:00
|
|
|
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'
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # pin@v2.1.0
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
if: github.event_name != 'pull_request'
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: docker/setup-buildx-action@95cb08cb2672c73d4ffd2f422e6d11953d2a9c70 # pin@v2.1.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'
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: sigstore/cosign-installer@7cc35d7fdbe70d4278a0c96779081e6fac665f88 # pin@v2.8.0
|
2022-05-28 23:40:37 +00:00
|
|
|
- name: Login to Dockerhub
|
|
|
|
if: github.event_name != 'pull_request'
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # pin@v2.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'
|
|
|
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # pin@v2
|
|
|
|
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
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: docker/metadata-action@12cce9efe0d49980455aaaca9b071c0befcdd702 # pin@v4.1.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'
|
2022-10-17 02:46:12 +00:00
|
|
|
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # pin@v3.2.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"
|
2022-08-14 22:20:03 +00:00
|
|
|
run: cosign sign ${{ steps.meta.outputs.tags }}@${{
|
|
|
|
steps.build-and-push.outputs.digest }}
|