项目作者: springernature

项目描述 :
SNPaaS client and docker image
高级语言: Shell
项目地址: git://github.com/springernature/ee-snpaas-cli.git
创建时间: 2018-10-18T14:47:39Z
项目社区:https://github.com/springernature/ee-snpaas-cli

开源协议:MIT License

下载


ee-snpaas-cli

Build docker and push to GCR (Github Packages and Google)
Build docker and publish to DockerHub if released

Engineering Enablement SNPaaS client.

This repository uses GitHub Actions to build the docker images. All changes are build and push to
Github Packages and our Google Container Registry.
To release a new version and publish to DockerHUB (in order to be used by snpaas-cli) please create a
new Github Release with a proper version (usually the same as you specify in Dockerfile/VERSION, but
the version from the release wins).

Install

  1. wget https://raw.githubusercontent.com/springernature/ee-snpaas-cli/master/snpaas -O snpaas && chmod a+x snpaas

Don’t want to install …

SNPaaS Command line program is based on Docker. This command is just a shell
wrapper for docker execute something like (plus a lot of variables):

  1. docker run --rm -v /home/$USER:/home/$USER -v $(pwd):/data -it platformengineering/snpaas-tools "${@}"

There is a python version of this program, but it has some issues, so it is
developed in the branch python-cli of this repo (the documentation is there).

Potentially it should run on Windows by installing Docker client command line
and delegating the execution to a box with docker daemon running (by defining
the proper environment variables), for example: the bastion host.

Docker development

The docker folder have all the sources to create the Docker container.
Creating and publishing the container is done with the script publish-dockers-dockerhub.sh
(also with GitHub actions), and uses an experimental docker feature squash to
create a single layer image. The script takes all folders (they must have a Dockerfile)
and creates a Docker image with the name of each folder. Once the image is created is
automatically pushed to dockerhub.com using platformengineering account.
You have to be loged in with docker login in other to publish the Image.

  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE
  • Images are public available. DO NOT INCLUDE SECRETS THERE

If you include them, your next task will be rotate all secrets everywhere!, without rest!
Anyway, if you include secrets, you are doing something wrong. Docker images are not created to store secrets!

How this thing works?

  1. Dockerfile includes all software (with specific versions).
  2. Docker reads the ENTRYPOINT ["/bin/bash", "/run.sh"], which will be always executed.
  3. Docker will make available the current folder to the running container inside /data, all programs and scripts will be executed there.
  4. The run.sh script reads the .envrc files and presents the usage (help) if needed.
  5. Depending on the first argument, it will execute a command like bosh, credhub … or it will run manage-deployment.sh script

The script manage-deployment.sh parses all the folder structure and runs the commands to manage a deployment. It is very verbose and always shows what it is doing, with colors, you can replicate everything copying the blue commands.

Usage

Download the bash script and make it executable:

  1. $ wget https://raw.githubusercontent.com/springernature/ee-snpaas-cli/master/snpaas -O snpaas && chmod a+x snpaas

