Skip to content

Commit

Permalink
Convert buildpack-deps to use a bake file
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorific committed Nov 19, 2023
1 parent 9646e8b commit b9b1175
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
base: ${{ github.ref }}
filters: |
aws-cli: 'aws-cli/**'
buildpack-deps/ubuntu/jammy: 'buildpack-deps/ubuntu/jammy/**'
fpm: 'fpm/**'
meshcmd: 'meshcmd/**'
python/3.8/slim-jammy: 'python/3.8/slim-jammy/**'
Expand Down
13 changes: 12 additions & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

set -x
set -eu
set -o pipefail

Expand All @@ -8,7 +9,17 @@ CINC_AUDITOR_CONTAINER_IMAGE=docker.io/boxcutter/cinc-auditor:6.6.0
BIN_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
CONTAINERFILE_DIR=$(pwd)
CINC_PROFILE_DIR="${CONTAINERFILE_DIR}/test"
DEFAULT_TAG="$(docker buildx bake local --print 2>/dev/null | jq -r '.target.local.tags | first')"
# DEFAULT_TAG="$(docker buildx bake local --print 2>/dev/null | jq -r '.target.local.tags | first')"

json_data="$(docker buildx bake local --print 2>/dev/null)"
# Check if .group.local.targets.default exists, and if it does, extract its value
exit_code=0
result=$(echo "$json_data" | jq -e '.group.local.targets') || exit_code=$?
if [ $exit_code -eq 0 ]; then
DEFAULT_TAG=$(echo "$json_data" | jq -r '.target.default.tags | first')
else
DEFAULT_TAG=$(echo "$json_data" | jq -r '.target.local.tags | first')
fi

usage() {
cat <<EOF
Expand Down
37 changes: 36 additions & 1 deletion buildpack-deps/ubuntu/jammy/Containerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
# syntax=docker/dockerfile:1
ARG CONTAINER_REGISTRY=docker.io
FROM $CONTAINER_REGISTRY/boxcutter/buildpack-deps:jammy-scm
FROM $CONTAINER_REGISTRY/ubuntu:jammy-20231004 as curl

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
netbase \
wget \
# https://bugs.debian.org/929417
tzdata \
; \
rm -rf /var/lib/apt/lists/*

RUN set -ex; \
if ! command -v gpg > /dev/null; then \
apt-get update; \
apt-get install -y --no-install-recommends \
gnupg \
dirmngr \
; \
rm -rf /var/lib/apt/lists/*; \
fi

FROM curl as scm

# procps is very common in build systems, and is a reasonably small package
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
mercurial \
openssh-client \
subversion \
\
procps \
&& rm -rf /var/lib/apt/lists/*

FROM scm

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# hadolint ignore=SC2046
Expand Down
4 changes: 0 additions & 4 deletions buildpack-deps/ubuntu/jammy/Polly.toml

This file was deleted.

3 changes: 0 additions & 3 deletions buildpack-deps/ubuntu/jammy/curl/.dockerignore

This file was deleted.

25 changes: 0 additions & 25 deletions buildpack-deps/ubuntu/jammy/curl/Containerfile

This file was deleted.

4 changes: 0 additions & 4 deletions buildpack-deps/ubuntu/jammy/curl/Polly.toml

This file was deleted.

3 changes: 0 additions & 3 deletions buildpack-deps/ubuntu/jammy/curl/test/controls/focal.rb

This file was deleted.

54 changes: 54 additions & 0 deletions buildpack-deps/ubuntu/jammy/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
variable "IMAGE_NAME" {
default = "buildpack-deps"
}

variable "CONTAINER_REGISTRY" {
default = "docker.io/boxcutter"
}

# There's no darwin-based Docker, so if we're running on macOS, change the platform to linux
variable "LOCAL_PLATFORM" {
default = regex_replace("${BAKE_LOCAL_PLATFORM}", "^(darwin)", "linux")
}

target "_common" {
dockerfile = "Containerfile"
labels = {
"org.opencontainers.image.source" = "https://github.com/polymathrobotics/oci"
"org.opencontainers.image.licenses" = "Apache-2.0"
"org.opencontainers.image.description" = "A collection of common build dependencies used for installing various modules."
"org.opencontainers.image.title" = "${IMAGE_NAME}"
}
}

target "curl" {
inherits = ["_common"]
target = "curl"
tags = [
"${CONTAINER_REGISTRY}/${IMAGE_NAME}:jammy-curl",
"${CONTAINER_REGISTRY}/${IMAGE_NAME}:22.04-curl"
]
}

target "scm" {
inherits = ["_common"]
target = "scm"
tags = [
"${CONTAINER_REGISTRY}/${IMAGE_NAME}:jammy-scm",
"${CONTAINER_REGISTRY}/${IMAGE_NAME}:22.04-scm"
]
}

group "local" {
targets = ["curl", "scm", "default"]
platforms = ["${LOCAL_PLATFORM}"]
}

target "default" {
inherits = ["_common"]
tags = [
"${CONTAINER_REGISTRY}/${IMAGE_NAME}:jammy",
"${CONTAINER_REGISTRY}/${IMAGE_NAME}:22.04"
]
platforms = ["linux/amd64", "linux/arm64/v8", "linux/arm/v7"]
}
3 changes: 0 additions & 3 deletions buildpack-deps/ubuntu/jammy/scm/.dockerignore

This file was deleted.

13 changes: 0 additions & 13 deletions buildpack-deps/ubuntu/jammy/scm/Containerfile

This file was deleted.

4 changes: 0 additions & 4 deletions buildpack-deps/ubuntu/jammy/scm/Polly.toml

This file was deleted.

3 changes: 0 additions & 3 deletions buildpack-deps/ubuntu/jammy/scm/test/controls/focal.rb

This file was deleted.

8 changes: 8 additions & 0 deletions buildpack-deps/ubuntu/jammy/test/controls/focal.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
describe command('curl') do
it { should exist }
end

describe command('git') do
it { should exist }
end

describe command('unzip') do
it { should exist }
end

0 comments on commit b9b1175

Please sign in to comment.