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

Use a setup.sh script for configuring ee final container #392

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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
55 changes: 7 additions & 48 deletions final/Containerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
# Builds community-ansible-dev-tools-container-base image which provides
# container-in-container support and all installs all binary dependencies
# cspell:ignore minrate,opencontainers,cffi,ruamel,subuid,subgid,workdir,chgrp,mountopt,microdnf,makecache,setcaps,pylibssh,chsh,nodev,overlayfs,libssh,markupsafe,additionalimage,USERNS,onigurumacffi
# cspell:ignore minrate,opencontainers,cffi,ruamel,subuid,subgid,workdir,chgrp,mountopt,microdnf,makecache,setcaps,pylibssh,chsh,nodev,overlayfs,libssh,markupsafe,additionalimage,USERNS
FROM community-ansible-dev-tools-base:latest

USER root

# When building for multiple-architectures in parallel using emulation
# it's really easy for one/more dnf processes to timeout or mis-count
# the minimum download rates. Bump both to be extremely forgiving of
# an overworked host.
RUN echo -e "\n\n# Added during image build" >> /etc/dnf/dnf.conf && \
echo -e "minrate=100\ntimeout=60\n" >> /etc/dnf/dnf.conf

LABEL org.opencontainers.image.source=https://github.com/ansible/ansible-dev-tools
LABEL org.opencontainers.image.authors="Ansible DevTools"
LABEL org.opencontainers.image.vendor="Red Hat"
LABEL org.opencontainers.image.licenses="GPL-3.0"
LABEL org.opencontainers.image.description="An execution environment targeted for Ansible content creators."

WORKDIR /context
RUN --mount=type=bind,target=. --mount=type=cache,dst=/var/cache/dnf --mount=type=cache,dst=/root/.cache/pip context/setup.sh
USER root

RUN --mount=type=bind,target=. --mount=type=cache,dst=/var/cache/dnf --mount=type=cache,dst=/root/.cache/pip ./setup.sh


ARG _REPO_URL="https://raw.githubusercontent.com/containers/image_build/main/podman"
ADD $_REPO_URL/containers.conf /etc/containers/containers.conf
Expand Down Expand Up @@ -75,42 +67,9 @@ RUN for dir in \
# base ansible-dev-tools setup

COPY dist/*.whl /tmp/dist
RUN --mount=type=cache,dst=/root/.cache/pip sh -ec -o pipefail "ls -1 /tmp/dist/*.whl | xargs -I '{}' python3 -m pip install -q '{}[server,lock]' && rm -rf /tmp/dist"

RUN \
mkdir -p ~/.ansible/roles /usr/share/ansible/roles /etc/ansible/roles && \
git config --system --add safe.directory /

# The dev container for docker runs as root
RUN chsh -s $(which zsh) root

RUN <<EOF
# Install argcomplete
python3 -m pip install argcomplete
activate-global-python-argcomplete
EOF

# Install oh-my-zsh
USER root
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# 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 \
&& ansible --version \
&& ansible-lint --version \
&& ansible-runner --version \
&& molecule --version \
&& molecule drivers \
&& podman --version \
&& python3 --version \
&& git --version \
&& ansible-galaxy role list \
&& ansible-galaxy collection list \
&& rpm -qa \
&& uname -a
RUN sh -ec -o pipefail "ls -1 /tmp/dist/*.whl | xargs -I '{}' python3 -m pip install --no-cache-dir '{}[server,lock]' && rm -rf /tmp/dist"

# Make a workdir usable by the root user
RUN mkdir -p /workdir
RUN --mount=type=bind,target=. --mount=type=cache,dst=/var/cache/dnf --mount=type=cache,dst=/root/.cache/pip ./setup2.sh

WORKDIR /workdir
ENTRYPOINT ["/opt/builder/bin/entrypoint", "dumb-init"]
Expand Down
9 changes: 8 additions & 1 deletion final/setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/bin/bash -e
# cspell: ignore onigurumacffi,makecache,euxo,libssh,overlayfs,setcaps
# cspell: ignore onigurumacffi,makecache,euxo,libssh,overlayfs,setcaps,minrate
set -euxo pipefail

# When building for multiple-architectures in parallel using emulation
# it's really easy for one/more dnf processes to timeout or mis-count
# the minimum download rates. Bump both to be extremely forgiving of
# an overworked host.
echo -e "\n\n# Added during image build" >> /etc/dnf/dnf.conf
echo -e "minrate=100\ntimeout=60\n" >> /etc/dnf/dnf.conf

microdnf -q -y makecache && microdnf -q -y update
microdnf -q -y install shadow-utils
rpm --setcaps shadow-utils 2>/dev/null
Expand Down
36 changes: 36 additions & 0 deletions final/setup2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# cspell: ignore euxo chsh
set -euxo pipefail

# this must run as user root

mkdir -p ~/.ansible/roles /usr/share/ansible/roles /etc/ansible/roles
git config --system --add safe.directory /

# The dev container for docker runs as root
chsh -s "$(which zsh)" root

# Install argcomplete
python3 -m pip install argcomplete
activate-global-python-argcomplete

# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# add some helpful CLI commands to check we do not remove them inadvertently and output some helpful version information at build time.
set -ex
ansible --version
ansible-lint --version
ansible-runner --version
molecule --version
molecule drivers
podman --version
python3 --version
git --version
ansible-galaxy role list
ansible-galaxy collection list
rpm -qa
uname -a

# Make a workdir usable by the root user
mkdir -p /workdir
3 changes: 2 additions & 1 deletion tools/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ python -m build --outdir "$REPO_DIR/final/dist/" --wheel "$REPO_DIR"
ansible-builder create -f execution-environment.yml --output-filename Containerfile -v3
$BUILD_CMD -f context/Containerfile context/ --tag community-ansible-dev-tools-base:latest
$BUILD_CMD -f final/Containerfile final/ --tag community-ansible-dev-tools:test
pytest --only-container --image-name community-ansible-dev-tools:test

pytest -v --only-container --container-engine=docker --image-name community-ansible-dev-tools:test
# -k test_navigator_simple
# Test the build of example execution environment to avoid regressions
pushd docs/examples
ansible-builder build
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ description =
Build the container image
skip_install = true
deps =
-r .config/requirements-test.in
ansible-builder
build
setuptools # https://github.com/ansible/ansible-builder/issues/644
Expand Down
Loading