Skip to content

Commit

Permalink
Merge pull request #2579 from ujh/prepare-for-prod-build
Browse files Browse the repository at this point in the history
Prepare for adding a production build
  • Loading branch information
ujh authored Dec 25, 2024
2 parents 36ba291 + 6420f58 commit 7b3cad6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ 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 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

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 && \
Expand Down Expand Up @@ -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 . .

Expand Down
19 changes: 19 additions & 0 deletions config/docker/dev-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
15 changes: 0 additions & 15 deletions config/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7b3cad6

Please sign in to comment.