Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
.git*
db/*.sqlite3
db/*.sqlite3-journal
.git
.gitignore
.bundle
.env
.env.*
!.env.sample
.ruby-lsp

config/application.yml
application.yml

log/*
tmp/*
Dockerfile
storage/*
coverage

vendor/bundle
node_modules

db/*.sqlite3
db/*.sqlite3-journal
dump.rdb
postgres-data*
redis-data
rails_database
rails_database.tar

spec
test
*.log
*.png?*
*.mp3?*

docker-compose*.yml
Dockerfile*
README.md
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ config/blog/.sass-cache

#local dev storage
/storage

/app/assets/builds
/app/assets/builds/*
!/app/assets/builds/.keep
5 changes: 2 additions & 3 deletions Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ install_plugin Capistrano::SCM::Git
#
# require 'capistrano/rvm'
require 'capistrano/rbenv'
require 'capistrano/nvm'
# require 'capistrano/chruby'
require 'capistrano/bundler'
# require 'capistrano/rails/assets'
Expand All @@ -34,7 +33,7 @@ require 'whenever/capistrano'

#require 'capistrano/cookbook/check_revision'
#require 'capistrano/cookbook/compile_assets_locally'
require 'capistrano/cookbook/create_database'
# require 'capistrano/cookbook/create_database'
#require 'capistrano/cookbook/logs'
#require 'capistrano/cookbook/monit'
#require 'capistrano/cookbook/nginx'
Expand All @@ -44,5 +43,5 @@ require 'capistrano/cookbook/create_database'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| load File.expand_path(r) }
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
163 changes: 113 additions & 50 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,63 +1,126 @@
FROM ubuntu:latest
# syntax=docker/dockerfile:1.7

# locale
# RUN locale-gen ja_JP.UTF-8 && \
# locale-gen en_US.UTF-8
# ENV LANG en_US.UTF-8
ARG RUBY_VERSION=3.3.10

ENV DEBIAN_FRONTEND noninteractive
ARG DOCKER_GROUP_ID
FROM ruby:${RUBY_VERSION}-slim-bookworm AS base

ENV APP_HOME=/home/rails/app \
BUNDLE_PATH=/usr/local/bundle \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3 \
LANG=C.UTF-8

RUN apt-get update && \
apt-get install --yes --no-install-recommends \
ca-certificates \
curl \
imagemagick \
libpq5 \
libtag1v5 \
libyaml-0-2 \
postgresql-client \
shared-mime-info \
sox \
libsox-fmt-mp3 \
webp && \
rm -rf /var/lib/apt/lists/* && \
groupadd --gid 1000 rails && \
useradd --create-home --uid 1000 --gid 1000 --shell /bin/bash rails && \
mkdir -p "${APP_HOME}" "${BUNDLE_PATH}" && \
chown rails:rails "${APP_HOME}" "${BUNDLE_PATH}"

WORKDIR ${APP_HOME}


# Installs native build dependencies and produces the production bundle/assets.
FROM base AS build

ARG BUNDLER_VERSION=2.5.22

RUN apt-get update && \
apt-get install --yes --no-install-recommends \
build-essential \
git \
libffi-dev \
libgdbm-dev \
libgmp-dev \
libpq-dev \
libssl-dev \
libtag1-dev \
libyaml-dev \
pkg-config \
rustc \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/*

COPY Gemfile Gemfile.lock ./

RUN gem install bundler --version "${BUNDLER_VERSION}" --no-document && \
bundle config set without "development test" && \
bundle install && \
rm -rf /root/.bundle "${BUNDLE_PATH}"/ruby/*/cache

COPY . .

RUN apt update
RUN apt upgrade -y
RUN apt-get install -y build-essential libtag1-dev libffi-dev \
xvfb firefox git curl sox libsox-fmt-mp3 libpq-dev imagemagick sudo postgresql-client
# Rails can compile assets without production credentials or a live database.
RUN SECRET_KEY_BASE_DUMMY=1 RAILS_ENV=production bundle exec rails assets:precompile && \
rm -rf tmp/cache

# for ruby
RUN apt-get install -y --force-yes autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev

