Skip to content

Commit

Permalink
Enhancements to the build system:
Browse files Browse the repository at this point in the history
  - Combined Dockerfile.alpine and Dockerfile.alpine-glibc by conditionaly installing glibc.
  - Each different images that need to be built have their parameters set in separate files.
  - Use build args instead of generating a new Dockerfile.
  - Added script for local builds.
  - Pave the way for multi-arch images.
  • Loading branch information
jlesage committed Jan 4, 2018
1 parent 5c8dc99 commit 3f05006
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 266 deletions.
18 changes: 0 additions & 18 deletions .travis.script

This file was deleted.

13 changes: 3 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,15 @@ services:
env:
global:
- DOCKER_REPO=jlesage/baseimage
- SOURCE_BRANCH=dev
matrix:
- DOCKER_TAG=alpine-3.7
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=alpine-3.7-glibc
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=alpine-3.6
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=alpine-3.6-glibc
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=alpine-3.5
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=alpine-3.5-glibc
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=debian-8
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG
- DOCKER_TAG=ubuntu-16.04
IMAGE_NAME=$DOCKER_REPO:$DOCKER_TAG

before_install:
- sudo add-apt-repository ppa:duggan/bats --yes
Expand All @@ -40,4 +31,6 @@ before_script:
- hooks/pre_build

script:
- bash -e .travis.script
- |
hooks/build && \
env DOCKER_IMAGE="$DOCKER_REPO:$DOCKER_TAG" bats tests
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# This is a dummy Dockerfile. Do not edit, it will be overwritten by Docker automated build.
# To get the content of Dockerfile, see https://github.com/jlesage/docker-baseimage-gui
# This is a dummy Dockerfile.
# See https://github.com/jlesage/docker-baseimage to get the content of the
# Dockerfile used to generate this image.
62 changes: 57 additions & 5 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,71 @@
# https://github.com/jlesage/docker-baseimage
#

ARG BASEIMAGE=unknown

# Pull base image.
FROM ${BASEIMAGE}

# Define software versions.
# Define s6 overlay related variables.
ARG S6_OVERLAY_ARCH=x86_64
ARG S6_OVERLAY_VERSION=1.21.2.1
ARG S6_OVERLAY_URL=https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.gz

# Define software download URLs.
ARG S6_OVERLAY_URL=https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-amd64.tar.gz
# Define GLIBC related variables.
ARG GLIBC_INSTALL=0
ARG GLIBC_ARCH=x86_64
ARG GLIBC_VERSION=2.26-0
ARG GLIBC_URL=https://github.com/sgerrand/docker-glibc-builder/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}-${GLIBC_ARCH}.tar.gz
ARG GLIBC_LOCALE_INPUT=en_US
ARG GLIBC_LOCALE_CHARMAP=UTF-8
ARG GLIBC_LOCALE=${GLIBC_LOCALE_INPUT}.${GLIBC_LOCALE_CHARMAP}

# Define working directory.
WORKDIR /tmp

