Skip to content

Commit

Permalink
Enable testing of devspaces container
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Nov 5, 2024
1 parent 26c0f4d commit 4dc12b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
23 changes: 13 additions & 10 deletions tools/devspaces.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
#!/bin/bash -e
# cspell: ignore euxo buildx
# cspell: ignore euxo buildx execdir
set -euxo pipefail
ADT_CONTAINER_ENGINE=${ADT_CONTAINER_ENGINE:-docker}
CONTAINER_NAME=ansible/ansible-workspace-env-reference:test
IMAGE_NAME=ansible/ansible-workspace-env-reference:test

mkdir -p out
mkdir -p out dist
# Ensure that we packaged the code first
WHEELS=(dist/*.whl)
# shellcheck disable=SC2207
WHEELS=($(find dist -name '*.whl' -maxdepth 1 -execdir echo '{}' ';'))
if [ ${#WHEELS[@]} -ne 1 ]; then
tox -e pkg
WHEELS=(dist/*.whl)
# shellcheck disable=SC2207
WHEELS=($(find dist -name '*.whl' -maxdepth 1 -execdir echo '{}' ';'))
if [ ${#WHEELS[@]} -ne 1 ]; then
echo "Unable to find a single wheel file in dist/ directory."
echo "Unable to find a single wheel file in dist/ directory: ${WHEELS[*]}"
exit 2
fi
fi
tox -e pkg
rm -f devspaces/context/*.whl
cp dist/*.whl devspaces/context
cp tools/setup-image.sh devspaces/context

# 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.
# --metadata-file=out/devspaces.meta --no-cache
$ADT_CONTAINER_ENGINE buildx build --tag=$CONTAINER_NAME --platform=linux/amd64 devspaces/context -f devspaces/Containerfile
$ADT_CONTAINER_ENGINE buildx build --tag=$IMAGE_NAME --platform=linux/amd64 devspaces/context -f devspaces/Containerfile

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

pytest --only-container --container-engine="${ADT_CONTAINER_ENGINE}" --container-name=devspaces --image-name=$IMAGE_NAME "$@" || echo "::error::Ignored failed devspaces tests, please https://github.com/ansible/ansible-dev-tools/issues/467"

if [[ -n "${GITHUB_SHA:-}" ]]; then
$ADT_CONTAINER_ENGINE tag $CONTAINER_NAME "ghcr.io/ansible/ansible-devspaces-tmp:${GITHUB_SHA}"
$ADT_CONTAINER_ENGINE tag $IMAGE_NAME "ghcr.io/ansible/ansible-devspaces-tmp:${GITHUB_SHA}"
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
Expand Down
14 changes: 7 additions & 7 deletions tools/ee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi
REPO_DIR=$(git rev-parse --show-toplevel)

TAG_BASE=community-ansible-dev-tools-base:latest
CONTAINER_NAME=community-ansible-dev-tools:test
IMAGE_NAME=community-ansible-dev-tools:test

# BUILD_CMD="podman build --squash-all"
BUILD_CMD="${ADT_CONTAINER_ENGINE} buildx build --progress=plain"
Expand Down Expand Up @@ -62,24 +62,24 @@ 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 "${TAG_BASE}"
cp tools/setup-image.sh final/
$BUILD_CMD -f final/Containerfile final/ --tag "${CONTAINER_NAME}"
$BUILD_CMD -f final/Containerfile final/ --tag "${IMAGE_NAME}"

# Check container size and layers
mk containers check $CONTAINER_NAME --engine="${ADT_CONTAINER_ENGINE}" --max-size=1500 --max-layers=22
mk containers check "$IMAGE_NAME" --engine="${ADT_CONTAINER_ENGINE}" --max-size=1500 --max-layers=22

pytest -v --only-container --container-engine=docker --image-name "${CONTAINER_NAME}"
pytest -v --only-container --container-engine="${ADT_CONTAINER_ENGINE}" --image-name "${IMAGE_NAME}"
# -k test_navigator_simple
# Test the build of example execution environment to avoid regressions
pushd docs/examples
ansible-builder build
popd

if [[ -n "${GITHUB_SHA:-}" ]]; then
FQ_CONTAINER_NAME="ghcr.io/ansible/community-ansible-dev-tools-tmp:${GITHUB_SHA}-$ARCH"
$ADT_CONTAINER_ENGINE tag $CONTAINER_NAME "${FQ_CONTAINER_NAME}"
FQ_IMAGE_NAME="ghcr.io/ansible/community-ansible-dev-tools-tmp:${GITHUB_SHA}-$ARCH"
$ADT_CONTAINER_ENGINE tag $IMAGE_NAME "${FQ_IMAGE_NAME}"
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
fi
$ADT_CONTAINER_ENGINE push "${FQ_CONTAINER_NAME}"
$ADT_CONTAINER_ENGINE push "${FQ_IMAGE_NAME}"
fi

0 comments on commit 4dc12b3

Please sign in to comment.