diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index 71abc377b..81408ef81 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -5,7 +5,7 @@ RUN apk add --no-cache python build-base COPY js . RUN yarn install \ - && yarn run build + && yarn run build # Then, build the application binary FROM elixir:alpine AS builder @@ -15,8 +15,8 @@ RUN apk add --no-cache build-base git cmake COPY mix.exs mix.lock ./ ENV MIX_ENV=prod RUN mix local.hex --force \ - && mix local.rebar --force \ - && mix deps.get + && mix local.rebar --force \ + && mix deps.get COPY lib ./lib COPY priv ./priv @@ -25,7 +25,7 @@ COPY docker/production/releases.exs ./config/ COPY --from=assets ./priv/static ./priv/static RUN mix phx.digest \ - && mix release + && mix release # Finally setup the app FROM alpine @@ -36,6 +36,6 @@ USER nobody EXPOSE 4000 COPY --from=builder --chown=nobody:nobody _build/prod/rel/mobilizon ./ +COPY docker/production/docker-entrypoint.sh ./ -ENTRYPOINT ["/bin/mobilizon"] -CMD ["start"] +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index 029a82871..30c3cec88 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -25,7 +25,7 @@ services: volumes: - ./public/uploads:/app/uploads ports: - - "4000:4000" + - "4000:4000" db: image: postgis/postgis diff --git a/docker/production/docker-entrypoint.sh b/docker/production/docker-entrypoint.sh new file mode 100755 index 000000000..9e118d45a --- /dev/null +++ b/docker/production/docker-entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +echo "-- Running migrations..." +/bin/mobilizon_ctl migrate + +echo "-- Starting!" +exec /bin/mobilizon start \ No newline at end of file diff --git a/rel/overlays/bin/mobilizon_ctl b/rel/overlays/bin/mobilizon_ctl new file mode 100755 index 000000000..458de578c --- /dev/null +++ b/rel/overlays/bin/mobilizon_ctl @@ -0,0 +1,41 @@ +#!/bin/sh +# Portions of this file are derived from Pleroma: +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +if [ -z "$1" ] || [ "$1" = "help" ]; then + echo "Usage: $(basename "$0") COMMAND [ARGS] + + The known commands are: + + migrate + Execute database migrations (needs to be done after updates) + + rollback [VERSION] + Rollback database migrations (needs to be done before downgrading) + + and any mix tasks under Mobilizon namespace, for example \`mix mobilizon.user.show COMMAND\` is + equivalent to \`$(basename "$0") user.show COMMAND\` + + By default mobilizon_ctl will try calling into a running instance to execute non migration-related commands, + if for some reason this is undesired, set MOBILIZON_CTL_RPC_DISABLED environment variable. + +" +else + SCRIPT=$(readlink -f "$0") + SCRIPTPATH=$(dirname "$SCRIPT") + + FULL_ARGS="$*" + + ACTION="$1" + if [ $# -gt 0 ]; then + shift + fi + + if [ "$ACTION" = "migrate" ] || [ "$ACTION" = "rollback" ] || [ "$ACTION" = "create" ] || [ "$MOBILIZON_CTL_RPC_DISABLED" = true ]; then + "$SCRIPTPATH"/mobilizon eval 'Mobilizon.CLI.run("'"$FULL_ARGS"'")' + else + "$SCRIPTPATH"/mobilizon rpc 'Mobilizon.CLI.run("'"$FULL_ARGS"'")' + fi +fi \ No newline at end of file