diff options
author | Chris Akritidis <43294513+cakrit@users.noreply.github.com> | 2019-03-13 12:47:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 12:47:20 +0100 |
commit | b7998ec82d579bd0550e23f880decdcee61264f5 (patch) | |
tree | 834bb528d86c9cff943fe33220952de4cbceca8b /packaging/docker/build-test.sh | |
parent | 97699c5c60342be372d776da4829167adfdfc133 (diff) |
When running from within a k8s pod, use the k8s API to get the cgroup name (#5576)
* When running from within a k8s pod, use the k8s API to get the pod name
* Check the last part of an underscore-delimited or slash-delimited container id
* Add a docker image builder that adds a single image to a user-specified registry, for use in k8s
* When running in k8s, disable cgroups that the pod API does not return
* Use longer name for k8s containers
* Add reference to build-test.sh to packaging/docker/README.md
* Anonymous statistics should not break when /proc/1/sched is not available
Diffstat (limited to 'packaging/docker/build-test.sh')
-rwxr-xr-x | packaging/docker/build-test.sh | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/packaging/docker/build-test.sh b/packaging/docker/build-test.sh new file mode 100755 index 0000000000..171b7c85d8 --- /dev/null +++ b/packaging/docker/build-test.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0-or-later +# Author : Chris Akritidis (cakrit) +# Cross-arch docker build helper script + +printhelp() { + echo "Usage: packaging/docker/build-test.sh -r <REPOSITORY> -v <VERSION> -u <DOCKER_USERNAME> -p <DOCKER_PASSWORD> [-s] + -s skip build, just push the image +Builds an amd64 image and pushes it to the docker hub repository REPOSITORY" +} + +set -e + +if [ ! -f .gitignore ]; then + echo "Run as ./packaging/docker/$(basename "$0") from top level directory of git repository" + exit 1 +fi + +DOBUILD=1 +while getopts :r:v:u:p:s option +do + case "$option" in + r) + REPOSITORY=$OPTARG + ;; + v) + VERSION=$OPTARG + ;; + u) + DOCKER_USERNAME=$OPTARG + ;; + p) + DOCKER_PASSWORD=$OPTARG + ;; + s) + DOBUILD=0 + ;; + *) + printhelp + exit 1 + ;; + esac +done + +if [ -n "${REPOSITORY}" ] && [ -n "${VERSION}" ] && [ -n "${DOCKER_USERNAME}" ] && [ -n "${DOCKER_PASSWORD}" ] ; then + if [ $DOBUILD -eq 1 ] ; then + echo "Building ${VERSION} of ${REPOSITORY} container" + docker run --rm --privileged multiarch/qemu-user-static:register --reset + + # Build images using multi-arch Dockerfile. + eval docker build --build-arg ARCH="amd64" --tag "${REPOSITORY}:${VERSION}" --file packaging/docker/Dockerfile ./ + + # Create temporary docker CLI config with experimental features enabled (manifests v2 need it) + mkdir -p /tmp/docker + #echo '{"experimental":"enabled"}' > /tmp/docker/config.json + fi + + # Login to docker hub to allow futher operations + echo "Logging into docker" + echo "$DOCKER_PASSWORD" | docker --config /tmp/docker login -u "$DOCKER_USERNAME" --password-stdin + + echo "Pushing ${REPOSITORY}:${VERSION}" + docker --config /tmp/docker push "${REPOSITORY}:${VERSION}" +else + echo "Missing parameter. REPOSITORY=${REPOSITORY} VERSION=${VERSION} DOCKER_USERNAME=${DOCKER_USERNAME} DOCKER_PASSWORD=${DOCKER_PASSWORD}" + printhelp + exit 1 +fi |