Skip to content

Commit 39708df

Browse files
elaborate on usage
1 parent 2cc88b9 commit 39708df

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
11
# init-plain
22
Script to provide an entrypoint and helpers for the plain docker image series.
3+
4+
## entrypoint.sh
5+
6+
The script is supposed to be specified as `ENTRYPOINT` for a given Docker Image.
7+
E.g. within [qnib/alplain-init](https://github.com/qnib/alplain-init).
8+
9+
It will iterate over the executables within `/opt/qnib/entry` and either execute or source them.
10+
11+
```
12+
#!/bin/bash
13+
set -e
14+
15+
for x in $(find /opt/qnib/entry/ -type f -perm /u+x |sort);do
16+
echo "> execute entrypoint '${x}'"
17+
if [[ "$x" == *.env ]];then
18+
source ${x}
19+
else
20+
./${x}
21+
fi
22+
done
23+
24+
if [ "X${ENTRY_USER}" != "X" ];then
25+
exec su -s /bin/bash -c "$@" ${ENTRY_USER}
26+
else
27+
exec "$@"
28+
fi
29+
```
30+
31+
Once this is done, the command defined with `CMD` will be executed and the process control is handed over - in case an `$ENTRY_USER` is specified under a user other then `root`.
32+
33+
## `/opt/qnib/entry`
34+
35+
### Share log-socket
36+
37+
The first script (`00-`) executed will search for a log-device of an underlying syslog server and create a symlink to `/dev/log`, so that the container can naturally use this socket.
38+
39+
```
40+
$ cat /opt/qnib/entry/00-logging.sh
41+
#!/bin/bash
42+
43+
if [ ! -z ${LOGNAME} ] && [ -S /shareddev/${LOGNAME}/log ];then
44+
ln -s /shareddev/${LOGNAME}/log /dev/log
45+
logger -s "Created container specific symlink to syslog container"
46+
elif [ -S /shareddev/log ];then
47+
ln -s /shareddev/log /dev/log
48+
logger -s "Created symlink from syslog container"
49+
fi
50+
```
51+
52+
### environment variables
53+
54+
In case environment variables should be sourced before the main process starts, the prefix `.env` should be used.
55+
56+
This exemplary script sources docker-secrets as environment variables.
57+
58+
```
59+
$ cat /opt/qnib/entry/10-docker-secrets.env
60+
#!/bin/bash
61+
62+
########
63+
## Check for /run/secrets and expose them as ENV variables
64+
mkdir -p /run/secrets/
65+
if [ -d /run/secrets/ ];then
66+
for sec in $(ls /run/secrets/);do
67+
KEY=$(echo ${sec} |tr '[:lower:]' '[:upper:]' |sed -e 's/-/_/g')
68+
echo "[II] Set environment variable ${KEY} from '/run/secrets/${sec}'"
69+
declare "$KEY=$(cat /run/secrets/${sec})"
70+
export $KEY
71+
done
72+
else
73+
echo "[II] No /run/secrets directory, skip step"
74+
fi
75+
```

0 commit comments

Comments
 (0)