-
Notifications
You must be signed in to change notification settings - Fork 13
/
push-image.sh
92 lines (71 loc) · 3.2 KB
/
push-image.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
#!/usr/bin/env bash
#
# Please refer to AUTHORS.md for a complete list of Copyright holders.
# Copyright (C) 2016-2023, Dockershelf Developers.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Exit early if there are errors and be verbose
set -exuo pipefail
# Some initial configuration
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load helper functions
source "${BASEDIR}/library.sh"
DOCKER_IMAGE_NAME="${1}"
DH_USERNAME="${2}"
DH_PASSWORD="${3}"
DOCKER_IMAGE_EXTRA_TAGS="${4}"
BRANCH="${5}"
if [ "${BRANCH}" == "develop" ]; then
DOCKER_IMAGE_NAME_SUFFIX="-dev"
else
DOCKER_IMAGE_NAME_SUFFIX=""
fi
# Exit if we didn't get an image to push
if [ -z "${DOCKER_IMAGE_NAME}" ]; then
msgerror "No Docker image name was given. Aborting."
exit 1
fi
# Exit if we didn't get credentials
if [ -z "${DH_USERNAME}" ] || [ -z "${DH_PASSWORD}" ]; then
msgerror "Username or Password for Docker Hub were not given. Aborting."
exit 1
fi
DOCKER_TEST_IMAGE_NAME="${DOCKER_IMAGE_NAME}-test${DOCKER_IMAGE_NAME_SUFFIX}"
DOCKER_FINAL_IMAGE_NAME="${DOCKER_IMAGE_NAME}${DOCKER_IMAGE_NAME_SUFFIX}"
# Login
docker login --username ${DH_USERNAME} --password ${DH_PASSWORD}
docker tag ${DOCKER_TEST_IMAGE_NAME}-arm64 ${DOCKER_FINAL_IMAGE_NAME}-arm64
docker push ${DOCKER_FINAL_IMAGE_NAME}-arm64
docker tag ${DOCKER_TEST_IMAGE_NAME}-amd64 ${DOCKER_FINAL_IMAGE_NAME}-amd64
docker push ${DOCKER_FINAL_IMAGE_NAME}-amd64
docker manifest rm ${DOCKER_FINAL_IMAGE_NAME} || true
docker manifest create ${DOCKER_FINAL_IMAGE_NAME} \
--amend ${DOCKER_FINAL_IMAGE_NAME}-arm64 \
--amend ${DOCKER_FINAL_IMAGE_NAME}-amd64
docker manifest inspect ${DOCKER_FINAL_IMAGE_NAME}
docker manifest push --purge ${DOCKER_FINAL_IMAGE_NAME}
if [ -n "${DOCKER_IMAGE_EXTRA_TAGS}" ]; then
for EXTRA_TAG in ${DOCKER_IMAGE_EXTRA_TAGS}; do
DOCKER_EXTRA_TAG_IMAGE_NAME="${EXTRA_TAG}${DOCKER_IMAGE_NAME_SUFFIX}"
# Login
docker login --username ${DH_USERNAME} --password ${DH_PASSWORD}
docker tag ${DOCKER_TEST_IMAGE_NAME}-arm64 ${DOCKER_EXTRA_TAG_IMAGE_NAME}-arm64
docker push ${DOCKER_EXTRA_TAG_IMAGE_NAME}-arm64
docker tag ${DOCKER_TEST_IMAGE_NAME}-amd64 ${DOCKER_EXTRA_TAG_IMAGE_NAME}-amd64
docker push ${DOCKER_EXTRA_TAG_IMAGE_NAME}-amd64
docker manifest rm ${DOCKER_EXTRA_TAG_IMAGE_NAME} || true
docker manifest create ${DOCKER_EXTRA_TAG_IMAGE_NAME} \
--amend ${DOCKER_EXTRA_TAG_IMAGE_NAME}-arm64 \
--amend ${DOCKER_EXTRA_TAG_IMAGE_NAME}-amd64
docker manifest inspect ${DOCKER_EXTRA_TAG_IMAGE_NAME}
docker manifest push --purge ${DOCKER_EXTRA_TAG_IMAGE_NAME}
done
fi