Skip to content

Commit

Permalink
Use packaged bats in Fedora, side-load for Ubuntu
Browse files Browse the repository at this point in the history
Fixes #139

Signed-off-by: Chris Evich <[email protected]>
  • Loading branch information
cevich committed Jun 22, 2022
1 parent 053926f commit 641d05a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ OSARCH ?= amd64
PACKER_VERSION ?= $(shell bash ./get_packer_version.sh)
override _PACKER_URL := https://releases.hashicorp.com/packer/$(strip $(call err_if_empty,PACKER_VERSION))/packer_$(strip $(PACKER_VERSION))_$(OSTYPE)_$(OSARCH).zip

# Bats must be side-loaded onto Ubuntu VMs and containers,
# define the wanted version here.
override UBUNTU_BATS_VERSION = v1.7.0

# Align each line properly to the header
override _HLPFMT = "%-20s %s\n"

Expand Down Expand Up @@ -157,6 +161,7 @@ define packer_build
-force \
-var TEMPDIR="$(_TEMPDIR)" \
-var GAC_FILEPATH="$(call err_if_empty,GAC_FILEPATH)" \
-var UBUNTU_BATS_VERSION=$(call err_if_empty,UBUNTU_BATS_VERSION) \
$(if $(PACKER_BUILDS),-only=$(PACKER_BUILDS)) \
$(if $(IMG_SFX),-var IMG_SFX=$(IMG_SFX)) \
$(if $(DEBUG_NESTED_VM),-var TTYDEV=$(shell tty),-var TTYDEV=/dev/null) \
Expand Down Expand Up @@ -226,6 +231,7 @@ $(_TEMPDIR)/%_podman.tar: podman/Containerfile podman/setup.sh $(wildcard base_i
--build-arg=BASE_NAME=$(subst prior-,,$*) \
--build-arg=BASE_TAG=$(call err_if_empty,BASE_TAG) \
--build-arg=PACKER_BUILD_NAME=$(subst _podman,,$*) \
--build-arg UBUNTU_BATS_VERSION=$(call err_if_empty,UBUNTU_BATS_VERSION) \
-v $(_TEMPDIR)/.cache/$*:/var/cache/dnf:Z \
-v $(_TEMPDIR)/.cache/$*:/var/cache/apt:Z \
-f podman/Containerfile .
Expand Down
1 change: 1 addition & 0 deletions cache_images/fedora_packaging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ INSTALL_PACKAGES=(\
autoconf
automake
bash-completion
bats
bridge-utils
btrfs-progs-devel
buildah
Expand Down
4 changes: 4 additions & 0 deletions cache_images/gce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ variables:
# Required for ssh private key access
TEMPDIR:

# Required for side-loading bats on Ubuntu
# See podman_tooling.sh
UBUNTU_BATS_VERSION:

# Don't leak sensitive values in error messages / output
sensitive-variables:
Expand Down Expand Up @@ -78,6 +81,7 @@ provisioners:
type: 'shell'
inline:
- 'set -e'
- 'export UBUNTU_BATS_VERSION={{ user `UBUNTU_BATS_VERSION` }}'
- '/bin/bash /tmp/automation_images/cache_images/ubuntu_setup.sh'

- only: ['build-push']
Expand Down
17 changes: 17 additions & 0 deletions cache_images/podman_tooling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ REPO_DIRPATH=$(realpath "$SCRIPT_DIRPATH/../")
# shellcheck source=./lib.sh
source "$REPO_DIRPATH/lib.sh"

if [[ "$OS_RELEASE_ID" == "ubuntu" ]]; then
if [[ -n "$(type -P bats)" ]]; then
die "Bats _MUST_ not be installed on ubuntu until fixed: https://bugs.launchpad.net/ubuntu/+source/bats/+bug/1882542"
fi
req_env_vars UBUNTU_BATS_VERSION
# shellcheck disable=SC2154
echo "Installing bats $UBUNTU_BATS_VERSION to /usr/local"
buildDir=$(mktemp -d)
lilto git clone -b "$UBUNTU_BATS_VERSION" \
https://github.com/bats-core/bats-core $buildDir

pushd $buildDir
$SUDO ./install.sh /usr/local
popd
rm -rf $buildDir
fi

echo "Configuring Go environment"
export GOPATH="${GOPATH:-/var/tmp/go}"
mkdir -p "$GOPATH"
Expand Down
6 changes: 2 additions & 4 deletions cache_images/ubuntu_packaging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ bigto ooe.sh $SUDO apt-get -qq -y upgrade

echo "Configuring additional package repositories"


# Useful version of criu is only available from launchpad repo
if [[ "$OS_RELEASE_VER" -le 2004 ]]; then
lilto ooe.sh $SUDO add-apt-repository --yes ppa:criu/ppa
Expand All @@ -44,9 +43,8 @@ curl --fail --silent --location --url "$GPG_URL" | \
$SUDO tee /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_unstable_ci.gpg &> /dev/null


# Removed golang-1.14 from install packages due to known
# performance reason. Reinstall when ubuntu has 1.16.

# N/B: DO NOT install the bats package on Ubuntu VMs, it's broken.
# ref: (still open) https://bugs.launchpad.net/ubuntu/+source/bats/+bug/1882542
INSTALL_PACKAGES=(\
apache2-utils
apparmor
Expand Down
8 changes: 6 additions & 2 deletions podman/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ ARG BASE_TAG=
FROM ${BASE_NAME}:${BASE_TAG}

ARG PACKER_BUILD_NAME=
ARG UBUNTU_BATS_VERSION=
ENV AI_PATH=/usr/src/automation_images \
CONTAINER=1
CONTAINER=1 \
UBUNTU_BATS_VERSION=${UBUNTU_BATS_VERSION}

# Only add needed files to avoid invalidating build cache
ADD /lib.sh "$AI_PATH/"
Expand All @@ -22,7 +24,9 @@ ADD /base_images/* "$AI_PATH/base_images/"
ADD /cache_images/* "$AI_PATH/cache_images/"
ADD /systemd_banish.sh "$AI_PATH/"
WORKDIR "$AI_PATH"
RUN bash ./podman/setup.sh
RUN cd $AI_PATH && \
chmod +x ./podman/setup.sh && \
$AI_PATH/podman/setup.sh

#### For runtime use...

Expand Down
2 changes: 1 addition & 1 deletion podman/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#!/bin/bash

# This script is intended to be executed as part of the container
# image build process. Using it under any other context is virtually
Expand Down

0 comments on commit 641d05a

Please sign in to comment.