From c2db0b06b09fce5cba7644a87cf323795c3c8f89 Mon Sep 17 00:00:00 2001 From: Justin Burr <20321959+juburr@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:35:46 -0400 Subject: [PATCH] feat: add apko/build command to the orb (#14) Co-authored-by: Justin Burr --- .circleci/test-deploy.yml | 9 ++++++++- src/commands/build.yml | 25 +++++++++++++++++++++++ src/examples/example.yml | 7 ++++++- src/scripts/build.sh | 40 +++++++++++++++++++++++++++++++++++++ src/tests/gdal-runtime.yaml | 22 ++++++++++++++++++++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100755 src/commands/build.yml create mode 100755 src/scripts/build.sh create mode 100644 src/tests/gdal-runtime.yaml diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index ec22f88..f461086 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -27,11 +27,18 @@ jobs: - image: cimg/base:current-22.04 steps: - checkout - # Run your orb's commands to validate them. - apko-orb/install - run: name: Verify Install command: command -v apko + - run: + name: Log Apko Version + command: apko version + - apko-orb/build: + config_path: src/tests/gdal-runtime.yaml + image_uri: ghcr.io/juburr/apko-orb/gdal-runtime-test:latest + log_level: debug + output_path: new-directory/gdal-runtime.tar workflows: test-deploy: jobs: diff --git a/src/commands/build.yml b/src/commands/build.yml new file mode 100755 index 0000000..d45fdff --- /dev/null +++ b/src/commands/build.yml @@ -0,0 +1,25 @@ +description: Builds a container using apko. +parameters: + config_path: + type: string + description: Path to a the YAML configuration file. + image_uri: + type: string + description: Image and tag of the output container image. + log_level: + type: enum + enum: ["debug", "info", "warn", "error", "fatal", "panic"] + default: "debug" + description: Logging level to use. + output_path: + type: string + description: Output filename for the final TAR file. +steps: + - run: + name: Build Apko Image + environment: + PARAM_CONFIG_PATH: << parameters.config_path >> + PARAM_IMAGE_URI: << parameters.image_uri >> + PARAM_LOG_LEVEL: << parameters.log_level >> + PARAM_OUTPUT_PATH: << parameters.output_path >> + command: << include(scripts/build.sh) >> diff --git a/src/examples/example.yml b/src/examples/example.yml index 4b82df5..05c5464 100755 --- a/src/examples/example.yml +++ b/src/examples/example.yml @@ -4,13 +4,18 @@ description: > usage: version: 2.1 orbs: - apko: juburr/apko-orb@0.2.6 + apko: juburr/apko-orb@0.3.0 jobs: build-images: docker: - image: cimg/base:current-22.04 steps: + - checkout - apko/install + - apko/build: + config_path: src/containers/runtimes/gdal.yaml + image_uri: ghcr.io/juburr/apko-orb/gdal-runtime:latest + output_path: gdal-runtime.tar workflows: use-my-orb: jobs: diff --git a/src/scripts/build.sh b/src/scripts/build.sh new file mode 100755 index 0000000..4796d68 --- /dev/null +++ b/src/scripts/build.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e + +# Ensure CircleCI environment variables can be passed in as orb parameters +CONFIG_PATH=$(circleci env subst "${PARAM_CONFIG_PATH}") +IMAGE_URI=$(circleci env subst "${PARAM_IMAGE_URI}") +LOG_LEVEL=$(circleci env subst "${PARAM_LOG_LEVEL}") +OUTPUT_PATH=$(circleci env subst "${PARAM_OUTPUT_PATH}") + +# Computed parameters +OUTPUT_DIR=$(dirname "${OUTPUT_PATH}") + +# Print command parameters for debugging purposes. +echo "Running Apko build with the following parameters:" +echo " CONFIG_PATH: ${CONFIG_PATH}" +echo " IMAGE_URI: ${IMAGE_URI}" +echo " LOG_LEVEL: ${LOG_LEVEL}" +echo " OUTPUT_DIR: ${OUTPUT_DIR}" +echo " OUTPUT_PATH: ${OUTPUT_PATH}" +echo "" + +# Validate configuration YAML file path +if [[ ! -f "${CONFIG_PATH}" ]]; then + echo "Configuration YAML does not exist at: ${CONFIG_PATH}" + exit 1 +fi + +# Create output directory if it does not yet exist +if [[ -d "${OUTPUT_DIR}" ]]; then + echo "Output directory already exists: ${OUTPUT_DIR}" +else + echo "Creating directory ${OUTPUT_DIR}..." + mkdir -p "${OUTPUT_DIR}" + echo " Done." +fi + +# Build image +echo "Building container image with apko..." +apko build --log-level "${LOG_LEVEL}" "${CONFIG_PATH}" "${IMAGE_URI}" "${OUTPUT_PATH}" diff --git a/src/tests/gdal-runtime.yaml b/src/tests/gdal-runtime.yaml new file mode 100644 index 0000000..38b1bf1 --- /dev/null +++ b/src/tests/gdal-runtime.yaml @@ -0,0 +1,22 @@ +contents: + keyring: + - https://packages.wolfi.dev/os/wolfi-signing.rsa.pub + repositories: + - https://packages.wolfi.dev/os + packages: + - ca-certificates-bundle + - gdal-tools + - glibc + - openssl + - tzdata + +accounts: + groups: + - groupname: nonroot + gid: 65532 + users: + - username: nonroot + uid: 65532 + +archs: + - amd64