Skip to content

Commit

Permalink
Automate container creation on release (#304)
Browse files Browse the repository at this point in the history
This is based on the Dockerfile provided at #284 with some
tweaks.

Makefile is adjusted to allow easy experimentation, but the
primary work here uses github actions.

The container is built any time a tag that looks like a
semver is pushed. This is in alignment with the existing
release handling.
  • Loading branch information
cdent committed Nov 29, 2021
1 parent 8fbd547 commit 73dd899
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: docker


on:
push:
tags:
- '[2-9].[0-9]+.[0-9]+'


jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: cdent/gabbi
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args:
GABBI_VERSION=${{steps.meta.outputs.version}}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3-alpine
MAINTAINER Chris Dent <cdent@anticdent.org>

ARG GABBI_VERSION
RUN python -m venv /app
COPY . /app/
RUN cd /app && PBR_VERSION=${GABBI_VERSION} /app/bin/pip --no-cache-dir install .

ENTRYPOINT ["/app/bin/python", "-m", "gabbi.runner"]
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# simple Makefile for some common tasks
.PHONY: clean test dist release pypi tagv docs

gabbi-version := $(shell python -c 'import gabbi; print gabbi.__version__')

clean:
find . -name "*.pyc" |xargs rm || true
rm -r dist || true
Expand All @@ -12,9 +14,7 @@ clean:
rm -r gabbi.egg-info || true

tagv:
git tag -s \
-m `python -c 'import gabbi; print gabbi.__version__'` \
`python -c 'import gabbi; print gabbi.__version__'`
git tag -s -m ${gabbi-version} ${gabbi-version}
git push origin main --tags

cleanagain:
Expand All @@ -41,3 +41,6 @@ release: clean test cleanagain tagv pypi
pypi:
python3 setup.py sdist bdist_wheel
twine upload -s dist/*

docker:
docker build --build-arg GABBI_VERSION=${gabbi-version} -t gabbi:${gabbi-version} .
7 changes: 7 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ Python 3 comes with a built-in tool to create virtual environments::
This way we can later use ``deactivate`` and safely remove the ``venv``
directory, thus erasing any trace of gabbi from the system.

If you prefer to not install gabbi, or perhaps want to use it in a dynamic
fashion in a CI setting, there is an official container image hosted at
`docker hub`_ as ``cdent/gabbi``. It allows running :doc:`gabbi-run <runner>`
with any arguments you might need, providing tests on STDIN of via a mounted
volume.

.. _docker hub: https://hub.docker.com/repository/docker/cdent/gabbi
.. _virtualenv: https://virtualenv.pypa.io

0 comments on commit 73dd899

Please sign in to comment.