DEV: improve docker dev environment

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)

diff --git a/bin/docker/boot_dev b/bin/docker/boot_dev
index 65f92a3..125e959 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 1d1005c..73d39ab 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 f1f258d..385dcbb 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 4cdc94f..be9e9eb 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 c9542d0..c25c840 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 1c35b78..4836d47 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 146a824..b1b73b7 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 8c90d5e..cfb3631 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 0000000..ba615c0
--- /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"

GitHub
sha: fef45789

This commit has been mentioned on Discourse Meta. There might be relevant details there: