项目作者: engapa

项目描述 :
Utils for docker containers
高级语言: Shell
项目地址: git://github.com/engapa/utils-docker.git
创建时间: 2017-01-21T12:58:55Z
项目社区:https://github.com/engapa/utils-docker

开源协议:MIT License

下载


Basic utilities within Docker images/containers

Build status
Docker Pulls
Docker Layering
Docker image version
OSS

Known utilities to use/build docker containers/images

Common Functions

A collection of bash functions to make easier common tasks

env_vars_in_file

Write your environment variables into a file.

For instance, suppose you have these vars and want to write them into a file “/conf.properties”:

  1. SERVER_TIMEOUT=60
  2. SERVER_URL=https://mysite.com
  3. SERVER_BIND_IP=192.168.10.10

The Dockerfile would be like this:

  1. ...
  2. ENV SERVER_TIMEOUT=60 \
  3. SERVER_URL=https://mysite.com \
  4. SERVER_BIND_IP=192.168.10.10
  5. ...
  6. RUN ["wget", "https://raw.githubusercontent.com/engapa/utils-docker/master/common-functions.sh"]
  7. RUN . common-functions.sh \
  8. && PREFIX=SERVER_ DEST_FILE='/conf.properties' DEBUG=true env_vars_in_file
  9. ...

When we’re building the Docker image we find out these lines in the output :

  1. $ docker build -t engapa/common_functions --rm .
  2. ...
  3. Step 5/6 : RUN . common-functions.sh && PREFIX=SERVER_ DEST_FILE='/conf.properties' DEBUG=true env_vars_in_file
  4. ---> Running in 4420331fd948
  5. Writing environment variables to file :
  6. PREFIX : SERVER_
  7. DEST_FILE : /conf.properties
  8. EXCLUSIONS :
  9. CREATE_FILE : true
  10. OVERRIDE : true
  11. FROM_SEPARATOR : _
  12. TO_SEPARATOR : .
  13. LOWER : true
  14. .......................................
  15. [ ADD ] : SERVER_BIND_IP --> bind.ip=192.168.10.10
  16. [ ADD ] : SERVER_TIMEOUT --> timeout=60
  17. [ ADD ] : SERVER_URL --> url=https://mysite.com
  18. ...
  19. Successfully built c3cee6c14084

So, the contents of file /conf.properties, in a new container created from this image, are the expected:

  1. $ docker run c3cee6c14084 cat /conf.properties
  2. bind.ip=192.168.10.10
  3. timeout=60
  4. url=https://mysite.com

And finally, if you want to change or add any more parameter then launch the container (or extended Dockerfile with ‘ENV’ entries) like this:

  1. $ docker run -e "SERVER_BIND_IP=0.0.0.0" -e "SERVER_VERIFY_SKIP=True" c3cee6c14084 \
  2. /bin/bash -c ". common-functions.sh && PREFIX=SERVER_ DEST_FILE='/conf.properties' DEBUG=true env_vars_in_file && cat /conf.properties"
  3. Writing environment variables to file :
  4. PREFIX : SERVER_
  5. DEST_FILE : /conf.properties
  6. EXCLUSIONS :
  7. CREATE_FILE : true
  8. OVERRIDE : true
  9. FROM_SEPARATOR : _
  10. TO_SEPARATOR : .
  11. LOWER : true
  12. .......................................
  13. [OVERRIDE] : SERVER_BIND_IP --> bind.ip=0.0.0.0
  14. [ ADD ] : SERVER_VERIFY_SKIP --> verify.skip=True
  15. [OVERRIDE] : SERVER_TIMEOUT --> timeout=60
  16. [OVERRIDE] : SERVER_URL --> url=https://mysite.com
  17. bind.ip=0.0.0.0
  18. timeout=60
  19. url=https://mysite.com
  20. verify.skip=True

NOTE: Do not forget to remove test containers and image to avoid resource consumption on your host by typing :
$ docker rm -f $(docker ps -q -f ancestor=c3cee6c14084)
$ docker rmi c3cee6c14084

GitHub Release

If you wonder how to publish a release on github this utility is for you.

Publish a release on GitHub

The gh-release function aims you to publish a release in GitHub.

All-in-One container

If you prefer to use directly a docker container, for instance in your workflow pipelines we may have a step like this one:

  1. $ docker run -it engapa/utils-docker:latest
  2. ... Outputs all available functions ...
  3. $ docker run -it engapa/utils-docker:latest log Hello Enk
  4. [INFO] [2019-01-03_08:29:46] - Hello Enk