blob: a0a4488db1d779b30e295af57ca294e57dc8ab7f [file] [log] [blame]
Zack Williams8bef3022018-09-18 13:35:09 -07001#!/usr/bin/env bash
2#
3# Copyright 2018-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# update_xos_docker.sh
18# Updates docker FROM lines of synchronizers and xos core, when XOS is updated,
19# and the synchronizer has the same parent SemVer major version
20#
21# Before using this, update XOS version in orchestration/xos/VERSION file
22#
23# After running script, `repo diff` will show the updated files.
24#
Zack Williamse30388f2018-09-27 07:06:35 -070025# To undo changes: `repo forall -c "git checkout *Dockerfile*"`
Zack Williams8bef3022018-09-18 13:35:09 -070026
27set -eu -o pipefail
28
29WORKSPACE=${WORKSPACE:-../../..}
30
Zack Williamse30388f2018-09-27 07:06:35 -070031NEW_COMMIT=${NEW_COMMIT:0}
32
Zack Williams8bef3022018-09-18 13:35:09 -070033XOS_MAJOR=$(cut -b 1 "${WORKSPACE}/cord/orchestration/xos/VERSION")
34
35XOS_VERSION=$(cat "${WORKSPACE}/cord/orchestration/xos/VERSION")
36
37# Update Synchronizer FROM parent versions
38for df in ${WORKSPACE}/cord/orchestration/xos_services/*/Dockerfile.synchronizer \
39 ${WORKSPACE}/cord/orchestration/profiles/*/Dockerfile.synchronizer
40do
41 df_contents=$(cat "$df")
42
43 # shellcheck disable=SC2076
44 if [[ "$df_contents" =~ "FROM xosproject/xos-synchronizer-base:${XOS_MAJOR}" ||
45 "$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
46 then
Zack Williamse30388f2018-09-27 07:06:35 -070047 pushd "$(dirname "$df")"
48
Zack Williams8bef3022018-09-18 13:35:09 -070049 echo "Updating synchronizer Dockerfile: ${df}"
Zack Williamse30388f2018-09-27 07:06:35 -070050
51 perl -pi -e "s/^FROM(.*):.*$/FROM\\1:$XOS_VERSION/" Dockerfile.synchronizer
52
53 # if NEW_COMMIT is nonzero, create a new GIT commit with these changes
54 if $NEW_COMMIT
55 then
56 # check if previous version is semver for patch version bump
57 OLD_VERSION=$(head -n1 "VERSION")
58 if [[ "$OLD_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
59 then
60 repo start "bump$XOS_VERSION"
61
62 # Increment patch by 1
63 perl -pi -e 's/(\d+)$/ 1 + $1/ge' VERSION
64
65 git add VERSION Dockerfile.synchronizer
66
67 git commit -m "Updated service to use new XOS core version: $XOS_VERSION"
68 else
69 echo "This service isn't on a released version, manual intervention required"
70 fi
71 fi
72
73 popd
Zack Williams8bef3022018-09-18 13:35:09 -070074 fi
75done
76
77# Update XOS parent versions
78for df in ${WORKSPACE}/cord/orchestration/xos/containers/*/Dockerfile* \
79 ${WORKSPACE}/cord/orchestration/xos-tosca/Dockerfile
80do
81 echo "Updating core Dockerfile: ${df}"
Zack Williamse30388f2018-09-27 07:06:35 -070082 perl -pi -e "s/^FROM xos(.*):.*$/FROM xos\\1:$XOS_VERSION/" "$df"
Zack Williams8bef3022018-09-18 13:35:09 -070083done