-
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.
Add Docker and Docker Compose configuration.
- Loading branch information
1 parent
cdc39df
commit 2f8d320
Showing
4 changed files
with
162 additions
and
4 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,15 @@ | ||
.dockerignore | ||
.ruby-version | ||
Dockerfile | ||
LICENSE | ||
Procfile | ||
Procfile.dev | ||
README.markdown | ||
docker-compose.yml | ||
.github/ | ||
.ruby-lsp/ | ||
coverage/ | ||
public/assets | ||
node_modules/ | ||
log/ | ||
tmp/ |
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,101 @@ | ||
ARG ENVIRONMENT="production" | ||
ARG NODE_VERSION="20.16.0" | ||
ARG RUBY_VERSION="3.3.4" | ||
|
||
FROM node:$NODE_VERSION-alpine3.20 AS node-builder | ||
|
||
# Set environment variables. | ||
ENV NODE_ENV=${ENVIRONMENT} | ||
|
||
# Change to a build working directory. | ||
WORKDIR /build | ||
|
||
# Copy the package into Docker. | ||
COPY .yarnrc.yml package.json yarn.lock . | ||
COPY .yarn .yarn | ||
|
||
# Install the Node.js dependencies. | ||
RUN yarn install --immutable | ||
|
||
# Copy in files for assets precompilation. | ||
COPY app/assets app/assets | ||
COPY app/javascript app/javascript | ||
COPY config/esbuild.config.js config/esbuild.config.js | ||
COPY config/locales/en.yml config/locals/en.yml | ||
|
||
# Build the assets. | ||
RUN yarn build | ||
|
||
# Remove dependencies. | ||
RUN rm -rf node_modules | ||
|
||
FROM ruby:$RUBY_VERSION-alpine3.20 AS ruby-builder | ||
|
||
# Accept optional arguments. | ||
ARG BUNDLE_WITHOUT="development test" | ||
|
||
# Set environment variables. | ||
ENV BUNDLE_WITHOUT=${BUNDLE_WITHOUT} \ | ||
RAILS_ENV=${ENVIRONMENT} \ | ||
REMOVE_JS_BUILD_YARN_INSTALL=true | ||
|
||
# Install build dependency requirements. | ||
RUN apk -U upgrade \ | ||
&& apk add --no-cache build-base libpq-dev libxml2-dev libxslt-dev tzdata | ||
|
||
# Change to a build working directory. | ||
WORKDIR /build | ||
|
||
# Configure Bundler. | ||
RUN bundle config --local build.nokogiri --use-system-libraries \ | ||
&& bundle config --local without "${BUNDLE_WITHOUT}" \ | ||
&& bundle config --local frozen "true" | ||
|
||
# Copy the Gemfile into Docker. | ||
COPY Gemfile Gemfile.lock . | ||
|
||
# Install the Bundler version specified. | ||
RUN gem install bundler -v $(tail -n1 Gemfile.lock) | ||
|
||
# Install the Ruby dependencies. | ||
RUN bundle install | ||
|
||
FROM ruby:$RUBY_VERSION-alpine3.20 AS application | ||
|
||
# Set environment variables. | ||
ENV NODE_ENV=${ENVIRONMENT} \ | ||
RAILS_ENV=${ENVIRONMENT} \ | ||
LD_PRELOAD="libjemalloc.so.2" \ | ||
RUBY_YJIT_ENABLE="1" | ||
|
||
# Install dependency requirements. | ||
RUN apk -U upgrade \ | ||
&& apk add --no-cache jemalloc libpq-dev tzdata | ||
|
||
# Create a application-specific user. | ||
RUN addgroup -S runner \ | ||
&& adduser -S runner -G runner | ||
|
||
# Switch to the user. | ||
USER runner | ||
|
||
# Create the application directory. | ||
RUN mkdir -p /home/runner/app | ||
WORKDIR /home/runner/app | ||
|
||
# Copy the application into Docker. | ||
COPY --chown=runner . . | ||
|
||
# Copy in the assets, cache, and dependencies. | ||
COPY --chown=runner --from=node-builder /build/app/assets/builds app/assets/builds | ||
COPY --chown=runner --from=ruby-builder /usr/local/bundle /usr/local/bundle | ||
|
||
# Precompile the Bootsnap cache. | ||
RUN rm -rf tmp/cache | ||
RUN bundle exec bootsnap precompile --gemfile app/ lib/ | ||
|
||
# Expose the server. | ||
EXPOSE 3000 | ||
|
||
# Run the server. | ||
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"] |
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,31 @@ | ||
services: | ||
database: | ||
image: postgres:16.4-bookworm | ||
environment: | ||
POSTGRES_DB: miroha | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_USER: postgres | ||
ports: | ||
- 5432:5432 | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
application: | ||
platform: linux/x86_64 | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
target: application | ||
args: | ||
BUNDLE_WITHOUT: test | ||
ENVIRONMENT: development | ||
ports: | ||
- 3000:3000 | ||
environment: | ||
DATABASE_URL: postgres://postgres:postgres@database:5432/miroha | ||
depends_on: | ||
database: | ||
condition: service_healthy |