Commit 537d69a2 authored by Brian Long's avatar Brian Long
Browse files

initial checkin

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+8 −0
Original line number Diff line number Diff line
# Maven
target
pom.xml.versionsBackup

# Eclipse
.project
.settings

Containerfile

0 → 100644
+21 −0
Original line number Diff line number Diff line

FROM ${os.image.prefix}${os.image.name}:${os.image.version}${os.image.suffix}

ENV SKIP_ENTRYPOINT_SCRIPTS=false
ENV VERBOSE=true

# these are effectively immutable; provided to be used by extending images
# the entrypoint will re-set these in case they are changed
ENV CONTAINERD_ENTRYPOINT_PATH="${image.containerd.directory}"
ENV CACERT_INSTALL_PATH="/usr/local/share/ca-certificates"

# Install curl & essentials
RUN apt update && \
        apt -y install curl

# Add our Docker container initialization scripts
ADD --chmod=755 maven/entrypoint.sh ${image.containerd.directory}/entrypoint.sh
# RUN chmod 755 ${image.containerd.directory}/entrypoint.sh

# Execute the Docker container initialization script
ENTRYPOINT [ "${image.containerd.directory}/entrypoint.sh" ]

README.md

0 → 100644
+31 −0
Original line number Diff line number Diff line

# Base Image

This project creates a container image that provides purpose agnostic functionality to all extending images.

## Features

### Tools

The following tools are available.

- `curl`

### Extensible `ENTRYPOINT`

This image provides an entrypoint script that executes other entrypoint scripts, before executing the `CMD` (if provided).  It will execute any executable `.sh` scripts added to the path described by the `CONTAINERD_ENTRYPOINT_PATH` environment variable.  It will execute them in default sort order, so the use of numerical prefixes (`00_first.sh` or `99_last.sh`) may be wise.

### Extensible Certificate Authority

This image detects files in the path described by the `CACERT_INSTALL_PATH` environment variable.  If a file is found, it will treat it as a certificate and add it to the trusted certificates in all supported contexts.

## Configuration

### Environment Variables

| Name                         | Default         | Mutable |
| ---------------------------- | --------------- |:-------:|
| `SKIP_ENTRYPOINT_SCRIPTS`    | `false`         | Yes     |
| `VERBOSE`                    | `true`          | Yes     |
| `CONTAINERD_ENTRYPOINT_PATH` | *not important* | No      |
| `CACERT_INSTALL_PATH`        | *not important* | No      |

pom.xml

