|
| 1 | + |
| 2 | + |
| 3 | +# This script is used by the Containerfile when building an image. |
| 4 | +# It should NEVER ever (EVER!) be used under any other circumstances |
| 5 | +# (nor set as executable). |
| 6 | + |
| 7 | +set -e |
| 8 | + |
| 9 | +declare -a req_vars |
| 10 | +req_vars=(\ |
| 11 | + REG_REPO |
| 12 | + REG_COMMIT_SCHEMA1_ONLY |
| 13 | + REG_COMMIT_SCHEMA1_SUPPORTED |
| 14 | + OSO_REPO |
| 15 | + OSO_TAG |
| 16 | +) |
| 17 | +for req_var in "${req_vars[@]}"; do |
| 18 | + if [[ -z "${!req_var}" ]]; then |
| 19 | + echo "ERROR: Required variable \$$req_var is unset or empty." |
| 20 | + exit 1 |
| 21 | + fi |
| 22 | +done |
| 23 | + |
| 24 | +GOPATH=$(mktemp -d -p '' ".tmp_$(basename ${BASH_SOURCE[0]})_XXXXXXXX") |
| 25 | +REG_GOSRC="$GOPATH/src/github.com/docker/distribution" \ |
| 26 | +OSO_GOSRC="$GOPATH/src/github.com/openshift/origin" |
| 27 | + |
| 28 | +# All golang code built here pre-dates support of go modules |
| 29 | +export GO111MODULE=off |
| 30 | + |
| 31 | +# Workaround unnecessary swap-enabling shenanagains in openshift-origin build |
| 32 | +export OS_BUILD_SWAP_DISABLE=1 |
| 33 | + |
| 34 | +# Make debugging easier |
| 35 | +set -x |
| 36 | + |
| 37 | +# This comes in from the Containerfile |
| 38 | +# shellcheck disable=SC2154 |
| 39 | +git clone "$REG_REPO" "$REG_GOSRC" |
| 40 | +cd "$REG_GOSRC" |
| 41 | + |
| 42 | +# Don't pollute the environment |
| 43 | +( |
| 44 | + # This is required to be set like this by the build system |
| 45 | + export GOPATH="$PWD/Godeps/_workspace:$GOPATH" |
| 46 | + # This comes in from the Containerfile |
| 47 | + # shellcheck disable=SC2154 |
| 48 | + git checkout -q "$REG_COMMIT_SCHEMA1_ONLY" |
| 49 | + go build -o /usr/local/bin/registry-v2-schema1-only \ |
| 50 | + github.com/docker/distribution/cmd/registry |
| 51 | +) |
| 52 | + |
| 53 | +( |
| 54 | + export GOPATH |
| 55 | + # This comes in from the Containerfile |
| 56 | + # shellcheck disable=SC2154 |
| 57 | + git checkout -q "$REG_COMMIT_SCHEMA1_SUPPORTED" |
| 58 | + go build -o /usr/local/bin/registry-v2-schema1-supported \ |
| 59 | + github.com/docker/distribution/cmd/registry |
| 60 | +) |
| 61 | + |
| 62 | +# These come in from the Containerfile |
| 63 | +# shellcheck disable=SC2154 |
| 64 | +git clone --depth 1 -b "$OSO_TAG" "$OSO_REPO" "$OSO_GOSRC" |
| 65 | +cd "$OSO_GOSRC" |
| 66 | + |
| 67 | +# Edit out a "go < 1.5" check which works incorrectly with go >= 1.10. |
| 68 | +sed -i -e 's/\[\[ "\${go_version\[2]}" < "go1.5" ]]/false/' ./hack/common.sh |
| 69 | + |
| 70 | +# Fix a bug in 'options' line processing of resolv.conf when an option is |
| 71 | +# 8 characters long. This can happen if/when systemd-resolved adds 'trust-ad'. |
| 72 | +sed -i '/== "attempts:"/s/ 8 / 9 /' vendor/github.com/miekg/dns/clientconfig.go |
| 73 | + |
| 74 | +# Backport https://github.com/ugorji/go/commit/8286c2dc986535d23e3fad8d3e816b9dd1e5aea6 |
| 75 | +# Go ≥ 1.22 panics with a base64 encoding using duplicated characters. |
| 76 | +sed -i -e 's,"encoding/base64","encoding/base32", ; s,base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789__"),base32.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"),' vendor/github.com/ugorji/go/codec/gen.go |
| 77 | + |
| 78 | +make build |
| 79 | +make all WHAT=cmd/dockerregistry |
| 80 | +cp -a ./_output/local/bin/linux/*/* /usr/local/bin/ |
| 81 | +cp ./images/dockerregistry/config.yml /atomic-registry-config.yml |
| 82 | +mkdir /registry |
| 83 | + |
| 84 | +# When script unsuccessful, leave this behind for debugging |
| 85 | +# Removing these two items _significantly_ reduces the image size. |
| 86 | +rm -rf $GOPATH $(go env GOCACHE) |
0 commit comments