Skip to content

Commit ea38545

Browse files
committed
Add more detail to readme
1 parent 4412b5d commit ea38545

File tree

1 file changed

+88
-3
lines changed

1 file changed

+88
-3
lines changed

README.md

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,74 @@ Common container Bash functions used for handling Docker image entrypoint semant
77

88
All functions are [Bats](https://github.com/bats-core/bats-core) tested and checked against [ShellCheck](https://github.com/koalaman/shellcheck).
99

10+
## Table of Contents
11+
12+
- [Core Concepts](#core-concepts)
13+
- [Functions](#functions)
14+
- [Process Management](#process-management)
15+
- [Service Waiting](#service-waiting)
16+
- [File Handling](#file-handling)
17+
- [Miscellaneous](#miscellaneous)
18+
- [Install](#install)
19+
- [Example Usage](#example-usage)
20+
- [Bash Strict Mode](#bash-strict-mode)
21+
- [License](#license)
22+
- [Status](#status)
23+
24+
## Core Concepts
25+
26+
This collection of Bash functions simplifies the creation of robust Docker entrypoint scripts. The main goals are:
27+
28+
- **Service-awareness**: Wait for dependent services like databases or message queues to be available before starting the main application.
29+
- **Dynamic configuration**: Use environment variables to render configuration files at runtime.
30+
- **Process management**: Manage application processes using `Procfile`-like mechanics.
31+
- **Filesystem setup**: Handle the mounting of data volumes and template files.
32+
33+
## Functions
34+
35+
### Process Management
36+
37+
| Function | Description | Usage |
38+
| --------------------------------------- | ------------------------------------------------------------------------------ | ----------------------------------- |
39+
| `execute <PROCFILE> <COMMAND>` | Executes a command from a Procfile. Returns 127 if the command is not found. | `execute Procfile web` |
40+
| `exec_procfile <COMMAND>` | A wrapper for `execute` that uses `Procfile` by default. | `exec_procfile web` |
41+
| `run_all [PROCFILE]` | Runs all commands in a Procfile. | `run_all` or `run_all Deployfile` |
42+
| `run_commands <PROCFILE> <COMMANDS...>` | Runs one or more specified commands from a Procfile. | `run_commands Procfile web worker` |
43+
| `run_deployfile` | Alias for `run_all Deployfile`. | `run_deployfile` |
44+
| `run_procfile` | Alias for `run_all Procfile`. | `run_procfile` |
45+
| `run_procfile_commands` | Alias for `run_commands Procfile`. | `run_procfile_commands web` |
46+
| `run_deployfile_commands` | Alias for `run_commands Deployfile`. | `run_deployfile_commands task` |
47+
48+
### Service Waiting
49+
50+
| Function | Description | Usage |
51+
| ----------------------------------------------- | -------------------------------------------------------------------- | ----------------------------------------- |
52+
| `wait_http <URL> [TIMEOUT] [HTTP_TIMEOUT]` | Waits for an HTTP service to become available. | `wait_http http://api:8080 60 5` |
53+
| `wait_kubeapi [RETRIES]` | Waits for the Kubernetes API to be available. Requires `kubectl`. | `wait_kubeapi 60` |
54+
| `wait_tcp <HOST> [PORT] [RETRIES] [TCP_TIMEOUT]`| Waits for a TCP port to be open. | `wait_tcp db 5432` |
55+
| `wait_tcp_multi <HOSTS> [MIN] [PORT]...` | Waits for a minimum number of hosts to have an open TCP port. | `wait_tcp_multi redis1,redis2 2 6379` |
56+
| `wait_mariadb <HOST> [PORT]...` | Alias for `wait_tcp` with port 3306. | `wait_mariadb db` |
57+
| `wait_postgres <HOST> [PORT]...` | Alias for `wait_tcp` with port 5432. | `wait_postgres db` |
58+
| `wait_rabbitmq <HOST> [PORT]...` | Alias for `wait_tcp` with port 5672. | `wait_rabbitmq rabbit` |
59+
| `wait_redis <HOST> [PORT]...` | Alias for `wait_tcp` with port 6379. | `wait_redis cache` |
60+
| `wait_multi_rabbitmq <HOSTS> [MIN] [PORT]` | Alias for `wait_tcp_multi` with port 5672. | `wait_multi_rabbitmq rabbit1,rabbit2 1` |
61+
| `wait_multi_redis <HOSTS> [MIN] [PORT]` | Alias for `wait_tcp_multi` with port 6379. | `wait_multi_redis redis1,redis2 1` |
62+
| `wait_multi_elasticsearch <HOSTS> [MIN] [PORT]` | Alias for `wait_tcp_multi` with port 9200. | `wait_multi_elasticsearch es1,es2 1` |
63+
64+
### File Handling
65+
66+
| Function | Description | Usage |
67+
| ------------------------------------- | ------------------------------------------------------ | ---------------------------------------- |
68+
| `import_env <FILE>` | Sources an environment file and exports the variables. | `import_env /app/.env` |
69+
| `render_templates <FILES...>` | Renders template files using `gomplate`. | `render_templates /app/config.yaml.tmpl` |
70+
| `run_mountfile [MOUNTFILE] [DATADIR]` | Mounts directories based on a `Mountfile`. | `run_mountfile` |
71+
72+
### Miscellaneous
73+
74+
| Function | Description | Usage |
75+
| ------------------------- | ------------------------------ | ------------------------------- |
76+
| `set_timezone [TIMEZONE]` | Sets the container's timezone. | `set_timezone America/New_York` |
77+
1078
## Install
1179

1280
The main functions require `bash`, `curl` and `coreutils`. These take about 10M of space. The template function requires [gomplate](https://github.com/hairyhenderson/gomplate/).
@@ -69,8 +137,18 @@ set -e
69137

70138
source /panubo-functions.sh
71139

72-
# Wait for services
73-
wait_mariadb "${DB_HOST}" "${DB_PORT:-3306}"
140+
# Set the timezone
141+
set_timezone "${TZ}"
142+
143+
# Wait for services to be available
144+
wait_postgres "${DB_HOST}" "${DB_PORT:-5432}"
145+
wait_redis "${REDIS_HOST}" "${REDIS_PORT:-6379}"
146+
147+
# Render configuration templates
148+
render_templates /etc/my.cnf.tmpl
149+
150+
# Import environment variables from a file
151+
import_env /app/.env
74152

75153
# Mount data mounts (specifying an alternate mount point uid/gid)
76154
MOUNTFILE_MOUNT_UID=33
@@ -91,7 +169,6 @@ exec_procfile "$1"
91169
if [ "$?" -eq "127" ]; then
92170
exec "${@}"
93171
fi
94-
95172
```
96173

97174
### Using gomplate templating
@@ -161,3 +238,11 @@ This will render `/foo.conf.tmpl` to `/foo.conf`.
161238
## Bash Strict Mode
162239

163240
Although we like [Unofficial Bash Strict Mode](http://redsymbol.net/articles/unofficial-bash-strict-mode/) not all of these functions currently work under strict mode.
241+
242+
## License
243+
244+
This project is licensed under the [MIT License](LICENSE).
245+
246+
## Status
247+
248+
Stable and used in production.

0 commit comments

Comments
 (0)