Skip to content

Commit 6d5d5a3

Browse files
committed
More work
1 parent a5a87d5 commit 6d5d5a3

3 files changed

Lines changed: 14 additions & 21 deletions

File tree

Dockerfile

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WORKDIR /rails
2020

2121
# Install base packages
2222
RUN apt-get update -qq && \
23-
apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq5 && \
23+
apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
2424
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
2525
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2626

@@ -52,10 +52,6 @@ COPY Gemfile Gemfile.lock ./
5252

5353
RUN bundle install && \
5454
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
55-
# Some gems (e.g. blanks) ship files as mode 600; the app runs as a
56-
# different UID at runtime (see config/deploy.qa.yml), so make sure
57-
# installed gems are readable regardless of owner.
58-
chmod -R a+rX "${BUNDLE_PATH}" && \
5955
# -j 1 disable parallel compilation to avoid a QEMU bug: https://github.com/rails/bootsnap/issues/495
6056
bundle exec bootsnap precompile -j 1 --gemfile
6157

@@ -79,20 +75,16 @@ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
7975
# Final stage for app image
8076
FROM base
8177

82-
# Run and own only the runtime files as a non-root user for security
83-
RUN groupadd --system --gid 1000 rails && \
84-
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash
85-
USER 1000:1000
78+
# Run and own only the runtime files as a non-root user for security. Matches
79+
# lyberadmin's uid:gid on the Puppet-managed deploy hosts (see config/deploy.qa.yml)
80+
# so no runtime --user override is needed there.
81+
RUN groupadd --system --gid 503 lyberadmin && \
82+
useradd lyberadmin --uid 503 --gid 503 --create-home --shell /bin/bash
83+
USER 503:503
8684

8785
# Copy built artifacts: gems, application
88-
COPY --chown=rails:rails --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
89-
COPY --chown=rails:rails --from=build /rails /rails
90-
91-
# Rails creates tmp/{cache,pids,sockets} at boot and writes log/production.log;
92-
# some destinations (see config/deploy.qa.yml) run the container as a different
93-
# UID than the image's baked-in rails user, so make these writable regardless
94-
# of runtime UID.
95-
RUN chmod -R a+rwX tmp log
86+
COPY --chown=lyberadmin:lyberadmin --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
87+
COPY --chown=lyberadmin:lyberadmin --from=build /rails /rails
9688

9789
# Entrypoint prepares the database.
9890
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

config/deploy.qa.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ servers:
2121
- argo-b3-qa-a.stanford.edu
2222
options:
2323
add-host: "host.docker.internal:host-gateway"
24-
# Overrides the image's baked-in rails (1000:1000) user so bind-mounted
25-
# writes (bulk actions, logs) land as lyberadmin, matching host ownership.
26-
user: "503:503"
2724
# Runs SolidQueue standalone (bin/jobs) rather than in-Puma, so it registers
2825
# its own graceful-shutdown signal handlers (see solid_queue/supervisor/signals.rb)
2926
# and can drain in-flight jobs on its own timeline, independent of the web
@@ -35,7 +32,6 @@ servers:
3532
stop_timeout: <%= ENV.fetch("SOLID_QUEUE_SHUTDOWN_TIMEOUT", 86400) %>
3633
options:
3734
add-host: "host.docker.internal:host-gateway"
38-
user: "503:503"
3935

4036
ssh:
4137
user: lyberadmin

config/deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ logging:
2121
max-size: "100m"
2222
max-file: "5"
2323

24+
aliases:
25+
console: app exec --interactive --reuse "bin/rails console -e p"
26+
db: app exec --interactive --reuse "bin/rails db -e p"
27+
shell: app exec --interactive --reuse "bash"
28+
2429
# Destination-specific configuration (servers, env, secrets, volumes) lives in
2530
# config/deploy.<destination>.yml, e.g. config/deploy.qa.yml. Run with:
2631
# bin/kamal deploy -d qa

0 commit comments

Comments
 (0)