diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 000000000..3e4e48b0b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c111a9099 --- /dev/null +++ b/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 " + +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 diff --git a/build/Dockerfile b/build/Dockerfile deleted file mode 100644 index 6305f9ae4..000000000 --- a/build/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM docker:dind -LABEL maintainer "Ansible " - -ENV TEST_USER=molecule -ENV TEST_HOME_DIR=/home/${TEST_USER} - -ENV PACKAGES="\ - gcc \ - make \ - bash \ - shadow \ - libffi-dev \ - musl-dev \ - openssl-dev \ - py-pip \ - python \ - python-dev \ - linux-headers \ - sudo \ - rsync \ - curl \ - ruby \ - ruby-dev \ - ruby-etc \ - ruby-rdoc \ - ruby-irb \ - git \ - openssh-client \ -" - -ENV PIP_PACKAGES="\ - molecule[azure,docker,docs,ec2,gce,lxc,openstack,vagrant,windows] \ - virtualenv \ -" - -ENV GEM_PACKAGES="\ - rubocop \ -" - -RUN \ - apk update \ - && apk add --update --no-cache ${PACKAGES} \ - && rm -rf /var/cache/apk/* \ - && pip install --upgrade pip \ - && pip install --no-cache-dir ${PIP_PACKAGES} \ - && rm -rf /root/.cache \ - && gem install ${GEM_PACKAGES} \ - && adduser -D -h ${TEST_HOME_DIR} ${TEST_USER} \ - && usermod -aG dockremap ${TEST_USER} \ - && echo "${TEST_USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -USER ${TEST_USER} -ENV SHELL /bin/bash diff --git a/build/Makefile b/build/Makefile deleted file mode 100644 index 7c1a140e4..000000000 --- a/build/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -USER := ansible -TAG := $(shell git describe --tags `git rev-list --tags --max-count=1`) -LATEST_IMAGE := $(USER)/molecule:latest -TAG_IMAGE := $(USER)/molecule:$(TAG) - -clean: - @echo "+ $@" - rm -rf build/lib/ - rm -rf dist/ - -build: clean - @echo "+ $@" - git clean -d -x -f molecule/cookiecutter/ - ./.tox/py27-ansible25-unit/bin/python setup.py sdist bdist_wheel - ./.tox/py36-ansible25-unit/bin/python setup.py sdist bdist_wheel - -docker-build: - @echo "+ $@" - cd build && sudo docker build \ - --pull \ - --rm=true \ - --no-cache \ - -t $(LATEST_IMAGE) -t $(TAG_IMAGE) . - -push: - ./.tox/py27-ansible25-unit/bin/twine upload dist/* -r pypi - -.PHONY: build diff --git a/tox.ini b/tox.ini index cb7c7e649..3fdb691c6 100644 --- a/tox.ini +++ b/tox.ini @@ -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