| tierno | 7d782ef | 2019-10-04 12:56:31 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | # |
| 16 | # For those usages not covered by the Apache License, Version 2.0 please |
| 17 | # contact with: nfvlabs@tid.es |
| 18 | ## |
| 19 | |
| 20 | # Generates the debian packages; and then generates a docker image base on Dockerfile-devops and update a |
| 21 | # running docker stack with the generated image |
| 22 | |
| 23 | HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]})) |
| 24 | export RO_BASE=$(dirname $HERE) |
| 25 | |
| 26 | # clean |
| 27 | docker rm -f ro_pkg 2>/dev/null && echo docker ro_pkg removed |
| 28 | rm -rf $HERE/temp/* |
| tierno | 57dadcf | 2019-11-23 15:11:15 +0000 | [diff] [blame] | 29 | find $RO_BASE -name "*.pyc" -exec rm {} ";" |
| tierno | 7d782ef | 2019-10-04 12:56:31 +0000 | [diff] [blame] | 30 | mkdir -p $HERE/temp |
| 31 | |
| 32 | echo -e "\n\n[STAGE 1] Builind dockerfile userd for the package generation" |
| 33 | docker build $RO_BASE -f $RO_BASE/Dockerfile -t opensourcemano/ro_pkg |
| 34 | sleep 2 |
| 35 | |
| 36 | echo "[STAGE 1.1] Generting packages inside docker ro_pkg" |
| 37 | docker run -d --name ro_pkg opensourcemano/ro_pkg bash -c 'sleep 3600' |
| 38 | docker cp $RO_BASE ro_pkg:/RO |
| 39 | docker exec ro_pkg bash -c 'cd /RO; ./devops-stages/stage-build.sh' |
| 40 | deb_files=`docker exec ro_pkg bash -c 'ls /RO/deb_dist/'` |
| 41 | [ -z "$deb_files" ] && echo "No packages generated" >&2 && exit 1 |
| 42 | echo $deb_files |
| 43 | |
| 44 | echo -e "\n\n[STAGE 1.2] Print package information and copy to '$HERE/temp/'" |
| 45 | # print package information and copy to "$HERE/temp/" |
| 46 | for deb_file in $deb_files ; do |
| 47 | echo; echo; echo |
| 48 | echo $deb_file info: |
| 49 | echo "===========================" |
| 50 | docker cp ro_pkg:/RO/deb_dist/$deb_file $HERE/temp/ |
| 51 | dpkg -I $HERE/temp/$(basename $deb_file) |
| 52 | done |
| 53 | |
| 54 | # docker rm -f ro_pkg |
| 55 | echo -e "\n\n[STAGE 2] Building docker image opensourcemano/ro:py3_devops based on debian packages" |
| 56 | docker build $HERE -f $HERE/Dockerfile-devops -t opensourcemano/ro:py3_devops || |
| 57 | ! echo "error generating devops dockerfile" >&2 || exit 1 |
| 58 | sleep 2 |
| 59 | # docker run -d --name ro_devops opensourcemano/ro:py3_devops |
| 60 | # docker run -ti exec ro_devops ro tenant-list || ! echo "Cannot exec ro client to get server tenants" >&2 || exit 1 |
| 61 | |
| 62 | echo -e "\n\n[STAGE 3] Update service osm_ro with generated docker image" |
| 63 | docker service update osm_ro --force --image opensourcemano/ro:py3_devops |
| 64 | sleep 2 |
| 65 | docker container prune -f |
| 66 | docker service logs osm_ro |