forked from edannenberg/kubler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.sh
executable file
·65 lines (51 loc) · 1.79 KB
/
push.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
#!/bin/bash
#
# Copyright (C) 2014-2015 Erik Dannenberg <[email protected]>
#
# Push images to repository, auth credentials are read from dock/<namespace>/push.conf
#
# Docker specific:
# If -h param is omitted docker.io is assumed as repository
# vars for push.conf: DOCKER_LOGIN, DOCKER_PW, DOCKER_EMAIL
#
# Usage: ./push.sh -h my-repository.org:5000 [namespace/image] or [namespace] ...
show_help() {
echo -e "usage: ./push.sh -h my-repository.org:5000 [namespace/image] or [namespace] ...\n"
exit 0
}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT=$(realpath -s $SCRIPT_DIR)
[ ! -f "${PROJECT_ROOT}/inc/core.sh" ] && echo "error: failed to read ${PROJECT_ROOT}/inc/core.sh" && exit 1
source "${PROJECT_ROOT}/inc/core.sh"
[[ ! -f "${PROJECT_ROOT}/build.conf" ]] && die "error: failed to read build.conf"
source "${PROJECT_ROOT}/build.conf"
DATE_ROOT="${DATE?Error \$DATE is not defined.}"
REPOSITORY_URL=""
while getopts "h:" opt; do
case $opt in
h)
REPOSITORY_URL=${OPTARG}
;;
esac
done
shift $(( $OPTIND -1 ))
[ "$1" = "--" ] && shift
[ -z "${1}" ] && show_help
REPO_ARGS="${@:-"*"}"
cd "${REPO_PATH}"
REPOS=$(expand_requested_repos "${REPO_ARGS}") || die "error expanding repos: ${REPO_ARGS}"
for REPO in $REPOS; do
NAMESPACE=${REPO%%/*}
REPO_EXPANDED=${REPO/\//\/${IMAGE_PATH}}
source_namespace_conf "$REPO_EXPANDED"
source_push_conf "${REPO}"
if ! image_exists $REPO; then
echo "skipping ${REPO}:${DATE}, image is not build yet"
continue
fi
if [[ "${LAST_PUSH_AUTH_NS}" != ${NAMESPACE} ]]; then
push_auth "${NAMESPACE}" "${REPOSITORY_URL}" || die "error while logging into repository"
LAST_PUSH_AUTH_NS=${NAMESPACE}
fi
push_image "${REPO}" "${REPOSITORY_URL}"
done