Script to update XOS parent versions
Change-Id: I96b98c7f0f91eee601d3531a859f9de335778f12
diff --git a/developer/update_xos_docker.sh b/developer/update_xos_docker.sh
new file mode 100755
index 0000000..dc4048c
--- /dev/null
+++ b/developer/update_xos_docker.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+#
+# Copyright 2018-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# update_xos_docker.sh
+# Updates docker FROM lines of synchronizers and xos core, when XOS is updated,
+# and the synchronizer has the same parent SemVer major version
+#
+# Before using this, update XOS version in orchestration/xos/VERSION file
+#
+# After running script, `repo diff` will show the updated files.
+#
+# To undo changes: `repo forall -c git checkout *Dockerfile*`
+
+set -eu -o pipefail
+
+WORKSPACE=${WORKSPACE:-../../..}
+
+XOS_MAJOR=$(cut -b 1 "${WORKSPACE}/cord/orchestration/xos/VERSION")
+
+XOS_VERSION=$(cat "${WORKSPACE}/cord/orchestration/xos/VERSION")
+
+# Update Synchronizer FROM parent versions
+for df in ${WORKSPACE}/cord/orchestration/xos_services/*/Dockerfile.synchronizer \
+ ${WORKSPACE}/cord/orchestration/profiles/*/Dockerfile.synchronizer
+do
+ df_contents=$(cat "$df")
+
+ # shellcheck disable=SC2076
+ if [[ "$df_contents" =~ "FROM xosproject/xos-synchronizer-base:${XOS_MAJOR}" ||
+ "$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
+ then
+ echo "Updating synchronizer Dockerfile: ${df}"
+ sed -i -- "s/^FROM\\(.*\\):.*$/FROM\\1:$XOS_VERSION/" "$df"
+ fi
+done
+
+# Update XOS parent versions
+for df in ${WORKSPACE}/cord/orchestration/xos/containers/*/Dockerfile* \
+ ${WORKSPACE}/cord/orchestration/xos-tosca/Dockerfile
+do
+ echo "Updating core Dockerfile: ${df}"
+ sed -i -- "s/^FROM xos\\(.*\\):.*$/FROM xos\\1:$XOS_VERSION/" "$df"
+done