Browse Source

docker: update start.sh and set container option to false by default

- Clean up of start.sh w/ addition of more comment
- Set socat option to false by default
- Added default value to SOCAT_LINK & RUN_CROND in the script to make it
  cleaner
- This commit contains non backward-compatible change: any configuration using socat links will either:
    - need to be updated to use DNS name when querrying external service
    - set environment variable SOCAT_LINK to true when launching the updated container
docker/socat
Jean-Philippe Roemer 9 years ago
parent
commit
b115fadd87
No known key found for this signature in database
GPG Key ID: 22A93F0A6FF4678C
  1. 2
      docker/README.md
  2. 76
      docker/start.sh

2
docker/README.md

@ -86,7 +86,7 @@ This container have some options available via environment variables, these opti
Bind linked docker container to localhost socket using socat.
Any exported port from a linked container will be binded to the matching port on localhost.
- <u>Disclaimer:</u>
As this option rely on the environment variable created by docker when a container is linked, this option should be deactivated in managed environment such as Rancher or Kubernetes (set to `0` or `false`)
As this option rely on the environment variable created by docker when a container is linked, this option should not be activated in managed environment such as Rancher or Kubernetes.
- **RUN_CROND**:
- <u>Possible value:</u>
`true`, `false`, `1`, `0`

76
docker/start.sh

@ -1,8 +1,31 @@
#!/bin/sh
## Container configuration
SOCAT_LINK=${SOCAT_LINK:-false}
RUN_CROND=${RUN_CROND:-false}
## Container utils
cleanup() {
# Cleanup SOCAT services and s6 event folder
# On start and on shutdown in case container has been killed
rm -rf $(find /app/gogs/docker/s6/ -name 'event')
rm -rf /app/gogs/docker/s6/SOCAT_*
}
create_volume_subfolder() {
# Create VOLUME subfolder
for f in /data/gogs/data /data/gogs/conf /data/gogs/log /data/git /data/ssh; do
if ! test -d $f; then
mkdir -p $f
fi
done
}
## Container option activators
create_socat_links() {
# Bind linked docker container to localhost socket using socat
USED_PORT="3000:22"
echo "init:socat | Socat links will be created (requested via SOCAT_LINK)" 1>&2
while read NAME ADDR PORT; do
if test -z "$NAME$ADDR$PORT"; then
continue
@ -22,42 +45,37 @@ create_socat_links() {
EOT
}
cleanup() {
# Cleanup SOCAT services and s6 event folder
# On start and on shutdown in case container has been killed
rm -rf $(find /app/gogs/docker/s6/ -name 'event')
rm -rf /app/gogs/docker/s6/SOCAT_*
activate_crond () {
# Request s6 to run crond
echo "init:crond | Cron Daemon (crond) will be run as requested by s6" 1>&2
rm -f /app/gogs/docker/s6/crond/down
}
create_volume_subfolder() {
# Create VOLUME subfolder
for f in /data/gogs/data /data/gogs/conf /data/gogs/log /data/git /data/ssh; do
if ! test -d $f; then
mkdir -p $f
fi
done
deactivate_crond () {
# Tell s6 not to run the crond service
touch /app/gogs/docker/s6/crond/down
}
## Environment variable parser
parse_container_options () {
# Parse opt-in / opt-out container optionss based on environment variable
# SOCAT_LINK: bind linked containers to localhost via socat
case $(echo "$SOCAT_LINK" | tr '[:upper:]' '[:lower:]') in
true|1) create_socat_links;;
esac
# RUN_CROND: request crond to be run inside the container
case $(echo "$RUN_CROND" | tr '[:upper:]' '[:lower:]') in
true|1) activate_crond;;
*) deactivate_crond;;
esac
}
## Main
cleanup
create_volume_subfolder
parse_container_options
LINK=$(echo "$SOCAT_LINK" | tr '[:upper:]' '[:lower:]')
if [ "$LINK" = "false" -o "$LINK" = "0" ]; then
echo "init:socat | Will not try to create socat links as requested" 1>&2
else
create_socat_links
fi
CROND=$(echo "$RUN_CROND" | tr '[:upper:]' '[:lower:]')
if [ "$CROND" = "true" -o "$CROND" = "1" ]; then
echo "init:crond | Cron Daemon (crond) will be run as requested by s6" 1>&2
rm -f /app/gogs/docker/s6/crond/down
else
# Tell s6 not to run the crond service
touch /app/gogs/docker/s6/crond/down
fi
# Exec CMD or S6 by default if nothing present
## End of initialization: exec CMD or s6 by default
if [ $# -gt 0 ];then
exec "$@"
else

Loading…
Cancel
Save