-
Notifications
You must be signed in to change notification settings - Fork 71
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 #23 from zakariaf/dockerize
Add Docker configs for production
- Loading branch information
Showing
18 changed files
with
609 additions
and
136 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,46 @@ | ||
.git/ | ||
|
||
# Ignore bundler config. | ||
/.bundle | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/* | ||
/tmp/* | ||
!/log/.keep | ||
!/tmp/.keep | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Ignore pidfiles, but keep the directory. | ||
/tmp/pids/* | ||
!/tmp/pids/ | ||
!/tmp/pids/.keep | ||
|
||
# Ignore uploaded files in development. | ||
/storage/* | ||
!/storage/.keep | ||
/tmp/storage/* | ||
!/tmp/storage/ | ||
!/tmp/storage/.keep | ||
|
||
/public/assets | ||
|
||
# Ignore master key for decrypting credentials and more. | ||
/config/master.key | ||
|
||
/app/assets/builds/* | ||
!/app/assets/builds/.keep | ||
|
||
# Ignore SampleCov files | ||
/coverage/* | ||
|
||
# Vite Ruby | ||
/public/vite* | ||
node_modules | ||
# Vite uses dotenv and suggests to ignore local-only env files. See | ||
# https://vitejs.dev/guide/env-and-mode.html#env-files | ||
*.local | ||
|
||
# Ignore uncategorized files | ||
.DS_Store |
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,83 @@ | ||
|
||
# Rather than use the directory name, let's control the name of the project. | ||
export COMPOSE_PROJECT_NAME=baseapp | ||
|
||
# Which environment is running? These should be "development" or "production". | ||
|
||
# About COMPOSE_PROFILES: https://docs.docker.com/compose/profiles/ | ||
# In development we want all services to start but in production you don't | ||
# need the asset watchers to run since assets get built into the image. | ||
# | ||
export RAILS_ENV=production | ||
export COMPOSE_PROFILES=postgres,redis,web,worker,cable | ||
|
||
# Should Docker restart your containers if they go down in unexpected ways? | ||
export DOCKER_RESTART_POLICY=unless-stopped | ||
# export DOCKER_RESTART_POLICY=no | ||
|
||
# What ip:port should be published back to the Docker host for the app server? | ||
# If you're using Docker Toolbox or a custom VM you can't use 127.0.0.1. This | ||
# is being overwritten in dev to be compatible with more dev environments. | ||
# | ||
# If you have a port conflict because something else is using 3000 then you | ||
# can either stop that process or change 3000 to be something else. | ||
# | ||
# Use the default in production to avoid having puma directly accessible to | ||
# the internet since it'll very likely be behind nginx or a load balancer. | ||
export DOCKER_WEB_PORT_FORWARD=127.0.0.1:3000 | ||
# export DOCKER_WEB_PORT_FORWARD=3000 | ||
|
||
# This is the same as above except for Action Cable. | ||
export DOCKER_CABLE_PORT_FORWARD=127.0.0.1:28080 | ||
# export DOCKER_CABLE_PORT_FORWARD=28080 | ||
|
||
# What CPU and memory constraints will be added to your services? When left at | ||
# 0 they will happily use as much as needed. | ||
# export DOCKER_POSTGRES_CPUS=0 | ||
# export DOCKER_POSTGRES_MEMORY=0 | ||
# export DOCKER_REDIS_CPUS=0 | ||
# export DOCKER_REDIS_MEMORY=0 | ||
# export DOCKER_WEB_CPUS=0 | ||
# export DOCKER_WEB_MEMORY=0 | ||
# export DOCKER_WORKER_CPUS=0 | ||
# export DOCKER_WORKER_MEMORY=0 | ||
# export DOCKER_CABLE_CPUS=0 | ||
# export DOCKER_CABLE_MEMORY=0 | ||
|
||
## Secret keys | ||
# You can use `rails secret` command to generate a secret key | ||
export SECRET_KEY_BASE=insecure-key | ||
export DEVISE_JWT_SECRET_KEY=my-jwt-secret-key | ||
|
||
## Host | ||
export DEFAULT_HOST=localhost | ||
|
||
## Action cable | ||
export ACTION_CABLE_URL=ws://localhost:28080 | ||
export ACTION_CABLE_ALLOWED_REQUEST_ORIGINS=http:\/\/localhost* | ||
# Examples: | ||
# http:\/\/localhost* | ||
# http:\/\/example.*,https:\/\/example.* | ||
|
||
## Puma | ||
# export PORT=3000 | ||
|
||
## Workers and threads count | ||
export WEB_CONCURRENCY=2 | ||
export RAILS_MAX_THREADS=5 | ||
export RAILS_MIN_THREADS=5 | ||
|
||
## Postgres | ||
export POSTGRES_HOST=postgres | ||
export POSTGRES_PORT=5432 | ||
export POSTGRES_USER=baseapp | ||
export POSTGRES_PASSWORD=postgres | ||
export POSTGRES_DB=baseapp | ||
|
||
## Redis URL | ||
export REDIS_URL=redis://redis:6379/1 | ||
export REDIS_CHANNEL_PREFIX=baseapp | ||
|
||
# Sidekiq web | ||
export SIDEKIQ_WEB_USERNAME=sidekiq-web-dashboard | ||
export SIDEKIQ_WEB_PASSWORD=sidekiq-web-123 |
This file was deleted.
Oops, something went wrong.
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,4 +1,6 @@ | ||
|
||
# This file will be used by github workflows | ||
|
||
## Host | ||
export DEFAULT_HOST=localhost | ||
|
||
|
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,69 @@ | ||
ARG RUBY_VERSION | ||
ARG IMAGE_FLAVOUR=alpine | ||
|
||
FROM ruby:$RUBY_VERSION-$IMAGE_FLAVOUR AS base | ||
|
||
# Install system dependencies required both at runtime and build time | ||
ARG NODE_VERSION | ||
ARG YARN_VERSION | ||
RUN apk add --update \ | ||
git \ | ||
postgresql-dev \ | ||
tzdata \ | ||
nodejs=$NODE_VERSION \ | ||
yarn=$YARN_VERSION | ||
|
||
###################################################################### | ||
|
||
# This stage will be responsible for installing gems and npm packages | ||
FROM base AS dependencies | ||
|
||
# Install system dependencies required to build some Ruby gems (pg) | ||
RUN apk add --update build-base | ||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
COPY .ruby-version Gemfile Gemfile.lock ./ | ||
|
||
# Install gems | ||
ARG RAILS_ENV | ||
ENV RAILS_ENV="${RAILS_ENV}" \ | ||
NODE_ENV="development" | ||
|
||
RUN bundle config set without "development test" | ||
RUN bundle install --jobs "$(nproc)" --retry "$(nproc)" | ||
|
||
COPY package.json yarn.lock ./ | ||
|
||
# Install npm packages | ||
RUN yarn install --frozen-lockfile | ||
|
||
COPY . ./ | ||
|
||
RUN SECRET_KEY_BASE=irrelevant DEVISE_JWT_SECRET_KEY=irrelevant bundle exec rails assets:precompile | ||
|
||
###################################################################### | ||
|
||
# We're back at the base stage | ||
FROM base AS app | ||
|
||
# Create a non-root user to run the app and own app-specific files | ||
RUN adduser -D app | ||
|
||
# Switch to this user | ||
USER app | ||
|
||
# We'll install the app in this directory | ||
WORKDIR /app | ||
|
||
# Copy over gems from the dependencies stage | ||
COPY --from=dependencies /usr/local/bundle/ /usr/local/bundle/ | ||
COPY --chown=app --from=dependencies /app/public/ /app/public/ | ||
|
||
# Finally, copy over the code | ||
# This is where the .dockerignore file comes into play | ||
# Note that we have to use `--chown` here | ||
COPY --chown=app . ./ | ||
|
||
# Launch the server | ||
CMD ["rails", "s"] |
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
Oops, something went wrong.