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 |
Zack Williams | f0b8e94 | 2019-07-23 16:21:28 -0700 | [diff] [blame] | 38 | for df in "${WORKSPACE}"/cord/orchestration/xos_services/*/Dockerfile.synchronizer |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 39 | do |
| 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 Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 46 | pushd "$(dirname "$df")" |
| 47 | |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 48 | echo "Updating synchronizer Dockerfile: ${df}" |
Zack Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 49 | |
| 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 Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 73 | fi |
| 74 | done |
| 75 | |
| 76 | # Update XOS parent versions |
Zack Williams | f0b8e94 | 2019-07-23 16:21:28 -0700 | [diff] [blame] | 77 | for df in "${WORKSPACE}"/cord/orchestration/xos/containers/*/Dockerfile* \ |
| 78 | "${WORKSPACE}/cord/orchestration/xos-tosca/Dockerfile" |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 79 | do |
| 80 | echo "Updating core Dockerfile: ${df}" |
Zack Williams | e30388f | 2018-09-27 07:06:35 -0700 | [diff] [blame] | 81 | perl -pi -e "s/^FROM xos(.*):.*$/FROM xos\\1:$XOS_VERSION/" "$df" |
Zack Williams | 8bef302 | 2018-09-18 13:35:09 -0700 | [diff] [blame] | 82 | done |