Add workflow to build and test docker image

This commit is contained in:
Oliver 2021-10-07 22:00:03 +11:00
parent 50d861e763
commit 59866a692c
4 changed files with 85 additions and 2 deletions

View File

@ -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 name: Docker Build

View File

@ -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>' tag
name: Docker Publish name: Docker Publish

41
.github/workflows/docker_test.yaml vendored Normal file
View File

@ -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

40
ci/check_api_endpoint.py Normal file
View File

@ -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")