diff --git a/Dockerfile b/Dockerfile index b33c540d8..636031df1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,9 @@ FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base WORKDIR /app +# The development stage is used to run the app locally as serves as the base for building the version +# that will contain the data for prod. +FROM base AS dev # Install base packages RUN apt-get update -qq && \ apt-get install --no-install-recommends -y curl libjemalloc2 libvips lsb-release gnupg2 && \ @@ -22,15 +25,10 @@ RUN apt-get update -qq && \ ENV BUNDLE_PATH="/usr/local/bundle" -# Throw-away build stage to reduce size of final image -# FROM base AS build - # Install Postgres 16, so that schema dumping works RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list - # Trust the PGDG gpg key RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc| gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg - # Install packages needed to build gems RUN apt-get update -qq && \ apt-get install --no-install-recommends -y build-essential git pkg-config libpq-dev postgresql-client-16 && \ @@ -60,6 +58,15 @@ RUN if [ $(uname -m) = "aarch64" ]; then NODE_ARCH=arm64 ; else NODE_ARCH=x64 ; RUN npm install --global yarn && ln -s /opt/nodejs/current/bin/yarn /usr/local/bin/yarn RUN yarn install +EXPOSE 80 + +# Entrypoint script always runs, even if command is overwritten +ENTRYPOINT ["/app/config/docker/dev-entrypoint.sh"] + +# CMD script doesn't run if command is overwritten (e.g. for migrations) +CMD ["bundle exec puma"] + +FROM dev AS build # Copy application code # COPY . . diff --git a/config/docker/dev-entrypoint.sh b/config/docker/dev-entrypoint.sh new file mode 100755 index 000000000..f3ea43f71 --- /dev/null +++ b/config/docker/dev-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/sh -ex + +cd /app + + +bundle check || bundle install || true + +if [[ $@ =~ 'yarn' ]] +then + yarn install --frozen-lockfile +else + # Remove a potentially pre-existing server.pid for Rails. + rm -rf /app/tmp/pids/server.pid +fi + +# Since we specified both an ENTRYPOINT and a CMD (which could be overwritten +# by a "command"), Docker passes the CMD/command to the ENTRYPOINT script as +# arguments. So we can run the CMD/command with exec "$@". +exec "$@" diff --git a/config/docker/entrypoint.sh b/config/docker/entrypoint.sh index f3ea43f71..427ec27e4 100755 --- a/config/docker/entrypoint.sh +++ b/config/docker/entrypoint.sh @@ -1,19 +1,4 @@ #!/bin/sh -ex cd /app - - -bundle check || bundle install || true - -if [[ $@ =~ 'yarn' ]] -then - yarn install --frozen-lockfile -else - # Remove a potentially pre-existing server.pid for Rails. - rm -rf /app/tmp/pids/server.pid -fi - -# Since we specified both an ENTRYPOINT and a CMD (which could be overwritten -# by a "command"), Docker passes the CMD/command to the ENTRYPOINT script as -# arguments. So we can run the CMD/command with exec "$@". exec "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 5aab5d24b..ced82d03f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,9 @@ x-rails: &rails pull_policy: never tty: true stdin_open: true - build: . + build: + context: . + target: dev environment: NODE_ENV: development PORT: 80