enable logging to stdout and log file
[yaml_builds.git] / tools / deploy_site.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.        #
4 #                                                                            #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may    #
6 # not use this file except in compliance with the License.                   #
7 #                                                                            #
8 # You may obtain a copy of the License at                                    #
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, WITHOUT  #
13 # 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
18
19 set -x
20 TIMESTAMP=$(date +"%Y%m%d%H%M")
21 LOGFILE=/var/log/deploy_site_$TIMESTAMP.log
22 echo "logging to $LOGFILE"
23 exec 1> >(tee -a $LOGFILE)
24 exec 2>&1
25
26 # Regional Server specific variables
27 KEYSTONE_IMAGE=
28 SHIPYARD_IMAGE=
29 # Site specific variables
30 DRYDOCK_PASSWORD=
31 SHIPYARD_PASSWORD=
32 REGION_NAME=
33
34
35 clean_configdocs(){
36   ## clean site YAMLs from Deckhand
37   TOKEN=`sudo docker run --rm --net=host -e OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3 -e OS_PROJECT_DOMAIN_NAME=default -e OS_USER_DOMAIN_NAME=default -e OS_PROJECT_NAME=service -e OS_REGION_NAME=RegionOne -e OS_USERNAME=drydock -e OS_PASSWORD=${DRYDOCK_PASSWORD} -e OS_IDENTITY_API_VERSION=3 ${KEYSTONE_IMAGE} openstack token issue -f value -c id`
38
39   curl -v -X DELETE -H "X-AUTH-TOKEN: $TOKEN" -H 'Content-Type: application/x-yaml' http://deckhand-int.ucp.svc.cluster.local:9000/api/v1.0/revisions
40 }
41
42 create_configdocs(){
43   sudo docker run -v $(pwd):/target -e 'OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3' -e OS_PASSWORD=${SHIPYARD_PASSWORD} -e 'OS_PROJECT_DOMAIN_NAME=default' -e 'OS_PROJECT_NAME=service' -e 'OS_USERNAME=shipyard' -e 'OS_USER_DOMAIN_NAME=default' -e 'OS_IDENTITY_API_VERSION=3' --rm --net=host ${SHIPYARD_IMAGE} create configdocs ${REGION_NAME} --directory=/target/configs/promenade
44
45   sleep 5
46 }
47
48 renderedconfigdocs(){
49   sudo docker run -v $(pwd):/target -e 'OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3' -e OS_PASSWORD=${SHIPYARD_PASSWORD} -e 'OS_PROJECT_DOMAIN_NAME=default' -e 'OS_PROJECT_NAME=service' -e 'OS_USERNAME=shipyard' -e 'OS_USER_DOMAIN_NAME=default' -e 'OS_IDENTITY_API_VERSION=3' --rm --net=host ${SHIPYARD_IMAGE} get renderedconfigdocs --committed > /tmp/renderedconfigdocs.yaml
50
51   sleep 5
52 }
53
54 commit_configdocs(){
55   sudo docker run -v $(pwd):/target -e 'OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3' -e OS_PASSWORD=${SHIPYARD_PASSWORD} -e 'OS_PROJECT_DOMAIN_NAME=default' -e 'OS_PROJECT_NAME=service' -e 'OS_USERNAME=shipyard' -e 'OS_USER_DOMAIN_NAME=default' -e 'OS_IDENTITY_API_VERSION=3' --rm --net=host ${SHIPYARD_IMAGE} commit configdocs
56
57   sleep 5
58 }
59
60 deploy_site(){
61   sudo docker run -e 'OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3' -e OS_PASSWORD=${SHIPYARD_PASSWORD} -e 'OS_PROJECT_DOMAIN_NAME=default' -e 'OS_PROJECT_NAME=service' -e 'OS_USERNAME=shipyard' -e 'OS_USER_DOMAIN_NAME=default' -e 'OS_IDENTITY_API_VERSION=3' --rm --net=host ${SHIPYARD_IMAGE} create action deploy_site
62 }
63
64 update_site(){
65   sudo docker run -e 'OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3' -e OS_PASSWORD=${SHIPYARD_PASSWORD} -e 'OS_PROJECT_DOMAIN_NAME=default' -e 'OS_PROJECT_NAME=service' -e 'OS_USERNAME=shipyard' -e 'OS_USER_DOMAIN_NAME=default' -e 'OS_IDENTITY_API_VERSION=3' --rm --net=host ${SHIPYARD_IMAGE} create action update_site
66 }
67
68
69 getactions(){
70   sudo docker run -v $(pwd):/target -e 'OS_AUTH_URL=http://keystone-api.ucp.svc.cluster.local:80/v3' -e OS_PASSWORD=${SHIPYARD_PASSWORD} -e 'OS_PROJECT_DOMAIN_NAME=default' -e 'OS_PROJECT_NAME=service' -e 'OS_USERNAME=shipyard' -e 'OS_USER_DOMAIN_NAME=default' -e 'OS_IDENTITY_API_VERSION=3' --rm --net=host ${SHIPYARD_IMAGE} get actions
71
72   sleep 5
73 }
74
75 sleep 900
76 clean_configdocs
77 create_configdocs
78 commit_configdocs
79 renderedconfigdocs
80
81 deploy_site
82 #getactions
83 #update_site
84
85 echo "## Airship deployment has been started..."
86 echo "##"
87 echo "## To monitor progress check:"
88 echo "## MaaS GUI    -> http://{{yaml.genesis.host}}:30001/MAAS/#/nodes"
89 echo "## Airflow GUI -> http://{{yaml.genesis.host}}:30004/admin/taskinstance/"
90
91 exec 2>&-
92 exec 1>&-
93 exit 0
94