Skip to content

Commit

Permalink
Switch to multi-stage builds using ansible/python-builder
Browse files Browse the repository at this point in the history
This is the first step towards supporting multi-stage builds in
ansible-runner. In this commit, we are simplifying our Dockerfile and
using a builder image to build python wheels. We then use the compiled
wheels to install into the base image, allowing us to remove compile
time dependencies.

Depends-On: ansible/python-builder-image#7
Depends-On: ansible/python-base-image#3
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
  • Loading branch information
pabelanger committed Dec 15, 2020
1 parent e5cd0ae commit 73d6692
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 233 deletions.
185 changes: 1 addition & 184 deletions .dockerignore
@@ -1,184 +1 @@
.git/

### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
### Vim template
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/dictionaries
.idea/**/shelf

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/
cmake-build-release/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Specific to ansible-runner
test/
ansible_runner/
docs/
packaging/
.github/
*.md
*.rst
*.toml
*.py
.tox
7 changes: 7 additions & 0 deletions .zuul.d/jobs.yaml
Expand Up @@ -4,13 +4,20 @@
parent: ansible-build-container-image
description: Build ansible-runner container image
pre-run: playbooks/ansible-runner-build-container-image/pre.yaml
required-projects:
- github.com/ansible/ansible
timeout: 2700
provides: ansible-runner-container-image
requires:
- python-builder-container-image
- python-base-container-image
vars: &ansible_runner_image_vars
container_images: &container_images
- context: .
registry: quay.io
repository: quay.io/ansible/ansible-runner
siblings:
- github.com/ansible/ansible
tags:
# If zuul.tag is defined: [ '3', '3.19', '3.19.0' ]. Only works for 3-component tags.
# Otherwise: ['latest']
Expand Down
46 changes: 10 additions & 36 deletions Dockerfile
@@ -1,23 +1,16 @@
ARG BASE_IMAGE=docker.io/fedora:32
FROM quay.io/ansible/python-builder:latest as builder
# =============================================================================

FROM ${BASE_IMAGE}
ARG ZUUL_SIBLINGS=""
COPY . /tmp/src
RUN assemble

# Install system packages for use in all images
RUN dnf install -y \
python3-pip \
gcc \
rsync \
openssh-clients \
sshpass \
glibc-langpack-en \
git \
https://github.com/krallin/tini/releases/download/v0.19.0/tini_0.19.0-amd64.rpm && \
rm -rf /var/cache/dnf
FROM quay.io/ansible/python-base:latest as base
# =============================================================================

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1

# Install python packages for use in all images
RUN pip3 install --no-cache-dir bindep
COPY --from=builder /output/ /output
RUN /output/install-from-bindep \
&& rm -rf /output

# Prepare the /runner folder, seed the folder with demo data
ADD demo /runner
Expand Down Expand Up @@ -45,29 +38,10 @@ VOLUME /runner

WORKDIR /runner

ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV HOME=/home/runner

ADD utils/entrypoint.sh /bin/entrypoint
RUN chmod +x /bin/entrypoint

ENTRYPOINT ["entrypoint"]
CMD ["ansible-runner", "run", "/runner"]


# Install ansible-runner
#TODO optionally install ansible-runner from rpm

ARG RUNNER_VERSION=2.0.0
COPY dist/ansible-runner-${RUNNER_VERSION}.tar.gz /tmp/
RUN pip3 install --no-cache-dir /tmp/ansible-runner-${RUNNER_VERSION}.tar.gz


# Install ansible
#TODO optionally install ansible from rpm
#ADD https://releases.ansible.com/ansible-runner/ansible-runner.el8.repo /etc/yum.repos.d/ansible-runner.repo

ARG ANSIBLE_BRANCH=devel
RUN pip3 install --no-cache-dir https://github.com/ansible/ansible/archive/${ANSIBLE_BRANCH}.tar.gz
4 changes: 4 additions & 0 deletions bindep.txt
Expand Up @@ -2,7 +2,11 @@
# see https://docs.openstack.org/infra/bindep/ for additional information.

gcc-c++ [test platform:rpm]
git
openssh-clients
python3-devel [test !platform:centos-7 platform:rpm]
python3 [test !platform:centos-7 platform:rpm]
python36 [test !platform:centos-7 !platform:fedora-28]
podman [test platform:rpm]
sshpass [epel]
rsync
18 changes: 6 additions & 12 deletions playbooks/ansible-runner-build-container-image/pre.yaml
@@ -1,15 +1,9 @@
---
- hosts: all
tasks:
# NOTE(pabelanger): We should consider pushing this into bindep.txt file, as build dependency.
- name: Ensure python3-wheel is installed
become: true
package:
name: python3-wheel
state: present

- name: Run build-python-release role
include_role:
name: build-python-release
vars:
release_python: python3
# NOTE(pabelanger): Remove option to download ansible-core from github
# directly. We've already cloned the contents locally.
- name: Update requirements.txt file
args:
chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
shell: sed -e 's|.*egg=||g' -i requirements.txt
1 change: 1 addition & 0 deletions requirements.txt
@@ -0,0 +1 @@
git+https://github.com/ansible/ansible.git@devel#egg=ansible-core
2 changes: 1 addition & 1 deletion utils/entrypoint.sh
Expand Up @@ -32,4 +32,4 @@ if [[ -n "${LAUNCHED_BY_RUNNER}" ]]; then
export ANSIBLE_CALLBACK_PLUGINS="$(dirname $RUNNER_CALLBACKS)"
fi

exec tini -- "${@}"
exec /usr/local/bin/dumb-init -- "${@}"

0 comments on commit 73d6692

Please sign in to comment.