Skip to content

Commit

Permalink
Refactor devspaces image build to produce smaller image
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 1, 2024
1 parent b73f692 commit 053cb9e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 22 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ containerfile
devcontainer
devel
devfile
devspaces
endgroup
gunicorn
libera
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ concurrency:
jobs:
tox:
uses: ansible/team-devtools/.github/workflows/tox.yml@main
with:
other_names_also: |
devspaces
build-image:
runs-on: ${{ matrix.builder }}
name: ${{ matrix.name }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ _readthedocs
# ansible-builder
/context
/collections
out
4 changes: 2 additions & 2 deletions devspaces/Containerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM quay.io/devfile/universal-developer-image:ubi8-latest
FROM quay.io/devfile/base-developer-image:ubi8-latest

ARG PYV=3.11

LABEL org.opencontainers.image.source=https://github.com/ansible/ansible-workspace-env-reference-image
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"
Expand Down
30 changes: 15 additions & 15 deletions devspaces/context/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ set -e
dnf -y makecache
dnf -y update
dnf install -y \
tar \
podman \
fuse-overlayfs \
openssh-clients \
zsh \
util-linux-user \
which \
git \
dumb-init \
fuse-overlayfs \
gcc \
git \
git-core \
libssh-devel \
python3-markupsafe \
ncurses \
python3-bcrypt \
python3-cffi \
python3-pip \
python3-pyyaml \
python3-ruamel-yaml \
python3-wheel \
openssh-clients \
podman \
python${PYV} \
python${PYV}-cffi \
python${PYV}-markupsafe \
python${PYV}-pip \
python${PYV}-pyyaml \
python${PYV}-wheel \
tar \
util-linux-user \
which \
zsh \
--exclude container-selinux
# python${PYV}-ruamel-yaml \
dnf clean all

/usr/bin/python${PYV} -m pip install --no-cache-dir -r requirements.txt
Expand Down
17 changes: 17 additions & 0 deletions tools/devspaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e
# cspell: ignore euxo buildx
set -euxo pipefail
ADT_CONTAINER_ENGINE=${ADT_CONTAINER_ENGINE:-docker}
CONTAINER_NAME=ansible/ansible-workspace-env-reference:test

mkdir -p out
# we force use of linux/amd64 platform because source image supports only this
# platform and without it, it will fail to cross-build when task runs on arm64.
$ADT_CONTAINER_ENGINE buildx build --metadata-file=out/devspaces.meta --no-cache --tag=$CONTAINER_NAME --platform=linux/amd64 devspaces/context -f devspaces/Containerfile

mk containers check $CONTAINER_NAME --engine="${ADT_CONTAINER_ENGINE}" --max-size=600 --max-layers=23

if [[ -n "${GITHUB_SHA:-}" ]]; then
$ADT_CONTAINER_ENGINE tag $CONTAINER_NAME "ansible/ansible-devspaces-tmp:${GITHUB_SHA}"
$ADT_CONTAINER_ENGINE push "ansible/ansible-devspaces-tmp:${GITHUB_SHA}"
fi
27 changes: 22 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env_list =
milestone
pkg
image
devspaces
skip_missing_interpreters = true

[testenv]
Expand All @@ -18,6 +19,7 @@ package = editable
extras =
test
pass_env =
ADT_CONTAINER_ENGINE
CI
CONTAINER_*
DOCKER_*
Expand All @@ -30,9 +32,11 @@ pass_env =
XDG_RUNTIME_DIR
set_env =
!milestone: PIP_CONSTRAINT = {toxinidir}/.config/constraints.txt
BUILDKIT_PROGRESS = plain
COVERAGE_COMBINED = {envdir}/.coverage
COVERAGE_FILE = {env:COVERAGE_FILE:{envdir}/.coverage.{envname}}
COVERAGE_PROCESS_START = {toxinidir}/pyproject.toml
DOCKER_CLI_HINTS = false
FORCE_COLOR = 1
PRE_COMMIT_COLOR = always
TERM = xterm-256color
Expand All @@ -46,9 +50,13 @@ commands =
coverage lcov --data-file={env:COVERAGE_COMBINED} -o {toxinidir}/.cache/.coverage/lcov.info --fail-under=0
coverage report --data-file={env:COVERAGE_COMBINED}
allowlist_externals =
./tools/devspaces.sh
docker
git
podman
rm
sh
{env:ADT_CONTAINER_ENGINE:docker}

[testenv:deps]
description = Bump all dependencies
Expand Down Expand Up @@ -118,17 +126,26 @@ skip_install = true
deps =
ansible-builder
build
mk
pytest
setuptools # https://github.com/ansible/ansible-builder/issues/644
commands_pre =
commands =
python -m build --outdir {toxinidir}/final/dist/ --wheel {toxinidir}
ansible-builder create -f execution-environment.yml --output-filename Containerfile -v3
podman build --squash-all context/ --tag community-ansible-dev-tools-base:latest
podman build --squash-all final/ --tag community-ansible-dev-tools:test
{env:ADT_CONTAINER_ENGINE:podman} build --squash-all context/ --tag community-ansible-dev-tools-base:latest
{env:ADT_CONTAINER_ENGINE:podman} build --squash-all final/ --tag community-ansible-dev-tools:test
mk containers check community-ansible-dev-tools:test --engine={env:ADT_CONTAINER_ENGINE:podman} --max-size=600 --max-layers=1
pytest --only-container --image-name community-ansible-dev-tools:test
allowlist_externals =
podman
pytest

[testenv:devspaces]
description = Build devspaces image for current architecture
skip_install = true
deps =
mk
commands_pre =
commands =
./tools/devspaces.sh

[testenv:test-image]
description =
Expand Down

0 comments on commit 053cb9e

Please sign in to comment.