Make sure to put it into a location included in your $PATH.
Once it is installed, type snpaas

  1. $ snpaas
  2. # latest: Pulling from platformengineering/snpaas-tools
  3. # Digest: sha256:98e43521714bbb536bb8d8b95f9bd7515cab8d9d61838ba2b723386465b99187
  4. # Status: Image is up to date for platformengineering/snpaas-tools:latest
  5. # docker.io/platformengineering/snpaas-tools:latest
  6. #
  7. # Running snpaas cli version 2.0
  8. # Workdir root: /data
  9. # Loading repository .envrc
  10. # > Targeting Bosh director 10.80.202.6 as admin user
  11. # Using environment '10.80.202.6' as client 'admin'
  12. #
  13. # Name test-bosh-env
  14. # UUID a25d8a26-ec15-40fb-a6da-8e43b269bd11
  15. # Version 270.1.1 (00000000)
  16. # CPI google_cpi
  17. # Features compiled_package_cache: disabled
  18. # config_server: enabled
  19. # local_dns: enabled
  20. # power_dns: disabled
  21. # snapshots: disabled
  22. # User admin
  23. #
  24. # Succeeded
  25. # > Targeting Credhub 10.80.202.6:8844 as credhub-admin user
  26. # Setting the target url: https://10.80.202.6:8844
  27. # Login Successful
  28. # > Defining gcloud config for project sn-paas-test region europe-west4 on zone europe-west4-a ...
  29. # Updated property [compute/zone].
  30. # Updated property [compute/region].
  31. # Updated property [core/project].
  32. #
  33. # DONE LOADING .envrc
  34. # No '.envrc' file found in current folder!
  35. # Docker image: platformengineering/snpaas-tools
  36. This docker image packages the tools SNPaaS team uses to manage the deployments.
  37. It includes binary clients for cf, bosh, credhub ...
  38. For more information go to: https://github.com/springernature/ee-snpaas-cli
  39. # Usage
  40. You can execute them directly. In the current folder you can define a '.envrc' file
  41. with all environment variables you want to be setup in the running container.
  42. If you do not have a '.envrc' file but you have the following environment variables
  43. in your environment, then Bosh-cli, Credhub-cli and CF-cli will automatically log-in:
  44. "BOSH_CLIENT"
  45. "BOSH_CLIENT_SECRET"
  46. "BOSH_ENVIRONMENT"
  47. "BOSH_CA_CERT"
  48. "CREDHUB_SERVER"
  49. "CREDHUB_CLIENT"
  50. "CREDHUB_SECRET"
  51. "CREDHUB_CA_CERT"
  52. "GCP_PROJECT"
  53. "GCP_ZONE"
  54. "GCP_REGION"
  55. "CF_USER"
  56. "CF_PASSWORD"
  57. "CF_API"
  58. "CF_ORG"
  59. "CF_SPACE"
  60. Then you are ready to manage to manage deployments, with this subcommands and options:
  61. [main-options] <subcommand> [subcommand-options] <folder-deployment-name> [other-specific-subcommand-args]
  62. Main-options:
  63. -h --help Shows this help
  64. --noenv Do not load .envrc files
  65. Subcommand-Options:
  66. -m Specify a manifest file, instead of generating a random one
  67. -p Deployments path. Default is $DEPLOYMENTS_PATH
  68. Subcommands:
  69. help Shows this usage help
  70. Bosh/deployment subcommands
  71. interpolate [bosh-int-parameters]
  72. Create the manifest for an environment
  73. create-env Deploy a Bosh Director
  74. delete-env Destroy a Bosh Director
  75. deploy [-f] [bosh-deploy-paramereters]
  76. Update or upgrade deployment after applying cloud/runtime configs
  77. destroy [-f] [bosh-destroy-parameters]
  78. Delete deployment (does not delete cloud/runtime configs)
  79. cloud-config Apply cloud-config operations files prefixed with deployment name
  80. runtime-config Apply runtime-config operations files prefixed with deployment name
  81. import-secrets Set secrets in Credhub from <deployment-folder>/$DEPLOYMENT_CREDS file
  82. list-secrets List secrets from Credhub for <deployment-folder>
  83. export-secrets Download secrets from Credhub to <deployment-folder>/$DEPLOYMENT_CREDS
  84. agent-certificates
  85. Scan Bosh vms of a deployment (if provided as argument, otherwise it
  86. will scan all vms) looking for Bosh Agent certificates, warning those
  87. vms with certificates about to expire. Helps finding VMs which need to
  88. be recreated when rotating Bosh Agent certificates.
  89. CloudFoundry subcommands (Please define CF_ environment variables!)
  90. cf-top top like command for Cloudfoundry
  91. cf-disk Full disk usage report
  92. cf-mem Memory usage report
  93. cf-users List users and roles
  94. cf-usage Show usage
  95. cf-docker List docker images
  96. cf-app-stats <app> Graphical application stats
  97. cf-mysql <service> Connect with a mysql database to perform commands
  98. cf-route-lookup <route> CF route lookup
  99. You can type any other (interactive) commands
  100. bosh
  101. cf
  102. terraform
  103. bash
  104. ...
  105. # Folder structure:
  106. <deployment-folder>
  107. ├── <boshrelease1-git-submodule-folder>
  108. ├── <boshrelease2-git-submodule-folder>
  109. ├── ...
  110. ├── [state.json]
  111. ├── [cloud-config.yml]
  112. ├── [runtime-config.yml]
  113. ├── var-files.yml
  114. ├── prepare.sh
  115. ├── finish.sh
  116. ├── operations
  117. ├── 00-base-manifest.yml -> ../<boshrelease1-git-submodule-folder>/manifest/base.yml
  118. ├── 10-operation.yml -> ../<boshrelease1-git-submodule-folder>/manifest/operations/operation.yml
  119. ├── 20-operation2.yml -> ../<boshrelease1-git-submodule-folder>/manifest/operations/operation2.yml
  120. ├── 99-springer-nature-operation-custom.yml
  121. ├── secrets.yml
  122. ├── runtime-config
  123. ├── local-runtime-config-file-for-deployment.yml
  124. ├── cloud-config
  125. ├── local-cloud-config-file-for-deployment.yml
  126. └── variables
  127. ├── variables-custom1.yml
  128. ├── variables-custom1.yml
  129. └── variables-provided.yml -> ../<boshrelease1-git-submodule-folder>/manifest/vars.yml
  130. * 'state.json' maintains the CURRENT STATE of the Director. It needs to be commited and pushed
  131. everytime Bosh director is updated/created.
  132. * 'cloud-config.yml' is the DEFAULT cloud-config AUTOMATICALLY applied after Director is updated (always)
  133. * 'runtime-config.yml' is the DEFAULT runtime-config AUTOMATICALLY applied after Director is updated (always)
  134. * 'var-files.yml' is a simple yaml key-value store to define 'var-file' arguments to Bosh client.
  135. Each line of this file will become an argument of '--var-file' parameters, eg:
  136. 'director_gcs_credentials_json: ../gcp-creds/bosh-user/sn-paas-74d6f8c8e43e.json'
  137. will become an command line argument
  138. '--var-file director_gcs_credentials_json=../gcp-creds/bosh-user/sn-paas-74d6f8c8e43e.json'.
  139. Files are relative paths to the folder where snpaas-cli is being executed (do not use absolute paths here!).
  140. * 'prepare.sh' script executed BEFORE ALL actions. If exits with error, the entire process stops.
  141. It receives as first argument the ACTION executed in snpaas-cli.
  142. * 'finish.sh' script executed AFTER ALL actions (last one before snpaas-cli exits).
  143. It receives as first argument the ACTION executed in snpaas-cli and the second argument
  144. is the EXIT code of the snpaas action executed (normally, 0 if no error, gt 1 otherwise).
  145. * 'operations' folder is a set of links to other files (normally in the git submodules)
  146. or files defining Bosh client operations files. Snpaas-cli generates a list of files alphabetically
  147. sorted by name. Order in operations files is important so, files are named with a
  148. numerical prefix.
  149. * 'secrets.yml' holds all secrets (users, passwords and certificates) created by bosh-cli
  150. create-env action (formerly called creds.yml). It is an important file, if it gets lost, all
  151. credentials will be regenerated and everything will need to get redeployed!.
  152. * 'cloud-config' folder defines NON-DEFAULT (named) cloud configs for Bosh. Those
  153. are not applied automatically. They need to be applied with
  154. 'snpaas cloud-config <folder-director-name>' (or manually). The name of each cloud-config
  155. will be '<deployment-or-director_name>-<name_of_the_file_without_extension>'.
  156. * 'runtime-config' folder defines NON-DEFAULT (named) runtime configs for Bosh. Those
  157. are not applied automatically. They need to be applied with
  158. 'snpaas runtime-config <folder-director-name>' (or manually). The name of each runtime-config
  159. will be '<deployment-or-director_name>-<name_of_the_file_without_extension>'.
  160. * 'variables' folder holds a set of files with variables being used in the runtime/cloud
  161. configs or manifests/operations files. There is no order in those files and potentially
  162. they can be generated by Terraform of in the Prepare script.
  163. Snpaas-cli will try to find variables in the environment, with the prefix of the
  164. folder, e.g. if the deployment folder is "cf-test" and you have defined an variable
  165. "((stemcell))" in an operations file, you can define a variable like
  166. "export CF_TEST_stemcell=ubuntu-xenial" and it will be used.
  167. Secrets processed by this program are type 'value' and they will be imported/exported
  168. from Credhub from/to a 'secrets.yml' file. When interpolate or deploy, the program
  169. will check if there is a secrets file, if so, it will be used as store for generated
  170. secrets automatically. If you want to force the script to generate and store
  171. secrets there, just create an empty file: "touch secrets.yml" otherwise Bosh will
  172. use Credhub. So make sure you do not have a 'secrets.yml' if you want to store all
  173. credentials in Credhub. To sum up:
  174. * Use a 'secrets.yml' file to export/import credentials from Credhub, then delete
  175. it to avoid confusion between Credhub and 'secrets.yml'.
  176. * If there is no Credhub, create an empty 'secrets.yml' file. All credentials will
  177. be generated and stored there.
  178. * Do not use 'secrets.yml' in any other situation.
  179. You can add a couple of scripts "prepare.sh" and "finish.sh" which will be executed
  180. automatically before and after the action (destroy, deploy or interpolate). Both
  181. will receive the action as first argument, and the "finish.sh" script will also get
  182. the exit code from the action (the finish script is always executed, even if the
  183. action fails).
  184. The operations file is not required if you have a simple manifest which does not need
  185. operations files. In this situation, just copy the manifest to the deployment folder
  186. and make sure there is no operations folder there. The first yaml file (in lexical
  187. order) will be taken as manifest and deployed, so make sure you call the manifest
  188. file properly (secrets.yml is always ignored, so do not worry about it).
  189. When deploying a Bosh Director, a state file 'state.json' will be created and
  190. the DEFAULT cloud-config and runtime-config (name=default!) will be applied AUTOMATICALLY
  191. if the deployment was successfully done.
  192. # Usage examples
  193. Given a typical deployment folder called 'app-logging' with this structure:
  194. app-logging
  195. ├── prepare.sh
  196. ├── runtime-config
  197. ├── dns.yml
  198. └── mtail.yml
  199. ├── cloud-config
  200. └── vm_types.yml
  201. ├── operations
  202. ├── 00-base.yml -> ../cf-logging-boshrelease/manifest/logstash.yml
  203. ├── 20-cf-apps-es.yml -> ../cf-logging-boshrelease/manifest/operations/pipelines/cf-apps-es-throttling.yml
  204. ├── 25-add-statsd-conf.yml -> ../cf-logging-boshrelease/manifest/operations/add-statsd-conf.yml
  205. ├── 30-add-throttle-param.yml -> ../cf-logging-boshrelease/manifest/operations/add-throttle-param.yml
  206. ├── 50-add-es-cloud-id.yml -> ../cf-logging-boshrelease/manifest/operations/add-es-cloud-id.yml
  207. ├── 50-add-es-xpack.yml -> ../cf-logging-boshrelease/manifest/operations/add-es-xpack.yml
  208. ├── 80-add-logstash-exporter.yml -> ../cf-logging-boshrelease/manifest/operations/add-logstash-exporter.yml
  209. ├── 90-add-release-version.yml -> ../cf-logging-boshrelease/manifest/operations/add-release-version.yml
  210. ├── 99-deployment-settings.yml
  211. └── 99-iaas.yml -> ../cf-logging-boshrelease/manifest/operations/add-iaas-parameters.yml
  212. ├── secrets.yml
  213. └── variables
  214. ├── iaas.yml
  215. ├── throttle-param.yml
  216. └── vars-release-version.yml -> ../cf-logging-boshrelease/manifest/vars-release-version.yml
  217. In the above structure 'cf-logging-boshrelease' is a git submodule. The idea is reuse
  218. resources from there (normally operations files).
  219. * To deploy or update the deployment called 'app-logging', execute: 'deploy app-logging'.
  220. If you do not want to answer 'y/n' question when bosh runs, just use '-f' option:
  221. 'deploy app-logging -f'
  222. * To list secrets of the deployment from Credhub: 'list-secrets app-logging'
  223. * Exporting the secrets of the deployment from Credhub to file 'app-logging/secrets.yml'
  224. is done with: 'export-secrets app-logging'. Only credentials type value are supported.
  225. * Import the secrets of the deployment to Credhub from a file 'app-logging/secrets.yml':
  226. 'import-secrets app-logging'. All credentials will be imported as type value.
  227. * In order to apply the name of the folder to the deployment, you need to provide
  228. an operations file with this operation.
  229. - type: replace
  230. path: /name
  231. value: ((deployment_name))
  232. The variable 'deployment_name' is provided by the program and taken from the
  233. folder name
  234. * It is possible to define variables in the runtime/cloud configs or
  235. manifests/operations files and the program will try to find those variables in
  236. the environment, with the prefix of the folder, e.g. if the deployment folder
  237. is "cf-test" and you have defined an variable "((stemcell))" in an operations
  238. file, you can define a variable like "export CF_TEST_stemcell=ubuntu-xenial"
  239. and it will be used.
  240. # Why?
  241. * Avoid writting documentation about each deployment. Each folder has a specific
  242. structure, the script only goes through the folder structure and generates
  243. and applies the operations to the base manifest.
  244. * Make it easy to manage bosh deployments. If the deployment folder is properly
  245. done, replicating it for testing purposes is as easy as clonning the folder
  246. and deploy again.
  247. * Easily manage Credhub secrets in a deployment. One can import, export and
  248. list secrets from files to Credhub (Only secrets type value, the other ones
  249. are managed via the 'variables' section in a manifest!).
  250. * Show you the commands it runs each time, with colorized output in order to
  251. stand out if something went wrong.
  252. * Loose coupled. The sript is a wrapper for Bosh and Credhub clients. If you do
  253. not like the script, you do not have to use it. The folder structure is
  254. self-documented, so you only need to build the bosh and credhub parameters
  255. from these files.
  256. The script always show what is executing (blue commands), if something fails,
  257. just copy the blue commands and execute them step by step.
  258. # Programs and versions installed
  259. Additionally you can directly execute all the following programs installed, just
  260. by typing then as argument, e.g:
  261. snpaas credhub find -p '/director-name/'
  262. BBR: 1.7.2
  263. CERTSTRAP: 1.1.1
  264. YQ: 3.3.2
  265. CF6_PLUGINS: /opt
  266. CF_CLI: 6.45.0
  267. VARSTOCREDHUB: 0.1.0
  268. CF_RTR: 2.22.0
  269. HALFPIPE: 3.34.0
  270. FLY: 6.3.0
  271. HOME: /home/snpaas
  272. VERSION: 3.12
  273. GCLOUD_SDK: 298.0.0
  274. USER: snpaas
  275. SPIFF: 1.0.8
  276. BOSH_CLI: 6.3.0
  277. CREDHUB: 2.7.0
  278. DATADIR: /data
  279. TERRAFORM: 0.12.23
  280. JQ: 1.5
  281. SPRUCE: 1.18.0
  282. VAULT: 1.4.2

Author

Springer Nature Engineering Enablement (EE), Jose Riguera Lopez (jose.riguera@springer.com)