Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 1 | #!/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 Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 25 | # To undo changes: `repo forall -c "git checkout *Dockerfile*"` |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 26 | |
| 27 | set -eu -o pipefail |
| 28 | |
| 29 | WORKSPACE=${WORKSPACE:-../../..} |
| 30 | |
Zack Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 31 | NEW_COMMIT=${NEW_COMMIT:0} |
| 32 | |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 33 | XOS_MAJOR=$(cut -b 1 "${WORKSPACE}/cord/orchestration/xos/VERSION") |
| 34 | |
| 35 | XOS_VERSION=$(cat "${WORKSPACE}/cord/orchestration/xos/VERSION") |
| 36 | |
| 37 | # Update Synchronizer FROM parent versions |
| 38 | for df in ${WORKSPACE}/cord/orchestration/xos_services/*/Dockerfile.synchronizer \ |
| 39 | ${WORKSPACE}/cord/orchestration/profiles/*/Dockerfile.synchronizer |
| 40 | do |
| 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 Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 47 | pushd "$(dirname "$df")" |
| 48 | |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 49 | echo "Updating synchronizer Dockerfile: ${df}" |
Zack Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 50 | |
| 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 Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 74 | fi |
| 75 | done |
| 76 | |
| 77 | # Update XOS parent versions |
| 78 | for df in ${WORKSPACE}/cord/orchestration/xos/containers/*/Dockerfile* \ |
| 79 | ${WORKSPACE}/cord/orchestration/xos-tosca/Dockerfile |
| 80 | do |
| 81 | echo "Updating core Dockerfile: ${df}" |
Zack Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 82 | perl -pi -e "s/^FROM xos(.*):.*$/FROM xos\\1:$XOS_VERSION/" "$df" |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 83 | done |