-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish
executable file
·49 lines (39 loc) · 1.19 KB
/
publish
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
#!/bin/bash
set -euo pipefail
#################################################################################
# A script to tag and publish the docker container. When run, the image will be
# tagged with the supplied version, the current git SHA, and `latest`.
#
# These will then be pushed to DockerHub using the (encrypted) credentials from
# the environment
#
# Usage: $0 <version>
#################################################################################
REPO=pseudomuto/protoc-gen-twagger
_tag_image() {
docker build -t "${1}" .
docker tag "${1}" "${2}:${3}"
docker tag "${1}" "${2}:latest"
}
_push_image() {
# credentials are encrypted in travis.yml
docker login -u "${DOCKER_HUB_USER}" -p "${DOCKER_HUB_PASSWORD}"
docker push "${1}"
docker push "${2}:${3}"
docker push "${2}:latest"
}
main() {
if [ "$#" -ne 1 ]; then
echo "USAGE: $0 <version>"
exit 1
fi
local sha="${TRAVIS_COMMIT:-}"
if [ -z "${sha}" ]; then sha=$(git rev-parse HEAD); fi
local version="${1}"
local git_tag="${REPO}:${sha}"
_tag_image "${git_tag}" "${REPO}" "${version}"
if [ -n "${DOCKER_HUB_USER:-}" ]; then
_push_image "${git_tag}" "${REPO}" "${version}"
fi
}
main "$@"