-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from nestauk/add-docker
Add docker
- Loading branch information
Showing
6 changed files
with
91 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,25 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | ||
ARG RUBY_VERSION=3.2.2 | ||
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base | ||
|
||
# Rails app lives here | ||
WORKDIR /rails | ||
|
||
# Set production environment | ||
ENV RAILS_ENV="production" \ | ||
BUNDLE_DEPLOYMENT="1" \ | ||
BUNDLE_PATH="/usr/local/bundle" \ | ||
BUNDLE_WITHOUT="development" | ||
|
||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as build | ||
|
||
# Install packages needed to build gems | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config | ||
|
||
# Install application gems | ||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle install && \ | ||
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ | ||
bundle exec bootsnap precompile --gemfile | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
# Precompile bootsnap code for faster boot times | ||
RUN bundle exec bootsnap precompile app/ lib/ | ||
|
||
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY | ||
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile | ||
FROM ruby:$RUBY_VERSION | ||
|
||
# Setup default directory | ||
RUN mkdir /var/source | ||
WORKDIR /var/source | ||
|
||
# Final stage for app image | ||
FROM base | ||
# Install rails and dependencies | ||
RUN gem install rails bundler | ||
|
||
# Install packages needed for deployment | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y curl libvips postgresql-client && \ | ||
rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
# Install the Heroku CLI | ||
RUN curl https://cli-assets.heroku.com/install-ubuntu.sh | sh | ||
|
||
# Copy built artifacts: gems, application | ||
COPY --from=build /usr/local/bundle /usr/local/bundle | ||
COPY --from=build /rails /rails | ||
# Install node 22 | ||
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash | ||
RUN apt-get install -y nodejs | ||
|
||
# Run and own only the runtime files as a non-root user for security | ||
RUN useradd rails --create-home --shell /bin/bash && \ | ||
chown -R rails:rails db log storage tmp | ||
USER rails:rails | ||
# Install playwright driver | ||
RUN npx playwright install chromium --with-deps | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
COPY docker/rails_entrypoint.sh /entrypoint.sh | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD ["./bin/rails", "server"] | ||
ENTRYPOINT [ "/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
services: | ||
app.local: | ||
build: . | ||
restart: unless-stopped | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- ".:/var/source" | ||
- "./storage/bundle:/usr/local/bundle" | ||
environment: | ||
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true | ||
DATABASE_URL: "postgres://pgsql:password@pgsql:5432" | ||
USE_MAILHOG: true | ||
MAILHOG_HOST: mailhog | ||
SYSTEM_TEST_DRIVER: playwright | ||
depends_on: | ||
- pgsql | ||
|
||
pgsql: | ||
image: postgres | ||
restart: unless-stopped | ||
ports: | ||
- 5433:5432 | ||
volumes: | ||
- ./storage/postgres:/var/lib/postgresql/data | ||
- ./docker/postgres_setup.sql:/docker-entrypoint-initdb.d/10-database-setup.sql | ||
environment: | ||
POSTGRES_USER: pgsql | ||
POSTGRES_PASSWORD: password | ||
|
||
tailwind: | ||
build: . | ||
entrypoint: /var/source/bin/rails tailwindcss:watch[always] | ||
restart: unless-stopped | ||
volumes: | ||
- ".:/var/source" | ||
- "./storage/bundle:/usr/local/bundle" | ||
depends_on: | ||
- app.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE DATABASE afs_tiny_happy_people_development; | ||
CREATE DATABASE afs_tiny_happy_people_test; | ||
CREATE DATABASE afs_tiny_happy_people_production; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# Ensure the correct dependencies are installed | ||
if ! bundler check | grep "The Gemfile's dependencies are satisfied" | ||
then | ||
bundler install | ||
fi | ||
|
||
# Remove server lock file | ||
rm /var/source/tmp/pids/server.pid | ||
|
||
/var/source/bin/rails server -b 0.0.0.0 |