From 9dd697f86daa446dd38180fcf1a6531c223ed924 Mon Sep 17 00:00:00 2001 From: nanaya Date: Mon, 11 Nov 2024 17:52:08 +0900 Subject: [PATCH 1/6] Move docker/development/entrypoint.sh to docker/development/run.sh --- docker/development/{entrypoint.sh => run.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docker/development/{entrypoint.sh => run.sh} (100%) diff --git a/docker/development/entrypoint.sh b/docker/development/run.sh similarity index 100% rename from docker/development/entrypoint.sh rename to docker/development/run.sh From edb47268901d02f2ffcbb5664ae4a6db523b5d66 Mon Sep 17 00:00:00 2001 From: nanaya Date: Mon, 11 Nov 2024 17:52:08 +0900 Subject: [PATCH 2/6] Restore docker/development/entrypoint.sh --- docker/development/entrypoint.sh | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 docker/development/entrypoint.sh diff --git a/docker/development/entrypoint.sh b/docker/development/entrypoint.sh new file mode 100755 index 00000000000..9d23169e534 --- /dev/null +++ b/docker/development/entrypoint.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +set -e +set -u + +export CHROME_BIN=/usr/bin/chromium +export DUSK_WEBDRIVER_BIN=/usr/bin/chromedriver +export YARN_CACHE_FOLDER=/app/.docker/.yarn +export COMPOSER_HOME=/app/.docker/.composer + +command=octane +if [ "$#" -gt 0 ]; then + command="$1" + shift +fi + +uid="$(stat -c "%u" /app)" +gid="$(stat -c "%g" /app)" + +if [ "$uid" != 0 ]; then + usermod -u "$uid" -o osuweb > /dev/null + groupmod -g "$gid" -o osuweb > /dev/null +fi + +usermod -d /app/.docker osuweb > /dev/null +chown -f "${uid}:${gid}" .docker/js-build/assets .docker/js-build/builds || true + +# helper functions +_rexec() { + exec gosu osuweb "$@" +} + +_run() { + gosu osuweb "$@" +} + +# commands +_job() { + _rexec php /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 +} + +_migrate() { + _run php /app/artisan db:create + _rexec php /app/artisan migrate:fresh-or-run +} + +_octane() { + _rexec /app/artisan octane:start --host=0.0.0.0 "$@" +} + +_schedule() { + _rexec php /app/artisan schedule:work +} + +_test() { + command=phpunit + if [ "$#" -gt 0 ]; then + command="$1" + shift + fi + + case "$command" in + browser) _test_browser "$@";; + js) _rexec yarn karma start --single-run --browsers ChromeHeadless "$@";; + phpunit) _rexec ./bin/phpunit.sh "$@";; + esac +} + +_test_browser() { + export APP_ENV=dusk.local + _rexec php /app/artisan dusk "$@" +} + + +_watch() { + _run yarn --network-timeout 100000 + _rexec yarn watch +} + +case "$command" in + artisan) _rexec php /app/artisan "$@";; + job|migrate|octane|schedule|test|watch) "_$command" "$@";; + *) _rexec "$command" "$@";; +esac From 9a5f9a72f539f6d4d90823ae684037f0c7649de6 Mon Sep 17 00:00:00 2001 From: nanaya Date: Mon, 11 Nov 2024 17:52:49 +0900 Subject: [PATCH 3/6] Simplify docker dev entrypoint script --- Dockerfile.development | 2 +- docker/development/entrypoint.sh | 79 ++------------------------------ docker/development/run.sh | 47 +++++-------------- 3 files changed, 17 insertions(+), 111 deletions(-) diff --git a/Dockerfile.development b/Dockerfile.development index 0872a15e6c1..bab3289db8a 100644 --- a/Dockerfile.development +++ b/Dockerfile.development @@ -42,7 +42,7 @@ COPY chromium /usr/bin/ WORKDIR /app -RUN groupadd osuweb && useradd -g osuweb osuweb +RUN groupadd osuweb && useradd -g osuweb -d /app/.docker osuweb ENTRYPOINT ["/app/docker/development/entrypoint.sh"] CMD ["octane"] diff --git a/docker/development/entrypoint.sh b/docker/development/entrypoint.sh index 9d23169e534..2a64ac72c5f 100755 --- a/docker/development/entrypoint.sh +++ b/docker/development/entrypoint.sh @@ -1,84 +1,13 @@ #!/bin/sh -set -e -set -u - -export CHROME_BIN=/usr/bin/chromium -export DUSK_WEBDRIVER_BIN=/usr/bin/chromedriver -export YARN_CACHE_FOLDER=/app/.docker/.yarn -export COMPOSER_HOME=/app/.docker/.composer - -command=octane -if [ "$#" -gt 0 ]; then - command="$1" - shift -fi - -uid="$(stat -c "%u" /app)" -gid="$(stat -c "%g" /app)" +uid=$(stat -c "%u" /app) +gid=$(stat -c "%g" /app) if [ "$uid" != 0 ]; then usermod -u "$uid" -o osuweb > /dev/null groupmod -g "$gid" -o osuweb > /dev/null fi -usermod -d /app/.docker osuweb > /dev/null -chown -f "${uid}:${gid}" .docker/js-build/assets .docker/js-build/builds || true - -# helper functions -_rexec() { - exec gosu osuweb "$@" -} - -_run() { - gosu osuweb "$@" -} - -# commands -_job() { - _rexec php /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 -} - -_migrate() { - _run php /app/artisan db:create - _rexec php /app/artisan migrate:fresh-or-run -} - -_octane() { - _rexec /app/artisan octane:start --host=0.0.0.0 "$@" -} - -_schedule() { - _rexec php /app/artisan schedule:work -} - -_test() { - command=phpunit - if [ "$#" -gt 0 ]; then - command="$1" - shift - fi - - case "$command" in - browser) _test_browser "$@";; - js) _rexec yarn karma start --single-run --browsers ChromeHeadless "$@";; - phpunit) _rexec ./bin/phpunit.sh "$@";; - esac -} - -_test_browser() { - export APP_ENV=dusk.local - _rexec php /app/artisan dusk "$@" -} - - -_watch() { - _run yarn --network-timeout 100000 - _rexec yarn watch -} +chown -f "${uid}:${gid}" .docker/js-build/assets .docker/js-build/builds -case "$command" in - artisan) _rexec php /app/artisan "$@";; - job|migrate|octane|schedule|test|watch) "_$command" "$@";; - *) _rexec "$command" "$@";; -esac +exec gosu osuweb /app/docker/development/run.sh "$@" diff --git a/docker/development/run.sh b/docker/development/run.sh index 9d23169e534..ffa5bca3851 100755 --- a/docker/development/run.sh +++ b/docker/development/run.sh @@ -1,8 +1,5 @@ #!/bin/sh -set -e -set -u - export CHROME_BIN=/usr/bin/chromium export DUSK_WEBDRIVER_BIN=/usr/bin/chromedriver export YARN_CACHE_FOLDER=/app/.docker/.yarn @@ -14,42 +11,22 @@ if [ "$#" -gt 0 ]; then shift fi -uid="$(stat -c "%u" /app)" -gid="$(stat -c "%g" /app)" - -if [ "$uid" != 0 ]; then - usermod -u "$uid" -o osuweb > /dev/null - groupmod -g "$gid" -o osuweb > /dev/null -fi - -usermod -d /app/.docker osuweb > /dev/null -chown -f "${uid}:${gid}" .docker/js-build/assets .docker/js-build/builds || true - -# helper functions -_rexec() { - exec gosu osuweb "$@" -} - -_run() { - gosu osuweb "$@" -} - # commands _job() { - _rexec php /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 + exec php /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 } _migrate() { - _run php /app/artisan db:create - _rexec php /app/artisan migrate:fresh-or-run + php /app/artisan db:create + exec php /app/artisan migrate:fresh-or-run } _octane() { - _rexec /app/artisan octane:start --host=0.0.0.0 "$@" + exec /app/artisan octane:start --host=0.0.0.0 "$@" } _schedule() { - _rexec php /app/artisan schedule:work + exec php /app/artisan schedule:work } _test() { @@ -61,24 +38,24 @@ _test() { case "$command" in browser) _test_browser "$@";; - js) _rexec yarn karma start --single-run --browsers ChromeHeadless "$@";; - phpunit) _rexec ./bin/phpunit.sh "$@";; + js) exec yarn karma start --single-run --browsers ChromeHeadless "$@";; + phpunit) exec ./bin/phpunit.sh "$@";; esac } _test_browser() { export APP_ENV=dusk.local - _rexec php /app/artisan dusk "$@" + exec php /app/artisan dusk "$@" } _watch() { - _run yarn --network-timeout 100000 - _rexec yarn watch + yarn --network-timeout 100000 + exec yarn watch } case "$command" in - artisan) _rexec php /app/artisan "$@";; + artisan) exec php /app/artisan "$@";; job|migrate|octane|schedule|test|watch) "_$command" "$@";; - *) _rexec "$command" "$@";; + *) exec "$command" "$@";; esac From 459ec959c7b88eb69ea8f43fd12142ebc482e8a2 Mon Sep 17 00:00:00 2001 From: nanaya Date: Mon, 11 Nov 2024 17:54:30 +0900 Subject: [PATCH 4/6] Remove extra env Not needed anymore with home set to the correct directory. --- docker/development/run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker/development/run.sh b/docker/development/run.sh index ffa5bca3851..d2450797462 100755 --- a/docker/development/run.sh +++ b/docker/development/run.sh @@ -2,8 +2,6 @@ export CHROME_BIN=/usr/bin/chromium export DUSK_WEBDRIVER_BIN=/usr/bin/chromedriver -export YARN_CACHE_FOLDER=/app/.docker/.yarn -export COMPOSER_HOME=/app/.docker/.composer command=octane if [ "$#" -gt 0 ]; then From 48d761aae745c1ffa7eb36215c2eaafe23be27df Mon Sep 17 00:00:00 2001 From: nanaya Date: Mon, 11 Nov 2024 18:01:54 +0900 Subject: [PATCH 5/6] Artisan is executable already --- docker/development/run.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docker/development/run.sh b/docker/development/run.sh index d2450797462..4a8fca97fe6 100755 --- a/docker/development/run.sh +++ b/docker/development/run.sh @@ -11,12 +11,12 @@ fi # commands _job() { - exec php /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 + exec /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 } _migrate() { - php /app/artisan db:create - exec php /app/artisan migrate:fresh-or-run + /app/artisan db:create + exec /app/artisan migrate:fresh-or-run } _octane() { @@ -24,7 +24,7 @@ _octane() { } _schedule() { - exec php /app/artisan schedule:work + exec /app/artisan schedule:work } _test() { @@ -43,7 +43,7 @@ _test() { _test_browser() { export APP_ENV=dusk.local - exec php /app/artisan dusk "$@" + exec /app/artisan dusk "$@" } @@ -53,7 +53,7 @@ _watch() { } case "$command" in - artisan) exec php /app/artisan "$@";; + artisan) exec /app/artisan "$@";; job|migrate|octane|schedule|test|watch) "_$command" "$@";; *) exec "$command" "$@";; esac From f8e49f02033f85979c555e6b649fa37450d49cb7 Mon Sep 17 00:00:00 2001 From: nanaya Date: Mon, 11 Nov 2024 18:04:55 +0900 Subject: [PATCH 6/6] Assume correct directory everywhere --- docker/development/entrypoint.sh | 6 +++--- docker/development/run.sh | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docker/development/entrypoint.sh b/docker/development/entrypoint.sh index 2a64ac72c5f..197942bf7a4 100755 --- a/docker/development/entrypoint.sh +++ b/docker/development/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -uid=$(stat -c "%u" /app) -gid=$(stat -c "%g" /app) +uid=$(stat -c "%u" .) +gid=$(stat -c "%g" .) if [ "$uid" != 0 ]; then usermod -u "$uid" -o osuweb > /dev/null @@ -10,4 +10,4 @@ fi chown -f "${uid}:${gid}" .docker/js-build/assets .docker/js-build/builds -exec gosu osuweb /app/docker/development/run.sh "$@" +exec gosu osuweb ./docker/development/run.sh "$@" diff --git a/docker/development/run.sh b/docker/development/run.sh index 4a8fca97fe6..372b5991eb7 100755 --- a/docker/development/run.sh +++ b/docker/development/run.sh @@ -11,20 +11,20 @@ fi # commands _job() { - exec /app/artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 + exec ./artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000 } _migrate() { - /app/artisan db:create - exec /app/artisan migrate:fresh-or-run + ./artisan db:create + exec ./artisan migrate:fresh-or-run } _octane() { - exec /app/artisan octane:start --host=0.0.0.0 "$@" + exec ./artisan octane:start --host=0.0.0.0 "$@" } _schedule() { - exec /app/artisan schedule:work + exec ./artisan schedule:work } _test() { @@ -43,7 +43,7 @@ _test() { _test_browser() { export APP_ENV=dusk.local - exec /app/artisan dusk "$@" + exec ./artisan dusk "$@" } @@ -53,7 +53,7 @@ _watch() { } case "$command" in - artisan) exec /app/artisan "$@";; + artisan) exec ./artisan "$@";; job|migrate|octane|schedule|test|watch) "_$command" "$@";; *) exec "$command" "$@";; esac