Matteo Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 1 | #!/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 | # |
| 26 | display_help () { |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 27 | 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 Prete | 284d764 | 2018-05-24 15:19:43 -0700 | [diff] [blame] | 29 | echo " " |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 30 | echo "Usage: $0 [filter] [docker-registry] " |
Matteo Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 31 | echo " " |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 32 | echo " filter A string used to filter the images (used as 'grep -E \"^$FILTER\"')" |
Matteo Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 33 | echo " docker-registry The address of the registry" |
Matteo Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 34 | echo " " |
| 35 | echo "Example usages:" |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 36 | 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 Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | # |
| 42 | # Tag and push all the locally available docker images |
| 43 | # |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 44 | FILTER=$1 |
| 45 | REGISTRY=$2 |
Matteo Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 46 | |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 47 | if [ "$FILTER" == "-h" ]; then |
| 48 | display_help |
| 49 | else |
| 50 | echo "REGISTRY: $REGISTRY" |
| 51 | echo "FILTER: $FILTER" |
| 52 | if [ "$FILTER" != "" ]; then |
Matteo Scandolo | e49a000 | 2018-10-09 10:38:31 -0700 | [diff] [blame] | 53 | images=$(docker images | grep -E "$FILTER" | grep -v "$REGISTRY" | awk '{if (NR!=1) {print}}' | awk '{ a=$1":"$2; print a }') |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 54 | else |
Matteo Scandolo | e49a000 | 2018-10-09 10:38:31 -0700 | [diff] [blame] | 55 | # NOTE I don't this is ever used |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 56 | images=$(docker images | awk '{if (NR!=1) {print}}' | awk '{ a=$1":"$2; print a }') |
| 57 | fi |
Matteo Scandolo | e49a000 | 2018-10-09 10:38:31 -0700 | [diff] [blame] | 58 | echo "Tagging Images:" |
| 59 | echo "$images" |
| 60 | echo " " |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 61 | for i in $images; do |
| 62 | if [ "$REGISTRY" != "" ]; then |
| 63 | docker tag "$i" "$REGISTRY/$i" |
| 64 | docker push "$REGISTRY/$i" |
| 65 | else |
| 66 | docker push "$i" |
| 67 | fi |
Matteo Scandolo | 3e765d5 | 2018-05-14 15:22:23 -0700 | [diff] [blame] | 68 | done |
Matteo Scandolo | 9ab700e | 2018-09-20 16:56:16 -0700 | [diff] [blame] | 69 | fi |