From fef45789c4c9dd5d0b886fce537564bafa79024e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 31 Dec 2018 10:45:08 +1100 Subject: [PATCH] DEV: improve docker dev environment - pass USER=discourse which is not passed in from docker exec (improves backup restore) - add unicorn script and unicorn support (expose port 9292) --- bin/docker/boot_dev | 7 ++++++- bin/docker/bundle | 2 +- bin/docker/mailcatcher | 2 +- bin/docker/migrate | 4 ++-- bin/docker/psql | 2 +- bin/docker/rails | 2 +- bin/docker/rake | 2 +- bin/docker/sidekiq | 2 +- bin/docker/unicorn | 10 ++++++++++ 9 files changed, 24 insertions(+), 9 deletions(-) create mode 100755 bin/docker/unicorn diff --git a/bin/docker/boot_dev b/bin/docker/boot_dev index 65f92a3dfc3..125e959eb4d 100755 --- a/bin/docker/boot_dev +++ b/bin/docker/boot_dev @@ -59,7 +59,12 @@ echo "Using data in: ${DATA_DIR}" mkdir -p "${DATA_DIR}" -docker run -d -p 1080:1080 -p 3000:3000 -v "$DATA_DIR:/shared/postgres_data:delegated" -v "$SOURCE_DIR:/src:delegated" $ENV_ARGS --hostname=discourse --name=discourse_dev --restart=always discourse/discourse_dev:release /sbin/boot +# 1080 mailcatcher +# 3000 puma... if you must (but unicorn is preferred) +# 9292 unicorn +# 9405 prometheus exporter + +docker run -d -p 9405:9405 -p 1080:1080 -p 3000:3000 -p 9292:9292 -v "$DATA_DIR:/shared/postgres_data:delegated" -v "$SOURCE_DIR:/src:delegated" $ENV_ARGS --hostname=discourse --name=discourse_dev --restart=always discourse/discourse_dev:release /sbin/boot if [ "${initialize}" = "initialize" ]; then echo "Installing gems..." diff --git a/bin/docker/bundle b/bin/docker/bundle index 1d1005c5a08..73d39aba5ff 100755 --- a/bin/docker/bundle +++ b/bin/docker/bundle @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="cd /src && RAILS_ENV=${RAILS_ENV:=development} bundle $PARAMS" +CMD="cd /src && USER=discourse RAILS_ENV=${RAILS_ENV:=development} bundle $PARAMS" docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/mailcatcher b/bin/docker/mailcatcher index f1f258d70ff..385dcbb727e 100755 --- a/bin/docker/mailcatcher +++ b/bin/docker/mailcatcher @@ -1,4 +1,4 @@ #!/bin/bash -CMD="mailcatcher --http-ip 0.0.0.0 -f" +CMD="USER=discourse mailcatcher --http-ip 0.0.0.0 -f" docker exec -it discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/migrate b/bin/docker/migrate index 4cdc94f88b7..be9e9ebd92a 100755 --- a/bin/docker/migrate +++ b/bin/docker/migrate @@ -1,6 +1,6 @@ #!/bin/bash -CMD="cd /src && RAILS_ENV=development rake db:migrate" +CMD="cd /src && USER=discourse RAILS_ENV=development rake db:migrate" docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" -CMD="cd /src && RAILS_ENV=test rake db:migrate" +CMD="cd /src && USER=discourse RAILS_ENV=test rake db:migrate" docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/psql b/bin/docker/psql index c9542d02dea..c25c840b79c 100755 --- a/bin/docker/psql +++ b/bin/docker/psql @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="psql $PARAMS" +CMD="USER=discourse psql $PARAMS" docker exec -it -u postgres discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/rails b/bin/docker/rails index 1c35b782123..4836d47eeb9 100755 --- a/bin/docker/rails +++ b/bin/docker/rails @@ -6,5 +6,5 @@ then PARAMS="$PARAMS -b 0.0.0.0" fi -CMD="cd /src && RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 LD_PRELOAD=/usr/lib/libjemalloc.so RACK_HANDLER=puma RAILS_ENV=${RAILS_ENV:=development} rails $PARAMS" +CMD="cd /src && USER=discourse RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 LD_PRELOAD=/usr/lib/libjemalloc.so RACK_HANDLER=puma RAILS_ENV=${RAILS_ENV:=development} rails $PARAMS" docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/rake b/bin/docker/rake index 146a824bb27..b1b73b7c95b 100755 --- a/bin/docker/rake +++ b/bin/docker/rake @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="cd /src && RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 LD_PRELOAD=/usr/lib/libjemalloc.so RAILS_ENV=${RAILS_ENV:=development} bundle exec rake $PARAMS" +CMD="cd /src && USER=discourse RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 LD_PRELOAD=/usr/lib/libjemalloc.so RAILS_ENV=${RAILS_ENV:=development} bundle exec rake $PARAMS" docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/sidekiq b/bin/docker/sidekiq index 8c90d5e98d5..cfb36311aa2 100755 --- a/bin/docker/sidekiq +++ b/bin/docker/sidekiq @@ -1,5 +1,5 @@ #!/bin/bash PARAMS="$@" -CMD="cd /src && RAILS_ENV=${RAILS_ENV:=development} bundle exec sidekiq -q critical -q low -q default" +CMD="cd /src && USER=discourse RAILS_ENV=${RAILS_ENV:=development} bundle exec sidekiq -q critical -q low -q default" docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD" diff --git a/bin/docker/unicorn b/bin/docker/unicorn new file mode 100755 index 00000000000..ba615c09549 --- /dev/null +++ b/bin/docker/unicorn @@ -0,0 +1,10 @@ +#!/bin/bash + +PARAMS="$@" +if [[ $# = 1 ]] && [[ "$1" =~ "s" ]]; +then + PARAMS="$PARAMS -b 0.0.0.0" +fi + +CMD="cd /src && USER=discourse RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 LD_PRELOAD=/usr/lib/libjemalloc.so RAILS_ENV=${RAILS_ENV:=development} bin/unicorn $PARAMS" +docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD"