Builds and archives uds artifacts
[infra/cicd.git] / jjb / onap / uds / scripts / archive-images.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2020 The Nordix Foundation. All rights reserved.
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 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 set -o errexit
21 set -o nounset
22 set -o pipefail
23
24 # Make directory to hold docker image artifacts
25 mkdir -p $DOCKER_IMAGE_ARTIFACT_DIRECTORY
26
27 # Ensure at root of WORKSPACE
28 cd $WORKSPACE
29
30 # For each docker image
31 for DOCKER_IMAGE in $(echo $DOCKER_IMAGES | tr "," "\n")
32 do
33   echo "----------------------------------------------------"
34   echo "Info: Archiving $DOCKER_IMAGE"
35   echo "----------------------------------------------------"
36   # Generate a name for the archive from its docker image name
37   # e.g.  uds/sdc-customization/eo-cassandra-init becomes eo-cassandra-init
38   DOCKER_IMAGE_TAG=$(docker images $DOCKER_IMAGE | awk '{ print $2}' | sed -n '2p')
39   # Create docker tag for filename using uds build version e.g. 1.5-STAGING-latest
40   DOCKER_IMAGE_NAME=$(echo $DOCKER_IMAGE | awk -F/ '{print $NF}')
41   # Create docker tag for filename using timestamp e.g. 1.5.0-20200610T134812Z
42   #DOCKER_IMAGE_TAG=$(docker images $DOCKER_IMAGE | awk '{ print $2}' | sed -n '3p')
43
44   # Create the archive.tar.gz
45   # Naming convention <docker-image-name>-<tag>-<project-commit-ids>.tar.gz
46   # Includes SHA commit ids of the projects for traceability of the artifacts
47   # e.g. eo-cassandra-init-1.7-STAGING-latest-6d3abef-d96bad4.tar.gz
48   docker save $DOCKER_IMAGE | gzip -c > $DOCKER_IMAGE_ARTIFACT_DIRECTORY/$DOCKER_IMAGE_NAME-$DOCKER_IMAGE_TAG-$COMMIT_IDS.tar.gz
49 done