# Immutable deployment image. It contains the application, bundle, and assets.
FROM base AS production

# RUN apt-get clean
ENV RAILS_ENV=production \
RACK_ENV=production \
RAILS_LOG_TO_STDOUT=true \
RAILS_SERVE_STATIC_FILES=true \
FALCON_BIND=http://0.0.0.0:3000 \
BUNDLE_WITHOUT="development:test"

# add user
RUN groupadd -g 1000 rails && useradd --create-home -s /bin/bash -u 1000 -g 1000 rails ;\
adduser rails sudo
RUN echo "Defaults !requiretty" >> /etc/sudoers
RUN echo "%sudo ALL=NOPASSWD: ALL" >> /etc/sudoers
RUN groupadd -g $DOCKER_GROUP_ID docker
RUN gpasswd -a rails docker
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=rails:rails ${APP_HOME} ${APP_HOME}

RUN mkdir -p log storage tmp/pids tmp/cache && \
chown -R rails:rails log storage tmp

USER rails
ENV HOME /home/rails
# Install rbenv and ruby-build
ENV RUBY_VERSION 3.2.2
RUN git clone https://github.com/rbenv/rbenv.git /home/rails/.rbenv
RUN git clone https://github.com/rbenv/ruby-build.git /home/rails/.rbenv/plugins/ruby-build
RUN echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> /home/rails/.bashrc
RUN echo 'eval "$(rbenv init -)"' >> /home/rails/.bashrc
ENV PATH /home/rails/.rbenv/bin:$PATH

ENV CONFIGURE_OPTS --disable-install-doc
RUN rbenv install $RUBY_VERSION
RUN rbenv global $RUBY_VERSION
RUN echo 'gem: --no-rdoc --no-ri' >> /home/rails/.gemrc
RUN rbenv exec gem update --system
RUN rbenv exec gem install bundler
RUN rbenv rehash
RUN rbenv exec bundle config --global github.https true

# Configure the main working directory. This is the base
# # directory used in any further RUN, COPY, and ENTRYPOINT
# # commands.
RUN mkdir -p /home/rails/app
WORKDIR /home/rails/app

# Expose port 3000 to the Docker host, so we can access it
# from the outside.

EXPOSE 3000

# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "falcon", "host", "config/falcon.rb"]


# Local development target. Source and gems remain bind-mounted by Compose.
FROM base AS development

ARG DOCKER_GROUP_ID
ARG BUNDLER_VERSION=2.5.22

RUN apt-get update && \
apt-get install --yes --no-install-recommends \
build-essential \
firefox-esr \
git \
libffi-dev \
libgdbm-dev \
libgmp-dev \
libpq-dev \
libssl-dev \
libtag1-dev \
libyaml-dev \
pkg-config \
rustc \
sudo \
xvfb \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/* && \
if [ -n "${DOCKER_GROUP_ID}" ]; then groupadd --gid "${DOCKER_GROUP_ID}" docker; else groupadd docker; fi && \
usermod --append --groups docker,sudo rails && \
printf '%%sudo ALL=(ALL) NOPASSWD: ALL\n' >/etc/sudoers.d/rails && \
gem install bundler --version "${BUNDLER_VERSION}" --no-document

USER rails

EXPOSE 3000

CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
19 changes: 16 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org/'

gem 'rails', '7.0.5'
gem 'rails', '7.1.6'
gem 'pg'

gem 'spring', group: :development
Expand Down Expand Up @@ -33,9 +33,8 @@ gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rbenv', "~>2.0"
gem 'capistrano-nvm', require: false
gem 'capistrano-sidekiq'
gem 'capistrano-cookbook', require: false, group: :development
# gem 'capistrano-cookbook', require: false, group: :development

group :test do
gem 'factory_bot_rails'
Expand Down Expand Up @@ -110,3 +109,17 @@ gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
gem "skylight"

gem "rubyzip"

gem "importmap-rails", "~> 2.2"

gem "propshaft", "~> 1.3"

gem "tailwindcss-rails"

gem "datastar", "~> 1.0"

gem "commonmarker", "~> 0.23"

gem "brotli"

gem "falcon"
Loading
Loading