Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing Multiarch dockerimages #21

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
# We ignore everything
# But including the finalfate directory
!finalfate/
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Setup variables
ARG SRC_NAME=amd64
ARG SRC_REPO=httpd
ARG SRC_TAG=alpine

# Pull image
FROM ${SRC_NAME}/${SRC_REPO}:${SRC_TAG}

COPY finalfate/ /usr/local/apache2/htdocs/
20 changes: 20 additions & 0 deletions aarch64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Set global environment variables

# Setup qemu
FROM alpine AS qemu

ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-aarch64.tar.gz

RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1

# Setup arguments for next image
ARG SRC_NAME
ARG SRC_REPO
ARG SRC_VERSION

# Pull image
FROM ${SRC_NAME}/${SRC_REPO}:${SRC_TAG} as bundle

COPY --from=qemu qemu-aarch64-static /usr/bin

COPY finalfate/ /usr/local/apache2/htdocs/
20 changes: 20 additions & 0 deletions armhf.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Set global environment variables

# Setup Qemu
FROM alpine AS qemu

ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v3.0.0%2Bresin/qemu-3.0.0+resin-arm.tar.gz

RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1

# Setup arguments for next image
ARG SRC_USER
ARG SRC_REPO
ARG SRC_VERSION

# Pull image
FROM ${SRC_NAME}/${SRC_REPO}:${SRC_TAG} as bundle

COPY --from=qemu qemu-arm-static /usr/bin

COPY finalfate/ /usr/local/apache2/htdocs/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 93 additions & 0 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# Local test values
DEST_ARCHES="amd64 arm32v7 arm64v8"
# Environment
DOCKERHUB_NAME="mengel38"
DEST_REPO="finalfate"
SRC_REPO="httpd"
SRC_TAG="alpine"

# dynamic Values
apt-get update && apt-get install git -y -q
VCS_REF="$(git rev-parse --short HEAD)"
BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
DEST_TAG="${DOCKER_TAG}"

echo "DEBUG: ${VCSREF} and ${BUILD_DATE}"

# Begin generating manifest file
echo "image: ${DOCKERHUB_NAME}/${DEST_REPO}:${DEST_TAG}" > auto-docker-manifest.yaml
echo "manifests:" >> auto-docker-manifest.yaml

# Cycle trough the the arches
for DEST_BUILD_ARCH in ${DEST_ARCHES}
do
echo "DEBUG: Begin Cycle ${DEST_BUILD_ARCH}"
DEST_OS="linux"
# Set AMD64
if [ ${DEST_BUILD_ARCH} == "amd64" ]; then
SRC_NAME="amd64"
DEST_ARCH=${DEST_BUILD_ARCH}
DOCKER_PREFIX=""
echo " - image: ${DOCKERHUB_NAME}/${DEST_REPO}:${DEST_TAG}-${DEST_BUILD_ARCH}" >> auto-docker-manifest.yaml
echo " platform:" >> auto-docker-manifest.yaml
echo " architecture: ${DEST_ARCH}" >> auto-docker-manifest.yaml
echo " os: ${DEST_OS}" >> auto-docker-manifest.yaml

# Set armhf
elif [ ${DEST_BUILD_ARCH} == "arm32v7" ]; then
SRC_NAME="arm32v7"
DEST_ARCH="arm"
DOCKERFILE_PREFIX="armhf."
echo " - image: ${DOCKERHUB_NAME}/${DEST_REPO}:${DEST_TAG}-${DEST_BUILD_ARCH}" >> auto-docker-manifest.yaml
echo " platform:" >> auto-docker-manifest.yaml
echo " architecture: ${DEST_ARCH}" >> auto-docker-manifest.yaml
echo " os: ${DEST_OS}" >> auto-docker-manifest.yaml
echo " variant: v7" >> auto-docker-manifest.yaml

# Set arm64
elif [ ${DEST_BUILD_ARCH} == "arm64v8" ]; then
SRC_NAME="arm64v8"
DEST_ARCH="arm64"
DOCKERFILE_PREFIX="aarch64."
echo " - image: ${DOCKERHUB_NAME}/${DEST_REPO}:${DEST_TAG}-${DEST_BUILD_ARCH}" >> auto-docker-manifest.yaml
echo " platform:" >> auto-docker-manifest.yaml
echo " architecture: ${DEST_ARCH}" >> auto-docker-manifest.yaml
echo " os: ${DEST_OS}" >> auto-docker-manifest.yaml
echo " variant: v8" >> auto-docker-manifest.yaml