# Copy helpers.
COPY helpers/* /usr/local/bin/

# Install glibc if needed.
RUN \
test "${GLIBC_INSTALL}" -eq 0 || ( \
add-pkg --virtual build-dependencies curl && \
# Download and install glibc.
curl -# -L ${GLIBC_URL} | tar xz -C / && \
# Create /etc/nsswitch.conf.
echo -n "hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4" > /etc/nsswitch.conf && \
# Create /usr/glibc-compat/etc/ld.so.conf
echo "# libc default configuration" >> /usr/glibc-compat/etc/ld.so.conf && \
echo "/usr/local/lib" >> /usr/glibc-compat/etc/ld.so.conf && \
echo "/usr/glibc-compat/lib" >> /usr/glibc-compat/etc/ld.so.conf && \
echo "/usr/lib" >> /usr/glibc-compat/etc/ld.so.conf && \
echo "/lib" >> /usr/glibc-compat/etc/ld.so.conf && \
# Create required symbolic links.
mkdir -p /lib /lib64 /usr/glibc-compat/lib/locale && \
ln -s /usr/glibc-compat/lib/ld-linux-x86-64.so.2 /lib/ld-linux-x86-64.so.2 && \
ln -s /usr/glibc-compat/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 && \
ln -s /usr/glibc-compat/etc/ld.so.cache /etc/ld.so.cache && \
# Run ldconfig.
/usr/glibc-compat/sbin/ldconfig && \
# Generate locale.
/usr/glibc-compat/bin/localedef --inputfile ${GLIBC_LOCALE_INPUT} \
--charmap ${GLIBC_LOCALE_CHARMAP} \
${GLIBC_LOCALE} && \
# Timezone support.
ln -s /usr/share/zoneinfo /usr/glibc-compat/share/zoneinfo && \
# Remove unneeded stuff.
rm /usr/glibc-compat/etc/rpc && \
rm /usr/glibc-compat/lib/*.a && \
rm -r /usr/glibc-compat/lib/audit && \
rm -r /usr/glibc-compat/lib/gconv && \
rm -r /usr/glibc-compat/lib/getconf && \
rm -r /usr/glibc-compat/include && \
rm -r /usr/glibc-compat/share && \
rm -r /usr/glibc-compat/var && \
# Cleanup
del-pkg build-dependencies && \
rm -rf /tmp/* /tmp/.[!.]* )

# Install s6 overlay.
RUN \
add-pkg --virtual build-dependencies curl tar patch && \
Expand Down Expand Up @@ -57,7 +107,8 @@ RUN \
COPY rootfs/ /

# Set environment variables.
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=3 \
ENV LANG=${ALPINE_GLIBC_LOCALE} \
S6_BEHAVIOUR_IF_STAGE2_FAILS=3 \
S6_SERVICE_DEPS=1 \
USER_ID=1000 \
GROUP_ID=1000 \
Expand All @@ -75,9 +126,10 @@ VOLUME ["/config"]
CMD ["/init"]

# Metadata.
ARG IMAGE_VERSION=unknown
LABEL \
org.label-schema.name="baseimage" \
org.label-schema.description="A minimal docker baseimage to ease creation of long-lived application containers" \
org.label-schema.version="unknown" \
org.label-schema.version="${IMAGE_VERSION}" \
org.label-schema.vcs-url="https://github.com/jlesage/docker-baseimage" \
org.label-schema.schema-version="1.0"
122 changes: 0 additions & 122 deletions Dockerfile.alpine-glibc

This file was deleted.

12 changes: 7 additions & 5 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
# https://github.com/jlesage/docker-baseimage
#

ARG BASEIMAGE=unknown

# Pull base image.
FROM ${BASEIMAGE}

# Define software versions.
# Define s6 overlay related variables.
ARG S6_OVERLAY_ARCH=x86_64
ARG S6_OVERLAY_VERSION=1.21.2.1

# Define software download URLs.
ARG S6_OVERLAY_URL=https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-amd64.tar.gz
ARG S6_OVERLAY_URL=https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.gz

# Variables needed for package installation via APT.
ARG DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -87,9 +88,10 @@ VOLUME ["/config"]
CMD ["/init"]

# Metadata.
ARG IMAGE_VERSION=unknown
LABEL \
org.label-schema.name="baseimage" \
org.label-schema.description="A minimal docker baseimage to ease creation of long-lived application containers" \
org.label-schema.version="unknown" \
org.label-schema.version="${IMAGE_VERSION}" \
org.label-schema.vcs-url="https://github.com/jlesage/docker-baseimage" \
org.label-schema.schema-version="1.0"
83 changes: 83 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"

usage() {
if [ "$*" ]; then
echo "$*"
echo
fi

echo "usage: $( basename $0 ) [OPTION]... DOCKER_TAG [DOCKER_TAG]...
Arguments:
DOCKER_TAG Defines the container flavor to build. Valid values are:
$(find "$SCRIPT_DIR"/versions -type f -printf ' %f\n' | sort)
all
Options:
-c, --without-cache Do not use the Docker cache when building.
-h, --help Display this help.
"
}

requirements() {
if [ -z "$( which bats )" ]; then
echo "ERROR: To run test, bats needs to be installed."
fi
}

# Parse arguments.
while [[ $# > 0 ]]
do
key="$1"

case $key in
-c|--without-cache)
USE_DOCKER_BUILD_CACHE=0
;;
-h|--help)
usage
exit 0
;;
-*)
usage "ERROR: Unknown argument: $key"
exit 1
;;
*)
break
;;
esac
shift
done

DOCKER_TAGS="$*"

[ -z "$DOCKER_TAGS" ] && usage "ERROR: At least one Docker tag must be specified." && exit 1
[ "$DOCKER_TAGS" == "all" ] && DOCKER_TAGS="$(find "$SCRIPT_DIR"/versions -type f -printf '%f ' | sort)"
for DOCKER_TAG in $DOCKER_TAGS; do
if [ ! -f "$SCRIPT_DIR"/versions/"$DOCKER_TAG" ]; then
usage "ERROR: Invalid docker tag: $DOCKER_TAG."
exit 1
fi
done

for DOCKER_TAG in $DOCKER_TAGS; do
# Export build variables.
export DOCKER_REPO=jlesage/baseimage
export DOCKER_TAG=$DOCKER_TAG
export USE_DOCKER_BUILD_CACHE=${USE_DOCKER_BUILD_CACHE:-1}

# Build.
hooks/pre_build
hooks/build

# Run tests.
for i in $(seq -s ' ' 1 5 | rev)
do
echo "Starting tests of Docker image $DOCKER_REPO:$DOCKER_TAG in $i..."
sleep 1
done
env DOCKER_IMAGE="$DOCKER_REPO:$DOCKER_TAG" bats tests
done
Loading

0 comments on commit 3f05006

Please sign in to comment.