Commit ab192231 authored by Brian Long's avatar Brian Long
Browse files

initial commit

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+2 −0
Original line number Diff line number Diff line
# IDEA
.idea

README.md

0 → 100644
+106 −0
Original line number Diff line number Diff line
# Base Runner Image

This is a base container image for CI/CD processes.

## Description

Based on the Debian Slim series of images, this image provides common tools for continuous integration/delivery.  It is only for build, not runtime purposes.  These are used by GitHub, GitLab, and Gitea runners to perform builds, releases, and related tasks.

## Features

### Inherited

This image provides everything [Debian Slim](https://github.com/linuxcontainers/debian-slim) provides.

### Tools

This following tools are installed and available with this image.

`tar`
: TAR extraction or creation

`gzip`
: GZIP or `tar.gz` extraction or creation

`zip`/`unzip`
: ZIP extraction or creation

`curl`
: HTTP service calls, including downloads

`jq`
: JSON parsing and modification

`xmlstarlet`
: XML parsing and modification

`git`
: Git source control

### Extensible `ENTRYPOINT`

This base image implements a universal `ENTRYPOINT` script that executes all executable scripts in `/opt/containerd` that end with `.sh`.  This provides the ability for all extending container images to include their own entrypoint script without overriding or shadowing any ancestral entrypoint.

This is nothing to the `CMD` directive, but if specified by an extending image, it will be respected.

## Tags

A version labeled `latest` always exists.

| Tag      | Description |
| -------- | ----------- |
| `latest` | The latest version |
| `X`      | The latest version within the specified major version `X`. |
| `X.Y`    | The latest version within the specified minor version `X.Y`. |
| `X.Y.Z`  | A specific version. |

## Configuration

### Environment Variables

| Name                     | Required | Default         | Purpose |
| ------------------------ |:--------:| --------------- | ------- |
| `GIT_CONFIG_USER_NAME`   | No       |                 | Initialize Git to use this `user.name`. |
| `GIT_CONFIG_USER_EMAIL`  | No       |                 | Initialize Git to use this `user.email`. |
| `CURL_CONFIG_DIR`        | No       | `/opt/etc/curl` | Expected location of Curl configuration files. |
| `CURL_CONFIG_IDS`        | No       |                 | Create Curl configuration file(s) using values provided in corresponding environment variables. |
| `CURL_CONFIG_*_USERNAME` | No       |                 | An HTTP BASIC username for a corresponding Curl configuration. |
| `CURL_CONFIG_*_PASSWORD` | No       |                 | An HTTP BASIC password for a corresponding Curl configuration. |

`CURL_CONFIG_IDS`
: The expected format: `<id>:<key> [<id>:<key> [<id>:<key> ...]]`.  The key is used in place of the `*` in the environment variables above.  The ID is used in the configuration filename.

#### Examples

Here are sample environment variable definitions:

```sh
GIT_CONFIG_USER_NAME=John Doe
GIT_CONFIG_USER_EMAIL=john.doe@inteligr8.com
CURL_CONFIG_IDS="biz1:BIZ1 biz2:BIZ2"
CURL_CONFIG_BIZ1_USERNAME=john.doe
CURL_CONFIG_BIZ1_PASSWORD=
CURL_CONFIG_BIZ2_USERNAME=jane.doe
CURL_CONFIG_BIZ2_PASSWORD=
```

Here is the corresponding usage of `curl` with the configuration:

```sh
curl --config ${CURL_CONFIG_DIR}/biz1.cfg ...
curl --config ${CURL_CONFIG_DIR}/biz2.cfg ...
```

## Usage

This is expected to be extended or used directly for simple CI/CD runners.

## Contributing

You are welcome to copy the repository, but please open an issue first to avoid fragmentation.

- [Open Issue](https://git.inteligr8.com/inteligr8/base-runner-image/issues)

## References

- [Debian Slim](https://github.com/linuxcontainers/debian-slim)
 No newline at end of file

cicd/build.sh

0 → 100755
+35 −0
Original line number Diff line number Diff line
#!/bin/bash
set -e

[[ -v ${CONTAINERD_REGISTRY_HOST} ]] || CONTAINERD_REGISTRY_HOST=docker.inteligr8.com
[[ -v ${CONTAINERD_IMAGE_NAMESPACE} ]] || CONTAINERD_IMAGE_NAMESPACE=inteligr8/
[[ -v ${CONTAINERD_IMAGE_NAME} ]] || CONTAINERD_IMAGE_NAME=base-runner
[[ -v ${CONTAINERD_CMD} ]] || CONTAINERD_CMD=buildah
[[ -v ${CONTAINERD_BUILD_FORMAT} ]] || CONTAINERD_BUILD_FORMAT=docker
[[ -v ${DEBIAN_VERSION} ]] || DEBIAN_VERSION=13

if [[ -v ${CONTAINERD_DEBUG} ]]; then
  SKOPEO_OPTS="${SKOPEO_OPTS} --debug"
  CONTAINERD_CMD_OPTS="${CONTAINERD_CMD_OPTS} --log-level=debug"
fi

GIT_COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)
CONTAINERD_IMAGE_REMOTE_NAME=${CONTAINERD_REGISTRY_HOST}/${CONTAINERD_IMAGE_NAMESPACE}${CONTAINERD_IMAGE_NAME}

set +e
skopeo ${SKOPEO_OPTS} inspect docker://${CONTAINERD_IMAGE_REMOTE_NAME}:sha${GIT_COMMIT_SHORT_SHA}
SKOPEO_INSPECT_RC=$?
set -e

if [[ "${INSPECT_RC}" == "0" ]]; then
  echo "Container image already built; skipping rebuild"
else
  echo "Building container image"
  ${CONTAINERD_CMD} ${CONTAINERD_CMD_OPTS} build \
    --format=${CONTAINERD_BUILD_FORMAT} \
    ${CONTAINERD_BUILD_OPTS} \
    --build-arg DEBIAN_VERSION=${DEBIAN_VERSION} \
    --build-arg CONTAINERD_REGISTRY_HOST=${CONTAINERD_REGISTRY_HOST} \
    --build-arg CONTAINERD_IMAGE_NAMESPACE=${CONTAINERD_IMAGE_NAMESPACE} \
    --tag ${CONTAINERD_IMAGE_REMOTE_NAME}:sha${GIT_COMMIT_SHORT_SHA}
fi

cicd/push-auth.sh

0 → 100755
+17 −0
Original line number Diff line number Diff line
#!/bin/bash
set -e

[[ -v ${CONTAINERD_REGISTRY_HOST} ]] || CONTAINERD_REGISTRY_HOST=docker.inteligr8.com
[[ -v ${CONTAINERD_CMD} ]] || CONTAINERD_CMD=buildah

if [[ -v ${CONTAINERD_DEBUG} ]]; then
  CONTAINERD_CMD_OPTS="${CONTAINERD_CMD_OPTS} --log-level=debug"
fi

if [[ -v ${CONTAINERD_REGISTRY_USERNAME} && -v ${CONTAINERD_REGISTRY_PASSWORD} ]]; then
  echo "Authenticating with container registry"
  echo "${CONTAINERD_REGISTRY_PASSWORD}" | ${CONTAINERD_CMD} ${CONTAINERD_CMD_OPTS} login \
    ${CONTAINERD_REGISTRY_HOST} \
    -u ${CONTAINERD_REGISTRY_USERNAME} \
    --password-stdin
fi

cicd/push-sha.sh

0 → 100755
+19 −0
Original line number Diff line number Diff line
#!/bin/bash
set -e

[[ -v ${CONTAINERD_REGISTRY_HOST} ]] || CONTAINERD_REGISTRY_HOST=docker.inteligr8.com
[[ -v ${CONTAINERD_IMAGE_NAMESPACE} ]] || CONTAINERD_IMAGE_NAMESPACE=inteligr8/
[[ -v ${CONTAINERD_IMAGE_NAME} ]] || CONTAINERD_IMAGE_NAME=base-runner
[[ -v ${CONTAINERD_CMD} ]] || CONTAINERD_CMD=buildah

if [[ -v ${CONTAINERD_DEBUG} ]]; then
  CONTAINERD_CMD_OPTS="${CONTAINERD_CMD_OPTS} --log-level=debug"
fi

GIT_COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)
CONTAINERD_IMAGE_REMOTE_NAME=${CONTAINERD_REGISTRY_HOST}/${CONTAINERD_IMAGE_NAMESPACE}${CONTAINERD_IMAGE_NAME}

echo "Pushing container image to registry with commit SHA: ${GIT_COMMIT_SHORT_SHA}"
${CONTAINERD_CMD} ${CONTAINERD_CMD_OPTS} push \
  ${CONTAINERD_PUSH_OPTS} \
  ${CONTAINERD_IMAGE_REMOTE_NAME}:sha${GIT_COMMIT_SHORT_SHA}
Loading