# arch not found
else
echo "FATAL: The buildarch is not referenced here. Exiting"
exit 1
fi

echo "Begin Building ${DEST_BUILD_ARCH}"
DOCKERFILE="${DOCKERFILE_PREFIX}Dockerfile"
# Build the docker image
docker build \
--compress \
--pull \
--label description="The Space Game created from Mengel38" \
--label docker.cmd="docker run -d ${DOCKERHUB_NAME}/${DEST_REPO}" \
--label maintainer="mengel38" \
--label vendor="mengel38" \
--label vcs-url="https://github.com/mengel38/finalfate" \
--label url="https://github.com/mengel38/finalfate" \
--label name="${IMAGE_NAME}" \
--label version="${BUILD_VERSION}"\
--label build-date="${BUILD_DATE}" \
--label vcs-ref="${VCS_REF}" \
--label schema-version="1.0.0-rc1" \
--file "${DOCKERFILE}" \
--build-arg SRC_REPO="${SRC_REPO}" \
--build-arg SRC_TAG="${SRC_TAG}" \
--build-arg SRC_NAME="${SRC_NAME}" \
--tag "${DOCKERHUB_NAME}/${DEST_REPO}:${DEST_TAG}-${DEST_BUILD_ARCH}" \
.
done

echo "Exit build hook"

exit 0
33 changes: 33 additions & 0 deletions hooks/post_checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

SRC_ARCH="amd64"
DEST_ARCHES="amd64 arm32v7 arm64v8"

# Cycle trough the the arches
for DEST_BUILD_ARCH in ${DEST_ARCHES}
do
if [ ${DEST_BUILD_ARCH} == "amd64" ]; then
echo 'qemu-user-static: Download not required for amd64'
continue
elif [ ${DEST_BUILD_ARCH} == "arm32v7" ]; then
QEMU_USER_STATIC_ARCH="arm"
elif [ ${DEST_BUILD_ARCH} == "arm64v8" ]; then
QEMU_USER_STATIC_ARCH="aarch64"
else
echo "DEBUG: DEST_BUILD_ARCH not referenced"
exit 1
fi

QEMU_USER_STATIC_DOWNLOAD_URL="https://github.com/multiarch/qemu-user-static/releases/download"
QEMU_USER_STATIC_LATEST_TAG=$(curl -s https://api.github.com/repos/multiarch/qemu-user-static/tags \
| grep 'name.*v[0-9]' \
| head -n 1 \
| cut -d '"' -f 4)

curl -SL "${QEMU_USER_STATIC_DOWNLOAD_URL}/${QEMU_USER_STATIC_LATEST_TAG}/x86_64_qemu-${QEMU_USER_STATIC_ARCH}-static.tar.gz" \
| tar xzv
done

echo "DEBUG: Exiting post_checkout"

exit 0
7 changes: 7 additions & 0 deletions hooks/pre_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

docker run --rm --privileged multiarch/qemu-user-static:register --reset

echo "DEBUG: Exiting pre_build"

exit 0
28 changes: 28 additions & 0 deletions hooks/push
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

apt-get update && apt-get install wget -y -q

# DEBUG
cat auto-docker-manifest.yaml

# Get the manifest-tool
wget -cO - https://github.com/estesp/manifest-tool/releases/download/v1.0.0/manifest-tool-linux-amd64 > manifest-tool

chmod +x manifest-tool

echo "Push the docker images"

# Cycle trough the the arches again and push the images
for DEST_BUILD_ARCH in ${DEST_ARCHES}
do
docker push ${DOCKERHUB_NAME}/${DEST_REPO}:${DEST_TAG}-${DEST_BUILD_ARCH}
done

echo "Push the manifest"

./manifest-tool push from-spec auto-docker-manifest.yaml
rm -f auto-docker-manifest.yaml

echo "DEBUG: Exiting push"

exit 0