Browse Source

Docker fixes

master
Christian Aust 1 year ago
parent
commit
c8da05f620
5 changed files with 46 additions and 37 deletions
  1. +13
    -1
      .dockerignore
  2. +25
    -32
      Dockerfile
  3. +1
    -1
      config/database.yml
  4. +2
    -2
      config/environments/production.rb
  5. +5
    -1
      config/storage.yml

+ 13
- 1
.dockerignore View File

@ -1,8 +1,20 @@
.git
# OSX specific
.DS_Store
# Ruby/Rails specific
.bundle
.ruby-*
node_modules
public/assets
storage/*
tmp
log/*
db/*.sqlite3
# other
.git
.gitignore
LICENSE
VERSION
README.md
docker-compose.yml

+ 25
- 32
Dockerfile View File

@ -1,46 +1,39 @@
FROM ruby:2.5.5-alpine
# Set local timezone
RUN apk add --update tzdata && \
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
echo "Europe/Berlin" > /etc/timezone
# Install your app's runtime dependencies in the container
RUN apk add --virtual runtime-deps nodejs libffi-dev readline sqlite sqlite-libs imagemagick
# Do not install gem documentation
RUN echo 'gem: --no-ri --no-rdoc' > ~/.gemrc
RUN gem install bundler
# Bundle into the temp directory
WORKDIR /tmp
ADD Gemfile* ./
# Install Yarn and others
ENV PATH=/root/.yarn/bin:$PATH
RUN apk add --virtual build-yarn curl && \
touch ~/.bashrc && \
curl -o- -L https://yarnpkg.com/install.sh | sh && \
apk del build-yarn && \
apk add --virtual build-deps build-base openssl-dev libc-dev linux-headers libxml2-dev libxslt-dev readline-dev sqlite-dev
RUN bundle install --without development test && \
apk del build-deps && \
rm -rf /var/cache/apk/*
# Configure production environment variables
ENV APP_HOME=/app \
ENV PATH=/root/.yarn/bin:$PATH \
APP_HOME=/app \
RAILS_ENV=production \
RACK_ENV=production
RACK_ENV=production \
RAILS_LOG_TO_STDOUT=1 \
RAILS_SERVE_STATIC_FILES=1
RUN apk add --update tzdata; \
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime; \
echo "Europe/Berlin" > /etc/timezone; \
echo "gem: --no-ri --no-rdoc" > ~/.gemrc; \
gem install bundler; \
apk add --virtual runtime-deps bash nodejs sqlite sqlite-libs imagemagick; \
apk add --virtual build-yarn curl; \
touch ~/.bashrc; \
curl -o- -L https://yarnpkg.com/install.sh | sh; \
apk del build-yarn; \
apk add --virtual build-deps build-base libxml2-dev libxslt-dev sqlite-dev; \
bundle install --without development test; \
bundle clean; \
apk del build-deps; \
rm -rf /var/cache/apk/*
# Copy the app's code into the container
COPY . $APP_HOME
WORKDIR $APP_HOME
RUN bundle exec rake assets:precompile
RUN rake assets:precompile; \
rm -Rf ./node_modules ./tmp/cache/* /tmp/*
# Expose port 3000 from the container
VOLUME $APP_HOME/data
EXPOSE 3000
# Run puma server by default
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
CMD ["rails", "server", "-b", "0.0.0.0", "-e", "production"]

+ 1
- 1
config/database.yml View File

@ -22,4 +22,4 @@ test:
production:
<<: *default
database: db/production.sqlite3
database: data/db/production.sqlite3

+ 2
- 2
config/environments/production.rb View File

@ -39,7 +39,7 @@ Rails.application.configure do
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
config.active_storage.service = :docker
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
@ -84,7 +84,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = Logger.new('/proc/1/fd/1')
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

+ 5
- 1
config/storage.yml View File

@ -6,7 +6,11 @@ local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
docker:
service: Disk
root: <%= Rails.root.join("data/storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>

Loading…
Cancel
Save