Skip to content

Commit

Permalink
Simplify docker dev entrypoint script
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Nov 11, 2024
1 parent 546b4d9 commit 9a5f9a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 111 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" /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 "$@"
47 changes: 12 additions & 35 deletions docker/development/run.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand All @@ -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

0 comments on commit 9a5f9a7

Please sign in to comment.