-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish_jochre_image.sh
executable file
·61 lines (48 loc) · 2.36 KB
/
publish_jochre_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
#!/bin/bash -eu
echoerr() { echo "$@" 1>&2; }
SCRIPTDIR=$(dirname "$0")
main() {
export JOCHRE3_SEARCH_VERSION=$(git tag -l --contains HEAD | cat | { grep "^[0-9]\+\.[0-9]\+\.[0-9]\+\(-SNAPSHOT\)\?" || true;} )
if [[ -z JOCHRE3_SEARCH_VERSION ]] ; then
echo "No tag corresponding to a matching semver among current tags:"
git tag -l --contains HEAD | cat
exit 1
fi
if [[ $(echo "JOCHRE3_SEARCH_VERSION" | wc -l) != 1 ]] ; then
echo "More than one tag corresponding to a matching semver":
echo "JOCHRE3_SEARCH_VERSION"
exit 2
fi
local docker_registry=${JOCHRE3_DOCKER_REGISTRY:-registry.gitlab.com}
echo "Using registry: $docker_registry"
local docker_username=${JOCHRE3_DOCKER_USERNAME:-deploy}
echo "Using username: $docker_username"
if [[ -z ${JOCHRE3_DOCKER_PASSWORD:-} ]]; then
echoerr "JOCHRE3_DOCKER_PASSWORD not set, trying to use \`pass show jochre/sonatype_deploy\` instead"
if ! pass show sd/sonatype_deploy > /dev/null; then
exit 1
fi
fi
local docker_password=${JOCHRE3_DOCKER_PASSWORD:-$(pass show jochre/sonatype_deploy)}
docker_image="${docker_registry}/jochre3-server:${JOCHRE3_SEARCH_VERSION}"
echo "DOCKER_IMAGE=${docker_image}" >> /tmp/deploy.env
echo ${docker_password} | docker login ${docker_registry} -u ${docker_username} --password-stdin
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $docker_image > /dev/null; then
echo "$docker_image already released"
if [[ ${FORCE_REDEPLOY_IMAGE:-} == "true" ]] ; then
echo "FORCE_REDEPLOY_IMAGE set, lets rebuild and redeploy the migration image "
elif echo $JOCHRE3_SEARCH_VERSION | grep "\-SNAPSHOT$" ;then
echo "$JOCHRE3_SEARCH_VERSION is a SNAPSHOT, lets repush it"
else
echo -e "\nIf you want to redeploy you semver must finish by -SNAPSHOT"
echo "or you can force repdeploy setting FORCE_REDEPLOY_IMAGE=true"
exit 0
fi
fi
export JOCHRE3_DOCKER_REGISTRY=${docker_registry}
export JOCHRE3_DOCKER_USERNAME=${docker_username}
export JOCHRE3_DOCKER_PASSWORD=${docker_password}
docker-compose -p ${COMPOSE_PROJECT} -f docker-compose/runner.yml build publisher
docker-compose -p ${COMPOSE_PROJECT} -f docker-compose/runner.yml run -T publisher
}
main "$@"