Skip to content

Commit

Permalink
Merge pull request #11638 from nanaya/docker-entrypoint-script-2
Browse files Browse the repository at this point in the history
Simplify docker dev entrypoint script
  • Loading branch information
notbakaneko authored Nov 12, 2024
2 parents 7ea2286 + 5d93699 commit a0901ef
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
79 changes: 4 additions & 75 deletions docker/development/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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" .)
gid=$(stat -c "%g" .)

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 ./docker/development/run.sh "$@"
59 changes: 59 additions & 0 deletions docker/development/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh

export CHROME_BIN=/usr/bin/chromium
export DUSK_WEBDRIVER_BIN=/usr/bin/chromedriver

command=octane
if [ "$#" -gt 0 ]; then
command="$1"
shift
fi

# commands
_job() {
exec ./artisan queue:listen --queue=notification,default,beatmap_high,beatmap_default,store-notifications --tries=3 --timeout=1000
}

_migrate() {
./artisan db:create
exec ./artisan migrate:fresh-or-run
}

_octane() {
exec ./artisan octane:start --host=0.0.0.0 "$@"
}

_schedule() {
exec ./artisan schedule:work
}

_test() {
command=phpunit
if [ "$#" -gt 0 ]; then
command="$1"
shift
fi

case "$command" in
browser) _test_browser "$@";;
js) exec yarn karma start --single-run --browsers ChromeHeadless "$@";;
phpunit) exec ./bin/phpunit.sh "$@";;
esac
}

_test_browser() {
export APP_ENV=dusk.local
exec ./artisan dusk "$@"
}


_watch() {
yarn --network-timeout 100000
exec yarn watch
}

case "$command" in
artisan) exec ./artisan "$@";;
job|migrate|octane|schedule|test|watch) "_$command" "$@";;
*) exec "$command" "$@";;
esac

0 comments on commit a0901ef

Please sign in to comment.