From: Sam Saffron Date: Fri, 6 Dec 2013 01:41:57 +0000 (-0800) Subject: add a special env var DOCKER_HOST_IP to all images X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=80c11be3440eb5df114d6ac6912561e19c239738;p=discourse_docker.git add a special env var DOCKER_HOST_IP to all images allow data container to bootstrap a discourse database configure a multi image setup --- diff --git a/launcher b/launcher index b99f304..83a8e7a 100755 --- a/launcher +++ b/launcher @@ -9,6 +9,13 @@ local_discourse=local_discourse image=samsaffron/discourse docker_path=`which docker` +docker_ip=`/sbin/ifconfig | \ + grep -B1 "inet addr" | \ + awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' | \ + grep docker0 | \ + awk -F: '{ print $3 }';` + + usage () { echo "Usage: launcher COMMAND CONFIG" echo "Commands:" @@ -84,7 +91,7 @@ case "$command" in rm -f $cidbootstrap - (exec echo "$input" | docker run -cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes $image \ + (exec echo "$input" | docker run -e DOCKER_HOST_IP=$docker_ip -cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes $image \ /bin/bash -c 'cd /pups && git pull && /pups/bin/pups --stdin') \ || (docker rm `cat $cidbootstrap` && rm $cidbootstrap) @@ -145,7 +152,9 @@ case "$command" in set_volumes - docker run -name $config -cidfile $cidfile $ports -d $volumes $local_discourse/$config /usr/bin/runsvdir -P /etc/service + docker run -e DOCKER_HOST_IP=$docker_ip -name $config -cidfile $cidfile $ports \ + -d $volumes $local_discourse/$config /usr/bin/runsvdir -P /etc/service + exit 0 else echo "cid found, ensuring container is started" diff --git a/samples/data.yml b/samples/data.yml index 2f46d82..84678a0 100644 --- a/samples/data.yml +++ b/samples/data.yml @@ -1,5 +1,5 @@ -# a basic data only container - +# A container for all things Data, be sure to set a secret password for discourse account, SOME_SECRET is just an example +# templates: - "templates/cron.template.yml" - "templates/postgres.template.yml" @@ -11,10 +11,20 @@ expose: - "6379:6379" - "2221:22" +# ssh key for logging in to container params: - ssh_key: YOUR_KEY + ssh_key: "" +# amend SOME_SECRET to a password for the discourse user +hooks: + after_postgres: + - exec: + stdin: | + alter user discourse with password 'SOME_SECRET'; + cmd: sudo -u postgres psql discourse + raise_on_fail: false +# be sure to set the host location somewhere sane volumes: - volume: - host: /home/sam/discourse_docker/shared + host: /var/discourse/shared guest: /shared diff --git a/samples/web_only.yml b/samples/web_only.yml index 5c1a4b8..69a987a 100644 --- a/samples/web_only.yml +++ b/samples/web_only.yml @@ -1,3 +1,6 @@ +# IMPORTANT: SET A SECRET PASSWORD in Postgres for the Discourse User +# SOME_SECRET in this template + templates: - "templates/sshd.template.yml" - "templates/web.template.yml" @@ -7,24 +10,30 @@ expose: - "2222:22" params: - ssh_key: YOUR_KEY +# your ssh key can go here, or you can use ssh-import-id + ssh_key: "" version: HEAD - database_yml: production: + socket: "" + host: <%= ENV['DOCKER_HOST_IP'] %> + database: discourse + username: discourse + password: SOME_SECRET host_names: - - example.com + - www.SOME_DOMAIN.com + +# developer emails allow you to fast track account creation on the site env: - DEVELOPER_EMAILS: 'dev@example.com' + DEVELOPER_EMAILS: '' volumes: - volume: - host: /home/sam/discourse_docker/shared + host: /var/docker/shared guest: /shared - # you may use the docker manager to upgrade and monitor your docker image # UI will be visible at http://yoursite.com/admin/docker hooks: @@ -32,6 +41,14 @@ hooks: #after_sshd: # - exec: ssh-import-id some-user after_code: + - file: + path: $home/config/redis.yml + contents: | + production: + host: <%= ENV['DOCKER_HOST_IP'] %> + port: 6379 + db: 0 + cache_db: 2 - exec: cd: $home/plugins cmd: diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml index 6e8a746..40f41a2 100644 --- a/templates/postgres.template.yml +++ b/templates/postgres.template.yml @@ -19,28 +19,6 @@ hooks: 0 */4 * * * /var/lib/postgresql/take-database-backup before_code: - - exec: - background: true - cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main" - - # give db a few secs to start up - - exec: "sleep 5" - - - exec: sudo -u postgres createdb discourse || exit 0 - - exec: - stdin: | - create user discourse; - cmd: sudo -u postgres psql discourse - raise_on_fail: false - - - exec: - stdin: | - grant all privileges on database discourse to discourse; - cmd: sudo -u postgres psql discourse - raise_on_fail: false - - - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"' - - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"' - replace: filename: /etc/service/sidekiq/run from: "# postgres" @@ -70,6 +48,12 @@ run: from: "data_directory = '/var/lib/postgresql/9.2/main'" to: "data_directory = '/shared/postgres_data'" + # listen on all interfaces + - replace: + filename: "/etc/postgresql/9.2/main/postgresql.conf" + from: /#?listen_addresses *=.*/ + to: "listen_addresses = '*'" + # Necessary to enable backups - exec: cmd: @@ -89,3 +73,36 @@ run: filename: "/etc/postgresql/9.2/main/pg_hba.conf" from: /^#local +replication +postgres +peer$/ to: "local replication postgres peer" + + # allow all to connect in with md5 auth + - replace: + filename: "/etc/postgresql/9.2/main/pg_hba.conf" + from: /^host.*all.*all.*127.*$/ + to: "host all all 0.0.0.0/0 md5" + + - exec: + background: true + cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main" + + # give db a few secs to start up + - exec: "sleep 5" + + - exec: sudo -u postgres createdb discourse || exit 0 + - exec: + stdin: | + create user discourse; + cmd: sudo -u postgres psql discourse + raise_on_fail: false + + - exec: + stdin: | + grant all privileges on database discourse to discourse; + cmd: sudo -u postgres psql discourse + raise_on_fail: false + + - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"' + - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"' + + - exec: + hook: postgres + cmd: "echo postgres installed!" diff --git a/templates/sshd.template.yml b/templates/sshd.template.yml index 327ad29..7325262 100644 --- a/templates/sshd.template.yml +++ b/templates/sshd.template.yml @@ -15,6 +15,8 @@ run: contents: | #!/bin/sh exec 2>&1 + echo export DOCKER_HOST_IP=$DOCKER_HOST_IP > /etc/profile.d/docker.sh + chmod +x /etc/profile.d/docker.sh exec /usr/sbin/sshd -D -e - exec: