From 59866a692cefde50d7ba58ddc11c4ede90ef7c48 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 7 Oct 2021 22:00:03 +1100 Subject: [PATCH 1/4] Add workflow to build and test docker image --- .github/workflows/docker_stable.yaml | 3 +- .github/workflows/docker_tag.yaml | 3 +- .github/workflows/docker_test.yaml | 41 ++++++++++++++++++++++++++++ ci/check_api_endpoint.py | 40 +++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker_test.yaml create mode 100644 ci/check_api_endpoint.py diff --git a/.github/workflows/docker_stable.yaml b/.github/workflows/docker_stable.yaml index 3d435e40da..1f3c7749c7 100644 --- a/.github/workflows/docker_stable.yaml +++ b/.github/workflows/docker_stable.yaml @@ -1,4 +1,5 @@ -# Build and push latest docker image on push to master branch +# Build and push docker image on push to 'stable' branch +# Docker build will be uploaded to dockerhub with the 'inventree:stable' tag name: Docker Build diff --git a/.github/workflows/docker_tag.yaml b/.github/workflows/docker_tag.yaml index b3b0c53d12..90b8f72505 100644 --- a/.github/workflows/docker_tag.yaml +++ b/.github/workflows/docker_tag.yaml @@ -1,4 +1,5 @@ -# Publish docker images to dockerhub +# Publish docker images to dockerhub on a tagged release +# Docker build will be uploaded to dockerhub with the 'invetree:' tag name: Docker Publish diff --git a/.github/workflows/docker_test.yaml b/.github/workflows/docker_test.yaml new file mode 100644 index 0000000000..36638784f2 --- /dev/null +++ b/.github/workflows/docker_test.yaml @@ -0,0 +1,41 @@ +# Test that the InvenTree docker image compiles correctly + +# This CI action runs on pushes to either the master or stable branches + +# 1. Build the development docker image (as per the documentation) +# 2. Install requied python libs into the docker container +# 3. Launch the container +# 4. Check that the API endpoint is available + +name: Docker Test + +on: + push: + branches: + - 'master' + - 'stable' + + pull_request: + branches-ignore: + - l10* + +jobs: + + docker: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + - name: Build Docker Image + run: | + cd docker + docker-compose -f docker-compose.dev.yml build + docker-compose -f docker-compose.dev.yml run inventree-dev-server invoke update + docker-compose -f docker-compose.dev.yml up -d + - name: Sleepy Time + run: sleep 60 + - name: Test API + run: | + pip install requests + python3 ci/check_api_endpoint.py diff --git a/ci/check_api_endpoint.py b/ci/check_api_endpoint.py new file mode 100644 index 0000000000..2969c64792 --- /dev/null +++ b/ci/check_api_endpoint.py @@ -0,0 +1,40 @@ +""" +Test that the root API endpoint is available. +""" + +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import json +import requests + +# We expect the server to be running on the local host +url = "http://localhost:8000/api/" + +print("Testing InvenTree API endpoint") + +response = requests.get(url) + +assert(response.status_code == 200) + +print("- Response 200 OK") + +data = json.loads(response.text) + +required_keys = [ + 'server', + 'version', + 'apiVersion', + 'worker_running', +] + +for key in required_keys: + assert(key in data) + print(f"- Found key '{key}'") + +# Check that the worker is running +assert(data['worker_running']) + +print("- Background worker is operational") + +print("API Endpoint Tests Passed OK") From 53f18368ba4b6dc2916c14f66269616dcc7b95ee Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 7 Oct 2021 22:04:42 +1100 Subject: [PATCH 2/4] This should break - Trying to install a fake package --- docker/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e4ebbc1b4b..ef055e9ca7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -68,7 +68,8 @@ RUN apk add --no-cache git make bash \ # PostgreSQL support postgresql postgresql-contrib postgresql-dev libpq \ # MySQL/MariaDB support - mariadb-connector-c mariadb-dev mariadb-client + mariadb-connector-c mariadb-dev mariadb-client \ + some-made-up-package # Install required base-level python packages COPY requirements.txt requirements.txt From 4c3b5554809c04938506e9f2e8d94bdae298edf5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 7 Oct 2021 22:25:55 +1100 Subject: [PATCH 3/4] Revert "This should break" This reverts commit 53f18368ba4b6dc2916c14f66269616dcc7b95ee. --- docker/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index ef055e9ca7..e4ebbc1b4b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -68,8 +68,7 @@ RUN apk add --no-cache git make bash \ # PostgreSQL support postgresql postgresql-contrib postgresql-dev libpq \ # MySQL/MariaDB support - mariadb-connector-c mariadb-dev mariadb-client \ - some-made-up-package + mariadb-connector-c mariadb-dev mariadb-client # Install required base-level python packages COPY requirements.txt requirements.txt From b4ff4c4018ba09a7b0fb98a87ea814dededb597c Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 7 Oct 2021 22:26:39 +1100 Subject: [PATCH 4/4] Only run on pushes --- .github/workflows/docker_test.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/docker_test.yaml b/.github/workflows/docker_test.yaml index 36638784f2..0067f337e5 100644 --- a/.github/workflows/docker_test.yaml +++ b/.github/workflows/docker_test.yaml @@ -15,10 +15,6 @@ on: - 'master' - 'stable' - pull_request: - branches-ignore: - - l10* - jobs: docker: