-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdocker-push.sh
executable file
·33 lines (25 loc) · 1.21 KB
/
docker-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
#!/usr/bin/env bash
set -e
main() {
local PROJECT_NAME="docker-hostmanager"
[ -n "$DOCKER_USERNAME" ] || { echo 'DOCKER_USERNAME need to be declared'; exit 1; }
[ -n "$DOCKER_PASSWORD" ] || { echo 'DOCKER_PASSWORD need to be declared'; exit 1; }
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker build -t $DOCKER_USERNAME/$PROJECT_NAME:latest .
docker push $DOCKER_USERNAME/$PROJECT_NAME:latest
# Tag image
if [ -n "$TRAVIS_TAG" ];then
# Extract major, minor and revision from tag
local PARTS=( ${TRAVIS_TAG//./ } )
local MAJOR=${PARTS[0]}
local MINOR=${PARTS[1]}
local REVISION=${PARTS[2]}
docker tag $DOCKER_USERNAME/$PROJECT_NAME:latest $DOCKER_USERNAME/$PROJECT_NAME:$MAJOR
docker tag $DOCKER_USERNAME/$PROJECT_NAME:latest $DOCKER_USERNAME/$PROJECT_NAME:$MAJOR.$MINOR
docker tag $DOCKER_USERNAME/$PROJECT_NAME:latest $DOCKER_USERNAME/$PROJECT_NAME:$MAJOR.$MINOR.$REVISION
docker push $DOCKER_USERNAME/$PROJECT_NAME:$MAJOR
docker push $DOCKER_USERNAME/$PROJECT_NAME:$MAJOR.$MINOR
docker push $DOCKER_USERNAME/$PROJECT_NAME:$MAJOR.$MINOR.$REVISION
fi
}
main "$@"