| garciadeblas | 90344b6 | 2024-08-20 16:28:12 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ####################################################################################### |
| 3 | # Copyright ETSI Contributors and Others. |
| 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 |
| 14 | # implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | ####################################################################################### |
| 18 | |
| garciadeblas | d227272 | 2024-09-11 14:35:35 +0200 | [diff] [blame] | 19 | if [ $# -ne 2 ]; then |
| garciadeblas | 90344b6 | 2024-08-20 16:28:12 +0200 | [diff] [blame] | 20 | echo "Usage $0 <module> <tag_number>" |
| garciadeblas | 09b4b24 | 2024-09-25 16:36:24 +0200 | [diff] [blame^] | 21 | echo " Example: $0 ro 2" |
| 22 | echo " Will import image in containerd local registry as opensourcemano/ro:devel-2" |
| 23 | echo " Example: $0 lcm 5" |
| 24 | echo " Will import image in containerd local registry as opensourcemano/lcm:devel-5" |
| 25 | echo " Example: $0 osm-krm-functions 24h" |
| 26 | echo " (when tag_number is '[0-9]+h') Will push the image to ttl.sh/osm-krm-functions-devel:24h" |
| garciadeblas | 90344b6 | 2024-08-20 16:28:12 +0200 | [diff] [blame] | 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | MODULE_NAME="$1" |
| 31 | TAG_NUMBER="$2" |
| 32 | |
| 33 | set -x |
| garciadeblas | 09b4b24 | 2024-09-25 16:36:24 +0200 | [diff] [blame^] | 34 | |
| 35 | if [[ "${TAG_NUMBER}" =~ ^[0-9]+h$ ]]; then |
| 36 | IMAGE_NAME="ttl.sh/${MODULE_NAME}-devel:${TAG_NUMBER}" |
| 37 | docker tag opensourcemano/${MODULE_NAME}:devel ${IMAGE_NAME} |
| 38 | docker push ${IMAGE_NAME} |
| 39 | exit 0 |
| 40 | else |
| 41 | echo "Image will be imported locally" |
| 42 | fi |
| 43 | |
| garciadeblas | 90344b6 | 2024-08-20 16:28:12 +0200 | [diff] [blame] | 44 | IMAGE_NAME="opensourcemano/${MODULE_NAME}:devel-${TAG_NUMBER}" |
| 45 | docker tag opensourcemano/${MODULE_NAME}:devel ${IMAGE_NAME} |
| 46 | IMAGE_FILE="${MODULE_NAME}-devel-${TAG_NUMBER}.tar.gz" |
| 47 | docker save -o ${IMAGE_FILE} ${IMAGE_NAME} |
| 48 | sudo ctr -n=k8s.io images import ${IMAGE_FILE} |
| 49 | rm ${IMAGE_FILE} |
| 50 | sudo ctr -n=k8s.io images list |grep ${IMAGE_NAME} |
| 51 | echo $IMAGE_NAME |
| 52 | kubectl -n osm patch deployment ${MODULE_NAME} --patch '{"spec": {"template": {"spec": {"containers": [{"name": "'${MODULE_NAME}'", "image": "'${IMAGE_NAME}'"}]}}}}' |
| 53 | kubectl -n osm rollout restart deployment ${MODULE_NAME} |
| 54 | |