Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(actions) Improvements in building docker images #696

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ci/build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,37 @@ echo -e "\e[35;1mCI_DOCKER_PUSH_IMAGE = ${CI_DOCKER_PUSH_IMAGE}\e[0m"
echo -e "\e[35;1mCI_DOCKER_SSH = ${CI_DOCKER_SSH}\e[0m"


if [[ "${CI_DOCKER_SSH}" == "true" ]]
then
ADDITIONAL_ARGS_LOCAL_BUILD="${ADDITIONAL_ARGS_LOCAL_BUILD} --ssh --ssh-key=YOUR_KEY_FILE"
fi

if [[ -n "${CI_OAUTH2_TOKEN}" ]]
then
ADDITIONAL_ARGS_LOCAL_BUILD="${ADDITIONAL_ARGS_LOCAL_BUILD} --oauth2_token=YOUR_OAUTH2_KEY"
fi

# Command to reproduce locally
# shellcheck disable=SC2016
echo -e "\e[35;1m
This build can be reproduced locally using the following commands:

\`\`\`
tue-get install docker
cd "'${TUE_DIR}'"
git checkout ${CI_COMMIT}

docker buildx rm multiarch-builder
docker context rm multiarch-environment

"'${TUE_DIR}'"/ci/build-docker-image.sh --image=${CI_DOCKER_IMAGE_NAME} --branch=${CI_BRANCH} --pull_request=${CI_PULL_REQUEST} --commit=${CI_COMMIT} --registry=${CI_DOCKER_REGISTRY} --ref-name=${CI_REF_NAME} --platforms=${CI_DOCKER_PLATFORMS} --push_image=false --ros_version=${CI_ROS_VERSION} --ros_distro=${CI_ROS_DISTRO} --targets_repo=${CI_TARGETS_REPO} --base_image=${CI_DOCKER_BASE_IMAGE} --docker_file=${CI_DOCKER_FILE}${ADDITIONAL_ARGS_LOCAL_BUILD}
\`\`\`

This command never pushes the docker image to the registry. You will need to alter the '--push_image' argument for that. This also requires you are logged in to the correct docker registry or provide the related arguments(--docker_login, --user and --password), so this script will login.
To access a private repository you need to provide a SSH key ('--ssh --ssh-key=YOUR_SSH_KEY_FILE') or an OAUTH2 token ('--oauth2_token=YOUR_OAUTH2_TOKEN').

\e[0m"

# Declare arrays for storing the constructed docker build arguments
CI_DOCKER_BUILD_ARGS=()
CI_DOCKER_BUILDX_ARGS=()
Expand Down Expand Up @@ -227,6 +258,13 @@ then
fi

# Construction of Docker buildx arguments begins here
if [[ "${GITHUB_ACTIONS}" == "true" ]]
then
echo -e "\e[35;1mRunning on GitHub Actions, using the specific GHA cache\e[0m"
CI_DOCKER_BUILDX_ARGS+=("--cache-from=type=gha")
CI_DOCKER_BUILDX_ARGS+=("--cache-to=type=gha,mode=min,compression=zstd")
fi

if [[ -n "$CI_DOCKER_PLATFORMS" ]]
then
CI_DOCKER_BUILDX_ARGS+=("--platform=linux/${CI_DOCKER_PLATFORMS}")
Expand Down
2 changes: 1 addition & 1 deletion ci/install-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ then
echo -e "\e[35;1mSSH_KEY = ${SSH_KEY_FINGERPRINT}\e[0m"

DOCKER_SSH_AUTH_SOCK="/tmp/ssh_auth_sock"
DOCKER_MOUNT_KNOWN_HOSTS_ARGS=("-e" "SSH_AUTH_SOCK=${DOCKER_SSH_AUTH_SOCK}" "--mount" "type=bind,source=$SHARED_DIR/.ssh,target=/tmp/.ssh")
DOCKER_MOUNT_KNOWN_HOSTS_ARGS=("-e" "SSH_AUTH_SOCK=${DOCKER_SSH_AUTH_SOCK}" "--mount" "type=bind,source=${SHARED_DIR}/.ssh,target=/tmp/.ssh")

# Used in the print statement to reproduce CI build locally
ADDITIONAL_ARGS_LOCAL_INSTALL+=("--shared=/tmp/shared/${PACKAGE}" "--ssh")
Expand Down
11 changes: 8 additions & 3 deletions dockerfiles/tue-env.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ SHELL ["/bin/bash", "-c"]

# Install commands used in our scripts and standard present on a clean ubuntu
# installation and setup a user with sudo priviledges
RUN apt-get update -qq && \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update -qq && \
echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections && \
apt-get install -qq --assume-yes --no-install-recommends apt-transport-https apt-utils bash-completion ca-certificates curl dbus debconf-utils dialog git keyboard-configuration lsb-release iproute2 iputils-ping mesa-utils net-tools openssh-client psmisc resolvconf sudo tzdata wget > /dev/null && \
apt-get install -qq --assume-yes --no-install-recommends apt-transport-https apt-utils bash-completion ca-certificates curl dbus debconf-utils dialog git keyboard-configuration lsb-release iproute2 iputils-ping mesa-utils net-tools openssh-client psmisc resolvconf sudo tzdata wget > /dev/null

# Add defined user
adduser -u $USER_ID --disabled-password --gecos "" $USER && \
RUN adduser -u $USER_ID --disabled-password --gecos "" $USER && \
groupadd -g 109 render && \
usermod -aG sudo $USER && \
usermod -aG adm $USER && \
Expand All @@ -72,6 +75,8 @@ RUN { [[ -n "$OAUTH2_TOKEN" ]] && git config --global credential.helper '!f() {

# Setup tue-env and install target ros
RUN --mount=type=ssh,uid=$USER_ID --mount=type=bind,source=installer/bootstrap.bash,target=bootstrap.bash \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
# Remove interactive check from bashrc, otherwise bashrc refuses to execute
sed -e s/return//g -i ~/.bashrc && \
# Set the CI args in the container as docker currently provides no method to
Expand Down