Skip to content

Commit

Permalink
🎨 Refactor building a docker image
Browse files Browse the repository at this point in the history
* Add linode extra
* Drop manual apk update and cleanup
* Put Molecule extras into env var
* Retrieve a Docker tag as pbr does
  • Loading branch information
webknjaz committed Mar 5, 2019
1 parent 0efcd54 commit bce7bfe
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 81 deletions.
1 change: 1 addition & 0 deletions .dockerignore
65 changes: 65 additions & 0 deletions Dockerfile
@@ -0,0 +1,65 @@
# This is a multi-stage build which requires Docker 17.05 or higher
FROM python:3.7-alpine as molecule-builder

WORKDIR /usr/src/molecule

ENV PACKAGES="\
gcc \
git \
libffi-dev \
make \
musl-dev \
openssl-dev \
"
RUN apk add --update --no-cache ${PACKAGES}

ENV MOLECULE_EXTRAS="azure,docker,docs,ec2,gce,linode,lxc,openstack,vagrant,windows"

ADD . .
RUN \
pip wheel \
-w dist \
".[${MOLECULE_EXTRAS}]"

# ✄---------------------------------------------------------------------
# This is an actual target container:

FROM python:3.7-alpine
LABEL maintainer "Ansible <info@ansible.com>"

ENV PACKAGES="\
docker \
ruby \
"
ENV BUILD_DEPS="\
gcc \
libc-dev \
make \
ruby-dev \
ruby-rdoc \
"

ENV PIP_INSTALL_ARGS="\
--only-binary :all: \
--no-index \
-f /usr/src/molecule/dist \
"

ENV GEM_PACKAGES="\
rubocop \
"

ENV MOLECULE_EXTRAS="azure,docker,docs,ec2,gce,linode,lxc,openstack,vagrant,windows"

COPY --from=molecule-builder \
/usr/src/molecule/dist \
/usr/src/molecule/dist

RUN \
apk add --update --no-cache ${BUILD_DEPS} ${PACKAGES} && \
pip install ${PIP_INSTALL_ARGS} "molecule[${MOLECULE_EXTRAS}]" && \
gem install ${GEM_PACKAGES} && \
apk del --no-cache ${BUILD_DEPS} && \
rm -rf /root/.cache

ENV SHELL /bin/bash
53 changes: 0 additions & 53 deletions build/Dockerfile

This file was deleted.

28 changes: 0 additions & 28 deletions build/Makefile

This file was deleted.

26 changes: 26 additions & 0 deletions tox.ini
Expand Up @@ -189,3 +189,29 @@ usedevelop = False
commands =
python -m setup checkdocs check --metadata --restructuredtext --strict --verbose
twine check .tox/dist/*

[testenv:build-docker]
# skip under Windows
platform = ^darwin|^linux
# `usedevelop = True` overrided `skip_install` instruction, it's unwanted
usedevelop = False
# don't install Molecule in this env
skip_install = True
# don't install any Python dist deps
deps =
pbr
# setuptools_scm
# reset pre-commands
commands_pre =
# build the docker container
commands =
sh -c '\
TAG=$(python -c "from pbr.packaging import get_version; print(get_version(\".\"))") && \
#TAG=$(python -c "from setuptools_scm import get_version; print(get_version())") && \
echo Building version "$TAG"... && \
sudo docker build \
--pull --rm \
{posargs:-t ansible/molecule:$TAG} .\
'
whitelist_externals =
sh

0 comments on commit bce7bfe

Please sign in to comment.