Skip to content

Commit

Permalink
Address running multiplatform builds in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
saville committed Apr 2, 2024
1 parent 9c69450 commit 2ad4e97
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 39 deletions.
38 changes: 22 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
FROM python:3.11

COPY . /buildrunner-source
FROM python:3.11-bookworm

ENV BUILDRUNNER_CONTAINER 1
ENV PIP_DEFAULT_TIMEOUT 60

# Install the docker client for multiplatform builds
RUN apt update && \
apt install ca-certificates curl && \
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc && \
apt clean all
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list

# Some of these packages are to have native installs so that arm packages will not be built
RUN \
set -x && \
useradd -m buildrunner && \
apt update && \
apt -y install \
docker-ce-cli \
docker-buildx-plugin \
libffi-dev \
libssl-dev \
libyaml-dev \
Expand All @@ -21,24 +31,26 @@ RUN \
python3-dev && \
apt clean all

# Running pip this way is strange, but it allows it to detect the system packages installed
# Install requirements first and then buildrunner itself for better docker image layer caching
# HACK - For some reason, 'python3 setup.py install' produces an error with 'jaraco-classes' package
# but replacing it with 'jaraco.classes' in the requirements.txt works. ¯\_(ツ)_/¯
COPY *requirements.txt /tmp/setup/
RUN \
cd /buildrunner-source && \
cd /tmp/setup && \
python3 -m pip install -U pip && \
sed -i s/jaraco-classes/jaraco.classes/ requirements.txt && \
python3 -m pip install \
-r requirements.txt && \
python3 -m pip install \
-r test_requirements.txt && \
rm -rf /tmp/setup
COPY . /buildrunner-source
RUN \
cd /buildrunner-source && \
sed -i s/jaraco-classes/jaraco.classes/ requirements.txt && \
python3 setup.py install && \
rm -rf /buildrunner-source

#RUN \
# set -ex; \
# apt-get -y install vim

# The following will install docker-engine. It's not needed for the container to run,
# but was very helpful during development
#RUN \
Expand All @@ -50,11 +62,5 @@ RUN \
# apt-get update; \
# apt-get -y install docker-engine

ENV BUILDRUNNER_CONTAINER 1

ENTRYPOINT ["/usr/local/bin/buildrunner"]
CMD []

# Local Variables:
# fill-column: 100
# End:
13 changes: 7 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ shows the different configuration options available:
# Buildrunner will attempt to pull these images from the remote registry.
# If the pull is unsuccessful, buildrunner will still pass in the image name
# into --cache-from, allowing a cache check in the host machine cache
# NOTE: Does not work for multi-platform builds
# NOTE: Does not work for multiplatform builds
cache_from:
- my-images/image:PR-123
- my-images/image:latest
Expand All @@ -279,11 +279,12 @@ shows the different configuration options available:
<or>
platform: linux/arm64/v8 # an apple m1 architecture
# To build multi-platform images, add each platform to be built to this list and buildrunner
# To build multiplatform images, add each platform to be built to this list and buildrunner
# will use docker buildx to build and provide a single tag containing all architectures specified.
# Note that buildx may be configured to build some platforms with emulation and therefore builds
# may take longer with this option specified. Also note that when using the platforms option, it is not
# valid to also specify the platform option.
# Notes:
# * buildx may be configured to build some platforms with emulation and therefore builds may take longer with this option specified
# * multiplatform builds cannot be used in the buildrunner docker image unless the 'build-registry' global config parameter is specified
# * only one of platform or platforms may be specified
platforms:
- linux/amd64
- linux/arm64/v8
Expand Down Expand Up @@ -371,7 +372,7 @@ the run step:
- test-step
- validation-step
# This is not supported in the same step as a multi-platform build.
# This is not supported in the same step as a multiplatform build.
run:
# xfail indicates whether the run operation is expected to fail. The
# default is false - the operation is expected to succeed. If xfail
Expand Down
9 changes: 8 additions & 1 deletion buildrunner/docker/multiplatform_image_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright 2023 Adobe
Copyright 2024 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
Expand All @@ -24,6 +24,7 @@
from buildrunner.config.models import MP_LOCAL_REGISTRY
from buildrunner.docker import get_dockerfile
from buildrunner.docker.image_info import BuiltImageInfo, BuiltTaggedImage
from buildrunner.errors import BuildRunnerConfigurationError


LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -118,6 +119,12 @@ def _start_local_registry(self):
str: The name of the registry container
"""
if not self._local_registry_is_running:
if os.getenv("BUILDRUNNER_CONTAINER"):
raise BuildRunnerConfigurationError(
"Multiplatform builds cannot be used in the buildrunner Docker image without "
"a 'build-registry' configured in the global buildrunner configuration."
)

LOGGER.debug("Starting local docker registry")
image = "registry"
if self._docker_registry:
Expand Down
14 changes: 6 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,17 @@ which simply calls the ``BASH`` script.
sure that you are using the `BASH shell
<https://www.laptopmag.com/articles/use-bash-shell-windows-10>`_ enhancements for Windows or that
you have something installed that enables the use of ``sh``, or else this method will not work.
If you are using WSL and the hyper-v installtion of docker:
If you are using WSL and the hyper-v installation of docker:

1. Click on the "Expose deamon on tcp://localhost:2375 without tls" from inside of the docker settings
2. Use the pip install method inside of the WSL subsystem
3. Export your docker host ``DOCKER_HOST=tcp://localhost:2375`` inside of WSL

.. note:: MAC USERS: If you are using the docker version of buildrunner and are getting the error
``docker-credential-osxkeychain not installed or not available in PATH``, you can do one of 2
things:
.. note:: MAC USERS: If you are using the docker version of buildrunner and are getting an error that
docker-credential-<key> is ``not installed or not available in PATH``, you can do one of the following:

1. If the authentication information for the docker registry in question is in your
``$HOME/.docker/config.json``, remove ``"credsStore" : "osxkeychain"`` and try again
2. Use this `BASH <https://github.com/adobe/buildrunner/blob/master/scripts/buildrunnerOSXCredStore>`__ script along with this `python
<https://github.com/adobe/buildrunner/blob/master/scripts/resolve-config.py>`_
script - this will pull the docker credentials from the OSX
keychain and inject them into the docker container
2. Use this `BASH <https://github.com/adobe/buildrunner/blob/master/scripts/buildrunnerOSXCredStore>`__ script along
with this `python <https://github.com/adobe/buildrunner/blob/master/scripts/resolve-config.py>`_
script. This will pull the docker credentials from the OSX keychain and inject them into the docker container
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ twine>=3.2.0
vcsinfo>=2.1.105
graphlib-backport>=1.0.3
timeout-decorator>=0.5.0
python-on-whales>=0.64.3
python-on-whales>=0.70.1
pydantic>=2.4.2
retry2>=0.9.5
colorlog>=6.8.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pygments==2.15.1
# rich
pynacl==1.5.0
# via paramiko
python-on-whales==0.65.0
python-on-whales==0.70.1
# via -r requirements.in
pyyaml==6.0
# via -r requirements.in
Expand Down
15 changes: 9 additions & 6 deletions scripts/buildrunner
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash

if [ -z "$DOCKER_HOST" ]; then
export DOCKER_HOST=unix:///var/run/docker.sock
fi
env_vars="-e HOME=/$HOME"
for var in $(env | egrep -i "^(DOCKER_HOST|DOCKER_TLS_VERIFY|DOCKER_CERT_PATH|BUILDRUNNER_)")
do
if [[ "$OS" = Windows* ]]
then
# Replace =c: with =//c
var=$( echo "$var" | sed "s,=\([a-z]\):,=//\L\1,gi" )
fi
env_vars="$env_vars -e $var"
if [[ "$OS" = Windows* ]]
then
# Replace =c: with =//c
var=$( echo "$var" | sed "s,=\([a-z]\):,=//\L\1,gi" )
fi
env_vars="$env_vars -e $var"
done

if [ "$(uname)" == "Darwin" ]; then
Expand Down

0 comments on commit 2ad4e97

Please sign in to comment.