Skip to content

Commit

Permalink
feat: add apko/build command to the orb (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Burr <juburr@users.noreply.github.com>
  • Loading branch information
juburr and juburr authored Sep 22, 2024
1 parent db47633 commit c2db0b0
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions src/commands/build.yml
Original file line number Diff line number Diff line change
@@ -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) >>
7 changes: 6 additions & 1 deletion src/examples/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions src/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -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}"
22 changes: 22 additions & 0 deletions src/tests/gdal-runtime.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c2db0b0

Please sign in to comment.