blob: 6fa21466b3f0f01872f556c31de95acd61baec0f [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
Matteo Scandolo3f9134b2019-02-14 08:08:51 -080038for df in ${WORKSPACE}/cord/orchestration/xos_services/*/Dockerfile.synchronizer
Zack Williams8bef3022018-09-18 13:35:09 -070039do
40 df_contents=$(cat "$df")
41
42 # shellcheck disable=SC2076
43 if [[ "$df_contents" =~ "FROM xosproject/xos-synchronizer-base:${XOS_MAJOR}" ||
44 "$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
45 then
Zack Williamse30388f2018-09-27 07:06:35 -070046 pushd "$(dirname "$df")"
47
Zack Williams8bef3022018-09-18 13:35:09 -070048 echo "Updating synchronizer Dockerfile: ${df}"
Zack Williamse30388f2018-09-27 07:06:35 -070049
50 perl -pi -e "s/^FROM(.*):.*$/FROM\\1:$XOS_VERSION/" Dockerfile.synchronizer
51
52 # if NEW_COMMIT is nonzero, create a new GIT commit with these changes
53 if $NEW_COMMIT
54 then
55 # check if previous version is semver for patch version bump
56 OLD_VERSION=$(head -n1 "VERSION")
57 if [[ "$OLD_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
58 then
59 repo start "bump$XOS_VERSION"
60
61 # Increment patch by 1
62 perl -pi -e 's/(\d+)$/ 1 + $1/ge' VERSION
63
64 git add VERSION Dockerfile.synchronizer
65
66 git commit -m "Updated service to use new XOS core version: $XOS_VERSION"
67 else
68 echo "This service isn't on a released version, manual intervention required"
69 fi
70 fi
71
72 popd
Zack Williams8bef3022018-09-18 13:35:09 -070073 fi
74done
75
76# Update XOS parent versions
77for df in ${WORKSPACE}/cord/orchestration/xos/containers/*/Dockerfile* \
78 ${WORKSPACE}/cord/orchestration/xos-tosca/Dockerfile
79do
80 echo "Updating core Dockerfile: ${df}"
Zack Williamse30388f2018-09-27 07:06:35 -070081 perl -pi -e "s/^FROM xos(.*):.*$/FROM xos\\1:$XOS_VERSION/" "$df"
Zack Williams8bef3022018-09-18 13:35:09 -070082done