blob: 2267e8b08d06aa447b554a9909161d4f046c557f [file] [log] [blame]
Matteo Scandolo3e765d52018-05-14 15:22:23 -07001#!/usr/bin/env bash
2#
3# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17###########################################################
18# #
19# Tags and push all the local images to a docker-registry #
20# #
21###########################################################
22
23#
24# Displays the help menu.
25#
26display_help () {
Luca Prete284d7642018-05-24 15:19:43 -070027 echo "Tags and pushes to a remote registry all the images present in the local docker registry." >&2
28 echo " "
Matteo Scandolo3e765d52018-05-14 15:22:23 -070029 echo "Usage: $0 {--push|--help} [docker-registry] [tag=candidate] " >&2
30 echo " "
Luca Prete284d7642018-05-24 15:19:43 -070031 echo " -h, --help Displays this help message."
32 echo " -r, --registry Tags and pushes all the local docker images to the remote <docker-registry>"
Matteo Scandolo3e765d52018-05-14 15:22:23 -070033 echo " "
34 echo " docker-registry The address of the registry"
35 echo " tag The tag to be used"
36 echo " "
37 echo "Example usages:"
38 echo " ./tag_and_push.sh -r 192.168.10.100:30500"
39 echo " ./tag_and_push.sh -r 192.168.10.100:30500 devel"
40}
41
42#
43# Tag and push all the locally available docker images
44#
45tag_and_push () {
46 echo "Pushing images to $DOCKER_REGISTRY with tag $DOCKER_TAG"
47 echo " "
48
49 # reading docker images
Matteo Scandolo5c75c902018-06-15 13:11:50 -070050 DOCKER_IMAGES=$(docker images --format="{{.Repository}}:{{.Tag}}" --filter "dangling=false" | grep -v none | grep "xosproject")
Matteo Scandolo3e765d52018-05-14 15:22:23 -070051
Zack Williams249ac7f2018-05-18 13:34:14 -070052 # split string to list only on newlines
53 IFS=$'\n'
54 for image in $DOCKER_IMAGES;
Matteo Scandolo3e765d52018-05-14 15:22:23 -070055 do
Matteo Scandolo5c75c902018-06-15 13:11:50 -070056 echo "Tagging $image with $DOCKER_REGISTRY/$image"
57 docker tag "$image" "$DOCKER_REGISTRY/$image"
Zack Williams249ac7f2018-05-18 13:34:14 -070058 docker push "$DOCKER_REGISTRY/$image"
Matteo Scandolo3e765d52018-05-14 15:22:23 -070059 done
60}
61
62#
63# Init
64#
65CLI_OPT=$1
66DOCKER_REGISTRY=$2
67DOCKER_TAG=${3:-"candidate"}
68
69while :
70do
71 case $CLI_OPT in
72 -r | --registry)
73 tag_and_push
74 exit 0
75 ;;
76 -h | --help)
77 display_help
78 exit 0
79 ;;
80 --) # End of all options
81 shift
82 break
83 ;;
84 *)
Zack Williams249ac7f2018-05-18 13:34:14 -070085 echo Error: Unknown option: "$CLI_OPT" >&2
Matteo Scandolo3e765d52018-05-14 15:22:23 -070086 echo " "
87 display_help
88 exit -1
89 ;;
90 esac
Zack Williams249ac7f2018-05-18 13:34:14 -070091done