Skip to content

Commit

Permalink
Add make targets to lint and test the code and to build Docker image
Browse files Browse the repository at this point in the history
The lint and test make targets use `tox` and can be found in `tox.mk`.

The `docker` make target builds the Commodore Docker image and provides
a binary version which is derived from the git repository state (using
git-describe) and embedded into Commodore during the Docker image build.

Signed-off-by: Simon Gerber <simon.gerber@vshn.ch>
  • Loading branch information
simu committed Feb 14, 2020
1 parent ad36ee1 commit 7e1e44c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Expand Up @@ -46,6 +46,10 @@ RUN ssh-keyscan -t rsa git.vshn.net > /app/.known_hosts

ENV GIT_SSH=/app/tools/ssh

ARG BINARY_VERSION

RUN sed -ie "s/^__version__ = 'Unreleased'$/__version__ = '$BINARY_VERSION'/" ./commodore/__init__.py

RUN chown 1001 /app
USER 1001

Expand Down
24 changes: 24 additions & 0 deletions Makefile
Expand Up @@ -37,3 +37,27 @@ $(web_dir)/index.html: playbook.yml $(pages)
check:
$(vale_cmd)


###
### Section for Commodore linting and testing
###

include tox.mk

###
### Section for Commodore image build using GitHub actions
###

# Project parameters
BINARY_NAME ?= commodore

BINARY_VERSION = $(shell git describe --tags --always --dirty --match=v* || (echo "command failed $$?"; exit 1))
VERSION ?= $(BINARY_VERSION)

IMAGE_NAME ?= docker.io/vshn/$(BINARY_NAME):$(VERSION)

.PHONY: docker

docker:
docker build --build-arg BINARY_VERSION=$(BINARY_VERSION) -t $(IMAGE_NAME) .
@echo built image $(IMAGE_NAME)
5 changes: 4 additions & 1 deletion commodore/__init__.py
Expand Up @@ -6,4 +6,7 @@
__email__ = 'simon.gerber@vshn.ch'
__license__ = 'BSD'
__url__ = 'https://git.vshn.net/syn/commodore/'
__version__ = '0.1.0dev1'
# NOTE: This variable is set during the Docker image build process and *MUST*
# be set somehow during the package build process if python package builds are
# setup in the future
__version__ = 'Unreleased'
4 changes: 3 additions & 1 deletion commodore/cli.py
Expand Up @@ -5,6 +5,8 @@
from .compile import compile as _compile
from .component_template import create_component

from . import __version__

pass_config = click.make_pass_decorator(Config)

verbosity = click.option('-v', '--verbose', count=True,
Expand All @@ -19,7 +21,7 @@
@click.option('--customer-git-base', metavar='URL',
help='Base directory for customer Git config repositories')
@verbosity
@click.version_option('0.0.1', prog_name='commodore')
@click.version_option(__version__, prog_name='commodore')
@click.pass_context
# pylint: disable=too-many-arguments
def commodore(ctx, api_url, api_token, global_git_base, customer_git_base, verbose):
Expand Down
29 changes: 29 additions & 0 deletions tox.mk
@@ -0,0 +1,29 @@
.PHONY: lint_flake8 lint_pylint lint_safety lint_bandit lint_readme

TOX_COMMAND = docker run --rm -v $(PWD):/src:ro -v $(PWD)/.tox:/app/.tox docker.io/painless/tox

lint_flake8:
$(TOX_COMMAND) tox -e flake8

lint_pylint:
$(TOX_COMMAND) tox -e pylint

lint_safety:
$(TOX_COMMAND) tox -e safety

lint_bandit:
$(TOX_COMMAND) tox -e bandit

lint_readme:
$(TOX_COMMAND) tox -e readme

.PHONY: test_py36 test_py37 test_py38

test_py36:
$(TOX_COMMAND) tox -e py36

test_py37:
$(TOX_COMMAND) tox -e py37

test_py38:
$(TOX_COMMAND) tox -e py38

0 comments on commit 7e1e44c

Please sign in to comment.