Reference Airship manifests, CICD, and reference architecture.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

431 lines
14 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright 2018 AT&T Intellectual Property. All other rights reserved.
  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. # #
  18. # Set up and deploy an Airship environment for development/testing purposes. #
  19. # Many of the defaults and sources used here are NOT production ready, and #
  20. # this should not be used as a copy/paste source for any production use. #
  21. # #
  22. ###############################################################################
  23. set -x
  24. # The last step to run through in this script. Valid Values are "collect",
  25. # "genesis", "deploy", and "demo". By default this will run through to the end
  26. # of the genesis steps
  27. LAST_STEP_NAME=${1:-"genesis"}
  28. if [[ ${LAST_STEP_NAME} == "collect" ]]; then
  29. STEP_BREAKPOINT=10
  30. elif [[ ${LAST_STEP_NAME} == "genesis" ]]; then
  31. STEP_BREAKPOINT=20
  32. elif [[ ${LAST_STEP_NAME} == "deploy" ]]; then
  33. STEP_BREAKPOINT=30
  34. elif [[ ${LAST_STEP_NAME} == "demo" ]]; then
  35. STEP_BREAKPOINT=40
  36. else
  37. STEP_BREAKPOINT=20
  38. fi
  39. # The directory of the repo where current script is located.
  40. REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../../../../ >/dev/null 2>&1 && pwd )"
  41. # The directory that will contain the copies of designs and repos from this
  42. # script. By default it is a directory where the repository is cloned.
  43. export WORKSPACE=${WORKSPACE:-"${REPO_DIR}/../"}
  44. # The site to deploy
  45. TARGET_SITE=${TARGET_SITE:-"aiab"}
  46. # Setup blank defaults for proxy variables
  47. http_proxy=${http_proxy:-""}
  48. https_proxy=${https_proxy:-""}
  49. no_proxy=${no_proxy:-""}
  50. # The host name for the single-node deployment. e.g.: 'genesis'
  51. SHORT_HOSTNAME=${SHORT_HOSTNAME:-""}
  52. # The host ip for this single-node deployment. e.g.: '10.0.0.9'
  53. HOSTIP=${HOSTIP:-""}
  54. # The cidr for the network for the host. e.g.: '10.0.0.0/24'
  55. HOSTCIDR=${HOSTCIDR:-""}
  56. # The interface on the host/genesis node. e.g.: 'ens3'
  57. NODE_NET_IFACE=${NODE_NET_IFACE:-""}
  58. # Allowance for Genesis/Armada to settle in seconds:
  59. POST_GENESIS_DELAY=${POST_GENESIS_DELAY:-60}
  60. # Command shortcuts
  61. PEGLEG="${REPO_DIR}/tools/airship pegleg"
  62. SHIPYARD="${REPO_DIR}/tools/airship shipyard"
  63. PROMENADE="${REPO_DIR}/tools/airship promenade"
  64. function check_preconditions() {
  65. set +x
  66. fail=false
  67. if ! [ $(id -u) = 0 ] ; then
  68. echo "Please execute this script as root!"
  69. fail=true
  70. fi
  71. if [ -z ${HOSTIP} ] ; then
  72. echo "The HOSTIP variable must be set. E.g. 10.0.0.9"
  73. fail=true
  74. fi
  75. if [ -z ${SHORT_HOSTNAME} ] ; then
  76. echo "The SHORT_HOSTNAME variable must be set. E.g. testvm1"
  77. fail=true
  78. fi
  79. if [ -z ${HOSTCIDR} ] ; then
  80. echo "The HOSTCIDR variable must be set. E.g. 10.0.0.0/24"
  81. fail=true
  82. fi
  83. if [ -z ${NODE_NET_IFACE} ] ; then
  84. echo "The NODE_NET_IFACE variable must be set. E.g. ens3"
  85. fail=true
  86. fi
  87. if [[ -z $(grep $SHORT_HOSTNAME /etc/hosts | grep $HOSTIP) ]]
  88. then
  89. echo "No /etc/hosts entry found for $SHORT_HOSTNAME. Please add one."
  90. fail=true
  91. fi
  92. if [ $fail = true ] ; then
  93. echo "Preconditions failed"
  94. exit 1
  95. fi
  96. set -x
  97. }
  98. function setup_workspace() {
  99. # Setup workspace directories
  100. mkdir -p ${WORKSPACE}/collected
  101. mkdir -p ${WORKSPACE}/genesis
  102. # Open permissions for output from Promenade
  103. chmod -R 777 ${WORKSPACE}/genesis
  104. }
  105. function configure_docker() {
  106. if [[ ! -z "${https_proxy}" ]] || [[ ! -z "${http_proxy}" ]]
  107. then
  108. echo "Configuring Docker to use a proxy..."
  109. mkdir -p /etc/systemd/system/docker.service.d/
  110. cat << EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
  111. [Service]
  112. Environment="HTTP_PROXY=${http_proxy}"
  113. Environment="HTTPS_PROXY=${https_proxy}"
  114. Environment="NO_PROXY=${no_proxy}"
  115. EOF
  116. systemctl daemon-reload
  117. systemctl restart docker
  118. fi
  119. }
  120. function configure_apt() {
  121. if [[ ! -z "${https_proxy}" ]] || [[ ! -z "${http_proxy}" ]]
  122. then
  123. echo "Configuring apt to use a proxy..."
  124. mkdir -p /etc/apt/
  125. cat << EOF > /etc/apt/apt.conf
  126. Acquire::http::proxy "${http_proxy}";
  127. Acquire::https::proxy "${https_proxy}";
  128. EOF
  129. fi
  130. }
  131. function configure_dev_configurables() {
  132. cat << EOF >> ${WORKSPACE}/treasuremap/site/${TARGET_SITE}/deployment/dev-configurables.yaml
  133. data:
  134. hostname: ${SHORT_HOSTNAME}
  135. hostip: ${HOSTIP}
  136. hostcidr: ${HOSTCIDR}
  137. interface: ${NODE_NET_IFACE}
  138. maas-ingress: '192.169.1.5/32'
  139. EOF
  140. }
  141. function install_dependencies() {
  142. apt -qq update
  143. # Install docker
  144. apt -y install --no-install-recommends docker.io jq nmap nfs-common
  145. }
  146. function run_pegleg_collect() {
  147. # Runs pegleg collect to get the documents combined
  148. pushd ${WORKSPACE}
  149. ${PEGLEG} site -r /target/treasuremap collect ${TARGET_SITE} -s /target/collected
  150. popd
  151. }
  152. function generate_certs() {
  153. # Runs the generation of certs by Promenade and builds bootstrap scripts
  154. # Note: In the really real world, CAs and certs would be provided as part of
  155. # the supplied design. In this dev/test environment, self signed is fine.
  156. # Moves the generated certificates from /genesis to the design, so that a
  157. # Lint can be run
  158. set +x
  159. echo "=== Generating updated certificates ==="
  160. set -x
  161. pushd ${WORKSPACE}
  162. # Copy the collected yamls into the target for the certs
  163. cp collected/*.yaml genesis/
  164. # Generate certificates
  165. ${PROMENADE} generate-certs -o /target/genesis /target/genesis/treasuremap.yaml
  166. # Copy the generated certs back into the deployment_files structure
  167. cp genesis/certificates.yaml treasuremap/site/${TARGET_SITE}/secrets
  168. popd
  169. }
  170. function lint_design() {
  171. # After the certificates are in the deployment files run a pegleg lint
  172. pushd ${WORKSPACE}
  173. ${PEGLEG} site -r /target/treasuremap lint -x P001 ${TARGET_SITE}
  174. popd
  175. }
  176. function generate_genesis() {
  177. # Generate the genesis scripts
  178. pushd ${WORKSPACE}
  179. ${PROMENADE} build-all -o /target/genesis --validators \
  180. /target/genesis/treasuremap.yaml \
  181. /target/genesis/certificates.yaml
  182. popd
  183. }
  184. function run_genesis() {
  185. # Runs the genesis script that was generated
  186. ${WORKSPACE}/genesis/genesis.sh
  187. }
  188. function validate_genesis() {
  189. # Vaidates the genesis deployment
  190. ${WORKSPACE}/genesis/validate-genesis.sh
  191. }
  192. function genesis_complete() {
  193. # Setup kubeconfig
  194. if [ ! -d "$HOME/.kube" ] ; then
  195. mkdir ~/.kube
  196. fi
  197. cp -r /etc/kubernetes/admin/pki ~/.kube/pki
  198. cat /etc/kubernetes/admin/kubeconfig.yaml | sed -e 's/\/etc\/kubernetes\/admin/./' > ~/.kube/config
  199. set +x
  200. echo "-----------"
  201. echo "Waiting ${POST_GENESIS_DELAY} seconds for Genesis process to settle. This is a good time to grab one more coffee :)"
  202. echo "-----------"
  203. sleep ${POST_GENESIS_DELAY}
  204. echo " "
  205. echo "Genesis complete. "
  206. print_shipyard_info1
  207. set -x
  208. }
  209. function print_shipyard_info1() {
  210. SHIPYARD_KEYSTONE_PASS=$(awk '/^data:/ {print $2}' ${WORKSPACE}/treasuremap/site/${TARGET_SITE}/secrets/passphrases/ucp_shipyard_keystone_password.yaml)
  211. set +x
  212. # signals that genesis completed
  213. echo " "
  214. echo "The .yaml files in ${WORKSPACE} contain the site design that may be suitable for use with Shipyard. "
  215. echo "The Shipyard Keystone password ${SHIPYARD_KEYSTONE_PASS} may be found in ${WORKSPACE}/treasuremap/site/${TARGET_SITE}/secrets/passphrases/ucp_shipyard_keystone_password.yaml"
  216. echo " "
  217. set -x
  218. }
  219. function setup_deploy_site() {
  220. # creates a directory /${WORKSPACE}/site with all the things necessary to run
  221. # deploy_site
  222. mkdir -p ${WORKSPACE}/site
  223. cp ${WORKSPACE}/treasuremap/tools/deployment/aiab/common/creds.sh ${WORKSPACE}/site
  224. cp ${WORKSPACE}/genesis/*.yaml ${WORKSPACE}/site
  225. print_shipyard_info2
  226. }
  227. function print_shipyard_info2() {
  228. set +x
  229. echo " "
  230. echo "${WORKSPACE}/site is set up with creds.sh which can be sourced to set up credentials for use in running Shipyard"
  231. echo "${WORKSPACE}/site contains .yaml files that represent the single-node site deployment. (treasuremap.yaml, certificates.yaml)"
  232. echo " "
  233. echo "----------------------------------------------------------------------------------"
  234. echo "The following commands will execute Shipyard to setup and run a deploy_site action"
  235. echo "----------------------------------------------------------------------------------"
  236. echo "cd ${WORKSPACE}/site"
  237. echo "source creds.sh"
  238. echo "${SHIPYARD} create configdocs design --filename=/home/shipyard/host/treasuremap.yaml"
  239. echo "${SHIPYARD} create configdocs secrets --filename=/home/shipyard/host/certificates.yaml --append"
  240. echo "${SHIPYARD} commit configdocs"
  241. echo "${SHIPYARD} create action deploy_site"
  242. echo " "
  243. echo "-----------"
  244. echo "Other Notes"
  245. echo "-----------"
  246. echo "If you need to run Armada directly to deploy charts (fix something broken?), the following may be of use:"
  247. echo "export ARMADA_IMAGE=quay.io/airshipit/armada"
  248. echo "docker run -t -v ~/.kube:/armada/.kube -v ${WORKSPACE}/site:/target --net=host \${ARMADA_IMAGE} apply /target/your-yaml.yaml"
  249. echo " "
  250. set -x
  251. }
  252. function execute_deploy_site() {
  253. set +x
  254. echo " "
  255. echo "This is an automated deployment using Shipyard, running commands noted previously"
  256. echo "Please stand by while Shipyard deploys the site"
  257. echo " "
  258. pushd ${WORKSPACE}/site
  259. source creds.sh
  260. set -x
  261. ${SHIPYARD} create configdocs design --filename=/target/treasuremap.yaml
  262. ${SHIPYARD} create configdocs secrets --filename=/target/certificates.yaml --append
  263. ${SHIPYARD} commit configdocs
  264. ${SHIPYARD} create action deploy_site
  265. ${REPO_DIR}/tools/gate/wait-for-shipyard.sh
  266. popd
  267. }
  268. function execute_create_heat_stack() {
  269. # TODO: (bryan-strassner) prevent this running unless we're running from a
  270. # compatible site defintion that includes OpenStack
  271. set +x
  272. echo " "
  273. echo "Performing basic sanity checks by creating heat stacks"
  274. echo " "
  275. set -x
  276. # Switch to directory where the script is located
  277. pushd ${WORKSPACE}/treasuremap/tools/deployment/aiab/common/
  278. bash test_create_heat_stack.sh
  279. popd
  280. }
  281. function publish_horizon_dashboard() {
  282. kubectl -n openstack expose service/horizon-int --type=NodePort --name=horizon-dashboard
  283. }
  284. function print_dashboards() {
  285. AIRFLOW_PORT=$(kubectl -n ucp get service airflow-web-int -o jsonpath="{.spec.ports[0].nodePort}")
  286. HORIZON_PORT=$(kubectl -n openstack get service horizon-dashboard -o jsonpath="{.spec.ports[0].nodePort}")
  287. MAAS_PORT=$(kubectl -n ucp get service maas-region-ui -o jsonpath="{.spec.ports[0].nodePort}")
  288. MASS_PASS=$(awk '/^data:/ {print $2}' ${WORKSPACE}/treasuremap/site/${TARGET_SITE}/secrets/passphrases/ucp_maas_admin_password.yaml)
  289. set +x
  290. echo " "
  291. echo "OpenStack Horizon dashboard is available on this host at the following URL:"
  292. echo " "
  293. echo " http://${HOSTIP}:${HORIZON_PORT}"
  294. echo " "
  295. # TODO: (roman_g) can we source it from somewhere?
  296. echo "Credentials:"
  297. echo " Domain: default"
  298. echo " Username: admin"
  299. echo " Password: password"
  300. echo " "
  301. echo "OpenStack CLI commands could be launched via \`./openstack\` script, e.g.:"
  302. echo " # cd ${WORKSPACE}/treasuremap/tools/"
  303. echo " # ./openstack stack list"
  304. echo " ..."
  305. echo " "
  306. echo "Other dashboards:"
  307. echo " "
  308. echo " MAAS: http://${HOSTIP}:${MAAS_PORT}/MAAS/ admin/${MASS_PASS}"
  309. echo " Airship Shipyard Airflow DAG: http://${HOSTIP}:${AIRFLOW_PORT}/"
  310. echo " "
  311. echo "Airship itself does not have a dashboard."
  312. echo " "
  313. # TODO: (roman_g) endpoints.yaml path below does not seem to be a reliable location
  314. echo "Other endpoints and credentials are listed in the following locations:"
  315. echo " ${WORKSPACE}/type/sloop/config/endpoints.yaml"
  316. echo " ${WORKSPACE}/treasuremap/site/${TARGET_SITE}/secrets/passphrases/"
  317. echo "Exposed ports of services can be listed with the following command:"
  318. echo " # kubectl get services --all-namespaces | grep -v ClusterIP"
  319. echo " ..."
  320. echo " "
  321. set -x
  322. }
  323. function your_next_steps() {
  324. set +x
  325. echo " "
  326. echo "---------------------------------------------------------------"
  327. echo " "
  328. echo "Airship has completed deployment of OpenStack (OpenStack-Helm)."
  329. echo " "
  330. echo "Explore Airship Treasuremap repository and documentation"
  331. echo "available at the following URLs:"
  332. echo " "
  333. echo " https://opendev.org/airship/treasuremap/"
  334. echo " https://airship-treasuremap.readthedocs.io/"
  335. echo " "
  336. echo "---------------------------------------------------------------"
  337. echo " "
  338. set -x
  339. }
  340. function clean() {
  341. # Perform any cleanup of temporary or unused artifacts
  342. set +x
  343. echo "To remove files generated during this script's execution, delete ${WORKSPACE}."
  344. echo "This VM is disposable. Re-deployment in this same VM will lead to unpredictable results."
  345. set -x
  346. }
  347. function error() {
  348. # Processes errors
  349. set +x
  350. echo "Error when $1."
  351. set -x
  352. exit 1
  353. }
  354. trap clean EXIT
  355. # Common steps for all breakpoints specified
  356. check_preconditions || error "checking for preconditions"
  357. configure_apt || error "configuring apt behind proxy"
  358. setup_workspace || error "setting up workspace directories"
  359. configure_dev_configurables || error "adding dev-configurables values"
  360. install_dependencies || error "installing dependencies"
  361. configure_docker || error "configuring docker behind proxy"
  362. # collect
  363. if [[ ${STEP_BREAKPOINT} -ge 10 ]]; then
  364. echo "This is a good time to grab a coffee :)"
  365. run_pegleg_collect || error "running pegleg collect"
  366. fi
  367. # genesis
  368. if [[ ${STEP_BREAKPOINT} -ge 20 ]]; then
  369. generate_certs || error "setting up certs with Promenade"
  370. lint_design || error "linting the design"
  371. generate_genesis || error "generating genesis"
  372. run_genesis || error "running genesis"
  373. validate_genesis || error "validating genesis"
  374. genesis_complete || error "printing out some info about next steps"
  375. setup_deploy_site || error "preparing the /site directory for deploy_site"
  376. fi
  377. # deploy
  378. if [[ ${STEP_BREAKPOINT} -ge 30 ]]; then
  379. execute_deploy_site || error "executing deploy_site from the /site directory"
  380. fi
  381. # demo
  382. if [[ ${STEP_BREAKPOINT} -ge 40 ]]; then
  383. execute_create_heat_stack || error "creating heat stack"
  384. publish_horizon_dashboard || error "publishing Horizon dashboard"
  385. print_shipyard_info1
  386. print_shipyard_info2
  387. print_dashboards || error "printing dashboards list"
  388. ## Done
  389. your_next_steps
  390. fi