-
Notifications
You must be signed in to change notification settings - Fork 313
/
build-dev-docker-manifest.sh
executable file
·98 lines (78 loc) · 3.57 KB
/
build-dev-docker-manifest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Prerequisites for releasing:
# Logged in on Docker Hub (docker login)
# fail this script immediately if any command fails with a non-zero exit code
set -eu
function push_failed {
echo "Error while pushing Docker image. Did you \`docker login\`?"
}
if [[ $# -eq 0 ]] ; then
echo "ERROR: $0 requires the Rally branch to build from as a command line argument and you didn't supply it."
echo "For example: $0 master true"
exit 1
fi
export RALLY_BRANCH=$1
export PUSH_LATEST=$2
export PUBLIC_DOCKER_REPO=$3
if [[ $PUBLIC_DOCKER_REPO == "true" ]]; then
export RALLY_DOCKER_IMAGE="elastic/rally"
else
export RALLY_DOCKER_IMAGE="docker.elastic.co/es-perf/rally"
fi
export RALLY_LICENSE=$(awk 'FNR>=2 && FNR<=2' LICENSE | sed 's/^[ \t]*//')
export GIT_SHA=$(git rev-parse --short HEAD)
export DATE=$(date +%Y%m%d)
export RALLY_VERSION="${RALLY_BRANCH}-${GIT_SHA}-${DATE}"
export MAIN_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
if [[ $RALLY_BRANCH == $MAIN_BRANCH ]]; then
export DOCKER_TAG_LATEST="dev-latest"
else
export DOCKER_TAG_LATEST="${RALLY_BRANCH}-latest"
fi
echo "========================================================"
echo "Pulling Docker images for Rally $RALLY_VERSION "
echo "========================================================"
docker pull ${RALLY_DOCKER_IMAGE}:${RALLY_VERSION}-amd64
docker pull ${RALLY_DOCKER_IMAGE}:${RALLY_VERSION}-arm64
echo "======================================================="
echo "Creating Docker manifest image for Rally $RALLY_VERSION"
echo "======================================================="
docker manifest create ${RALLY_DOCKER_IMAGE}:${RALLY_VERSION} \
--amend ${RALLY_DOCKER_IMAGE}:${RALLY_VERSION}-amd64 \
--amend ${RALLY_DOCKER_IMAGE}:${RALLY_VERSION}-arm64
trap push_failed ERR
echo "======================================================="
echo "Publishing Docker image ${RALLY_DOCKER_IMAGE}:$RALLY_VERSION "
echo "======================================================="
docker manifest push ${RALLY_DOCKER_IMAGE}:${RALLY_VERSION}
trap - ERR
if [[ $PUSH_LATEST == "true" ]]; then
echo "======================================================="
echo "Creating Docker manifest image for Rally $DOCKER_TAG_LATEST"
echo "======================================================="
docker manifest create ${RALLY_DOCKER_IMAGE}:${DOCKER_TAG_LATEST} \
--amend ${RALLY_DOCKER_IMAGE}:${DOCKER_TAG_LATEST}-amd64 \
--amend ${RALLY_DOCKER_IMAGE}:${DOCKER_TAG_LATEST}-arm64
trap push_failed ERR
echo "======================================================="
echo "Publishing Docker image ${RALLY_DOCKER_IMAGE}:${DOCKER_TAG_LATEST}"
echo "======================================================="
docker manifest push ${RALLY_DOCKER_IMAGE}:${DOCKER_TAG_LATEST}
fi
trap - ERR