0 → 100644
+165 −0
Original line number Diff line number Diff line
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>com.inteligr8.container</groupId>
	<artifactId>base</artifactId>
	<version>${base.version}-${os.image.name}-${os.image.version}</version>
	<name>Base Image</name>
	<description>This is a purpose-agnostic base image</description>
	<packaging>pom</packaging>

	<properties>
		<base.version>1.0</base.version>

		<!-- The release version of Debian Linux to use as the base -->
		<!-- See: https://hub.docker.com/_/debian -->
		<os.image.prefix></os.image.prefix>
		<os.image.name>debian</os.image.name>
		<os.image.version>12.14</os.image.version>
		<os.image.suffix>-slim</os.image.suffix>

		<!-- The Docker image meta-data for pushing the build -->
		<image.name>inteligr8/${project.artifactId}</image.name>
		<image.tag>${project.version}</image.tag>
		<image.registry>docker.inteligr8.com</image.registry>

		<!-- using version properties so they can be overridden by child projects or Maven executions -->
		<kubernetes-maven-plugin.version>1.19.0</kubernetes-maven-plugin.version>
		<regex-maven-plugin.version>1.0.7</regex-maven-plugin.version>

		<!-- these properties are only used in the container -->
		<image.containerd.directory>/opt/inteligr8/containerd</image.containerd.directory>
	</properties>

	<build>
		<resources>
			<resource>
				<directory>src/main/containerd</directory>
				<filtering>true</filtering>
				<targetPath>${project.build.directory}/resources</targetPath>
			</resource>
		</resources>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.eclipse.jkube</groupId>
					<artifactId>kubernetes-maven-plugin</artifactId>
					<version>${kubernetes-maven-plugin.version}</version>
				</plugin>
				<plugin>
					<groupId>com.inteligr8</groupId>
					<artifactId>regex-maven-plugin</artifactId>
					<version>${regex-maven-plugin.version}</version>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>com.inteligr8</groupId>
				<artifactId>regex-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>determine-os-image-short-name</id>
						<phase>validate</phase>
						<goals>
							<goal>replace-property</goal>
						</goals>
						<configuration>
							<property>os.image.name</property>
							<newProperty>os.image.shortName</newProperty>
							<regexes>
								<regex>
									<pattern>(.{3}).+</pattern>
									<replacement>$1</replacement>
								</regex>
							</regexes>
						</configuration>
					</execution>
					<execution>
						<id>determine-os-image-major-version</id>
						<phase>validate</phase>
						<goals>
							<goal>replace-property</goal>
						</goals>
						<configuration>
							<property>os.image.version</property>
							<newProperty>os.image.majorVersion</newProperty>
							<regexes>
								<regex>
									<pattern>([^.]+).*</pattern>
									<replacement>$1</replacement>
								</regex>
							</regexes>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-resources</id>
						<phase>process-resources</phase>
						<goals><goal>resources</goal></goals>
						<configuration>
							<encoding>utf-8</encoding>
							<propertiesEncoding>utf-8</propertiesEncoding>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<!-- This plugin build and pushes the Docker image -->
			<plugin>
				<groupId>org.eclipse.jkube</groupId>
				<artifactId>kubernetes-maven-plugin</artifactId>
				<configuration>
					<images>
						<image>
							<name>${image.name}:${image.tag}</name>
							<registry>${image.registry}</registry>
							<build>
								<contextDir>${project.build.directory}/resources</contextDir>
								<dockerFile>${project.basedir}/Containerfile</dockerFile>
								<tags>
									<tag>${base.version}-${os.image.shortName}${os.image.majorVersion}</tag>
								</tags>
							</build>
						</image>
					</images>
					<verbose>true</verbose>
				</configuration>
				<executions>
					<!-- This execution builds the Docker image -->
					<execution>
						<id>docker-build</id>
						<phase>package</phase>
						<goals><goal>build</goal></goals>
					</execution>
					<!-- This execution pushes the built Docker image to the configured Docker Registry -->
					<execution>
						<id>docker-push</id>
						<phase>deploy</phase>
						<goals><goal>push</goal></goals>
					</execution>
				</executions>
			</plugin>
			<!-- This plugin prevents the project from deploying to the Maven Repository, as it is pointless -->
			<plugin>
				<artifactId>maven-deploy-plugin</artifactId>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<profiles>
		<profile>
			<id>no-docker</id>
			<properties>
				<jkube.build.strategy>jib</jkube.build.strategy>
			</properties>
		</profile>
	</profiles>
	
</project>
+41 −0
Original line number Diff line number Diff line
#!/bin/bash

function ifecho() {
    if [[ ${VERBOSE} == "true" ]]; then
        echo "$1"
    fi
}

# error on any non-zero exit code
set -e

# setting environment variables here so they cannot be overridden
export CONTAINERD_ENTRYPOINT_PATH="${image.containerd.directory}"
export CACERT_INSTALL_PATH="/usr/local/share/ca-certificates"

if [[ ${SKIP_ENTRYPOINT_SCRIPTS} == "true" ]]; then
    ifecho "Skipping entrypoint executions ..."
else
    # execute all scripts
    CONTAINERD_FILES=( ${CONTAINERD_ENTRYPOINT_PATH}/*.sh )
    if (( ${#CONTAINERD_FILES[@]} > 1 )); then
        for (( CONTAINERD_FILEINDEX = 0; CONTAINERD_FILEINDEX < ${#CONTAINERD_FILES[@]}; CONTAINERD_FILEINDEX++ )); do
            CONTAINERD_FILE=${CONTAINERD_FILES[$CONTAINERD_FILEINDEX]}
            if [[ ${CONTAINERD_FILE} != "${CONTAINERD_ENTRYPOINT_PATH}/entrypoint.sh" ]]; then
                ifecho "Executing entrypoint: ${CONTAINERD_FILE}"
                . ${CONTAINERD_FILE}
            fi
        done
    fi
fi

if ! find ${CACERT_INSTALL_PATH}/ -maxdepth 0 -empty | read JUNK; then
    # update cacerts with any custom certs in /usr/local/share/ca-certificates
    ifecho "Updating CA certificates ..."
    update-ca-certificates
fi

if [[ ! -z $1 ]]; then
    ifecho "Executing command ..."
    exec "$@"
fi