-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker for development setup (first version)
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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 | ||
|
||
ENV RAILS_ENV="development" \ | ||
BUNDLE_PATH="/gems" \ | ||
LANG=C.UTF-8 \ | ||
BUNDLE_JOBS=10 \ | ||
BUNDLE_RETRY=3 | ||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as build | ||
|
||
# Install packages needed to build gems and node modules | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y build-essential curl git libpq-dev node-gyp pkg-config python-is-python3 | ||
|
||
# Install JavaScript dependencies | ||
ARG NODE_VERSION=18.16.0 | ||
ARG YARN_VERSION=1.22.19 | ||
ENV PATH=/usr/local/node/bin:$PATH | ||
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \ | ||
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \ | ||
npm install -g yarn@$YARN_VERSION && \ | ||
rm -rf /tmp/node-build-master | ||
|
||
# Install application gems | ||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle install && \ | ||
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git | ||
|
||
# Install node modules | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install --frozen-lockfile | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
# 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 tmp | ||
USER rails:rails | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD ["./bin/rails", "server"] |
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,45 @@ | ||
version: '3.7' | ||
|
||
x-backend: &backend | ||
stdin_open: true | ||
tty: true | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile.development | ||
volumes: | ||
- .:/rails | ||
- node_modules:/rails/node_modules | ||
- gem_cache:/gems | ||
depends_on: | ||
- database | ||
entrypoint: ./bin/docker-entrypoint | ||
|
||
services: | ||
rails: | ||
<<: *backend | ||
ports: | ||
- '3000:3000' | ||
environment: | ||
- RUBY_DEBUG_OPEN=true | ||
- DATABASE_URL=postgres://postgres:postgres@database:5432 | ||
command: ./bin/rails server -b 0.0.0.0 | ||
|
||
js: | ||
<<: *backend | ||
command: yarn build --watch | ||
|
||
css: | ||
<<: *backend | ||
command: yarn build:css --watch | ||
|
||
database: | ||
image: 'postgres:15' | ||
volumes: | ||
- postgres:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
|
||
volumes: | ||
postgres: | ||
gem_cache: | ||
node_modules: |