blob: f3c007e85482f3f5e2e69d08f5a4594ece5e5d31 [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 () {
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070027 echo "Tags and pushes to a remote registry all the images present in the local docker registry."
28 echo "Note that this script won't change the tag on the container"
Luca Prete284d7642018-05-24 15:19:43 -070029 echo " "
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070030 echo "Usage: $0 [filter] [docker-registry] "
Matteo Scandolo3e765d52018-05-14 15:22:23 -070031 echo " "
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070032 echo " filter A string used to filter the images (used as 'grep -E \"^$FILTER\"')"
Matteo Scandolo3e765d52018-05-14 15:22:23 -070033 echo " docker-registry The address of the registry"
Matteo Scandolo3e765d52018-05-14 15:22:23 -070034 echo " "
35 echo "Example usages:"
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070036 echo " ./tag_and_push.sh xosproject 192.168.10.100:30500" # tag all the xosproject images and push them to the registry
37 echo " ./tag_and_push.sh . 192.168.10.100:30500" # tag all the images and push them to the registry
38 echo " ./tag_and_push.sh xosproject" # push the xosproject images to dockerhub
Matteo Scandolo3e765d52018-05-14 15:22:23 -070039}
40
41#
42# Tag and push all the locally available docker images
43#
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070044FILTER=$1
45REGISTRY=$2
Matteo Scandolo3e765d52018-05-14 15:22:23 -070046
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070047if [ "$FILTER" == "-h" ]; then
48 display_help
49else
50 echo "REGISTRY: $REGISTRY"
51 echo "FILTER: $FILTER"
52 if [ "$FILTER" != "" ]; then
53 images=$(docker images | awk '{if (NR!=1) {print}}' | grep -E "^$FILTER" | awk '{ a=$1":"$2; print a }')
54 else
55 images=$(docker images | awk '{if (NR!=1) {print}}' | awk '{ a=$1":"$2; print a }')
56 fi
57 for i in $images; do
58 if [ "$REGISTRY" != "" ]; then
59 docker tag "$i" "$REGISTRY/$i"
60 docker push "$REGISTRY/$i"
61 else
62 docker push "$i"
63 fi
Matteo Scandolo3e765d52018-05-14 15:22:23 -070064 done
Matteo Scandolo9ab700e2018-09-20 16:56:16 -070065fi