Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Replace ansible-builder with plan container building
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 7, 2022
1 parent 4424026 commit 9aba676
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
tox:
name: ${{ matrix.toxenv }}

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

strategy:
fail-fast: false
Expand Down
52 changes: 19 additions & 33 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
ARG EE_BASE_IMAGE=quay.io/ansible/ansible-runner:latest
ARG EE_BUILDER_IMAGE=quay.io/ansible/ansible-builder:latest

FROM $EE_BASE_IMAGE as galaxy
ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS=
USER root

ADD _build /build
WORKDIR /build

RUN ansible-galaxy role install -r requirements.yml --roles-path "/usr/share/ansible/roles"
RUN ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path "/usr/share/ansible/collections"

FROM $EE_BUILDER_IMAGE as builder

COPY --from=galaxy /usr/share/ansible /usr/share/ansible

ADD _build/requirements.txt requirements.txt
ADD _build/bindep.txt bindep.txt
RUN ansible-builder introspect --sanitize --user-pip=requirements.txt --user-bindep=bindep.txt --write-bindep=/tmp/src/bindep.txt --write-pip=/tmp/src/requirements.txt
RUN assemble

# Overly simplified single stage build process: we take all binary dependencies
# using dnf and use pip to install the rest.
ARG EE_BASE_IMAGE=quay.io/fedora/fedora:latest
FROM $EE_BASE_IMAGE
USER root

COPY --from=galaxy /usr/share/ansible /usr/share/ansible

COPY --from=builder /output/ /output/
RUN /output/install-from-bindep && rm -rf /output/wheels
RUN set -ex && /output/install-from-bindep && rm -rf /output/wheels && alternatives --set python /usr/bin/python3 && dnf -y upgrade && dnf autoremove
COPY _build/requirements.in /root/requirements.in
COPY _build/requirements.txt /root/requirements.txt
RUN \
dnf update -y && \
dnf -y upgrade && \
dnf install -y podman python3-pip git python3-cffi python3-cryptography python3-ruamel-yaml python3-pyyaml python3-pyrsistent && \
dnf autoremove
RUN \
pip3 install -r /root/requirements.in -c /root/requirements.txt && \
rm -rf $(pip3 cache dir)
# add some helpful CLI commands to check we do not remove them inadvertently and output some helpful version information at build time.
RUN set -ex \
&& molecule --version \
&& molecule drivers \
&& ansible-lint --version \
&& podman --version \
&& python --version \
&& git --version
&& ansible-lint --version \
&& molecule --version \
&& molecule drivers \
&& podman --version \
&& python3 --version \
&& git --version
28 changes: 11 additions & 17 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ requires =

[testenv]
description =
build: Build `{env:ANSIBLE_BUILDER_TARGET_CONTAINER_NAME}:{env:ANSIBLE_BUILDER_TARGET_CONTAINER_TAG}` container
build: Build `{env:TARGET_CONTAINER_NAME}:{env:TARGET_CONTAINER_TAG}` container
podman: Build container using podman
docker: Build container using docker
allowlist_externals =
Expand All @@ -24,23 +24,16 @@ allowlist_externals =
podman
basepython = python3
commands_pre =
/bin/bash -c "{env:CONTAINER_RUNTIME:podman} rmi {env:ANSIBLE_BUILDER_TARGET_CONTAINER_NAME}:{env:ANSIBLE_BUILDER_TARGET_CONTAINER_TAG} || true"
/bin/bash -c "{env:CONTAINER_RUNTIME:podman} rmi {env:TARGET_CONTAINER_NAME}:{env:TARGET_CONTAINER_TAG} || true"
commands =
ansible-builder build \
-v3 \
-c . \
{posargs:-t {env:ANSIBLE_BUILDER_TARGET_CONTAINER_NAME}:{env:ANSIBLE_BUILDER_TARGET_CONTAINER_TAG}} \
{env:ANSIBLE_BUILDER_POST_ARGS:}
# safety measure to keep container image under control
# https://github.com/wemake-services/docker-image-size-limit/issues/223
docker: disl {env:ANSIBLE_BUILDER_TARGET_CONTAINER_NAME}:{env:ANSIBLE_BUILDER_TARGET_CONTAINER_TAG} 1700MiB
# --platform linux/amd64
{env:CONTAINER_RUNTIME:podman} buildx build --load . -t {env:TARGET_CONTAINER_NAME}:{env:TARGET_CONTAINER_TAG}
{env:CONTAINER_RUNTIME:podman} inspect --format='\{\{ json .Size \}\}' quay.io/ansible/creator-ee
deps =
ansible-builder
docker-image-size-limit
paramiko # indirect docker-image-size-limit
passenv =
ANSIBLE_BUILDER_TARGET_CONTAINER_NAME
ANSIBLE_BUILDER_TARGET_CONTAINER_TAG
TARGET_CONTAINER_NAME
TARGET_CONTAINER_TAG
HOME
# all below needed by container engines
CONTAINER_RUNTIME
Expand All @@ -50,10 +43,11 @@ passenv =
SSH_AUTH_SOCK
TERM
setenv =
podman: CONTAINER_RUNTIME=podman
docker: CONTAINER_RUNTIME=docker
ANSIBLE_BUILDER_POST_ARGS = --container-runtime={env:CONTAINER_RUNTIME:podman}
ANSIBLE_BUILDER_TARGET_CONTAINER_NAME = {env:ANSIBLE_BUILDER_TARGET_CONTAINER_NAME:quay.io/ansible/creator-ee}
ANSIBLE_BUILDER_TARGET_CONTAINER_TAG = {env:ANSIBLE_BUILDER_TARGET_CONTAINER_TAG:latest}
TARGET_CONTAINER_NAME = {env:TARGET_CONTAINER_NAME:quay.io/ansible/creator-ee}
TARGET_CONTAINER_TAG = {env:TARGET_CONTAINER_TAG:latest}

[testenv:lint]
description = Run all linters
Expand All @@ -70,4 +64,4 @@ commands_pre =
deps =
commands =
echo "Starting container, wait for login prompt."
{env:CONTAINER_RUNTIME:podman} run -it {env:ANSIBLE_BUILDER_TARGET_CONTAINER_NAME}:{env:ANSIBLE_BUILDER_TARGET_CONTAINER_TAG} /bin/bash
{env:CONTAINER_RUNTIME:podman} run -it {env:TARGET_CONTAINER_NAME}:{env:TARGET_CONTAINER_TAG} /bin/bash

0 comments on commit 9aba676

Please sign in to comment.