Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed May 19, 2023
1 parent 8ede7d7 commit 3bedaf9
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.

# Ignore git directory.
/.git/

# Ignore bundler config.
/.bundle

# Ignore all default key files.
/config/master.key
/config/credentials/*.key

# Ignore all environment files.
/.env*
!/.env.example

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets
82 changes: 82 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.1.0
FROM ruby:$RUBY_VERSION-slim as base

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_WITHOUT="development:test" \
BUNDLE_DEPLOYMENT="1"

# Update gems and bundler
RUN gem update --system --no-document && \
gem install -N bundler


# 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 libpq-dev libvips node-gyp pkg-config python-is-python3

# Install Node.js
ARG NODE_VERSION=12.x
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 && \
rm -rf /tmp/node-build-master

# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
bundle exec bootsnap precompile --gemfile && \
rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git

# Install node modules
COPY --link package.json ./
RUN npm install

# Copy application code
COPY --link . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile


# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y imagemagick libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

# 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 storage tmp
USER rails:rails

# Deployment options
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true"

# 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"]
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ source "https://#{ENV['AVO_GEM_TOKEN']}@packager.fly.dev/avo-hq-beta/" do
gem "avo_dashboards"
end


# gem "avo", path: "/Users/adrian/work/avocado/gems/avo"
# gem "avo_pro", path: "/Users/adrian/work/avocado/gems/avo_pro"
# gem "avo_advanced", path: "/Users/adrian/work/avocado/gems/avo_advanced"
Expand Down Expand Up @@ -140,3 +141,5 @@ gem 'countries'
gem 'sprockets'
gem 'activestorage'
gem 'mapkick-rb'

gem "dockerfile-rails", ">= 1.3", :group => :development
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ GEM
responders
warden (~> 1.2.3)
docile (1.4.0)
dockerfile-rails (1.3.0)
rails
dotenv (2.7.6)
dotenv-rails (2.7.6)
dotenv (= 2.7.6)
Expand Down Expand Up @@ -250,6 +252,8 @@ GEM
net-protocol
newrelic_rpm (8.6.0)
nio4r (2.5.9)
nokogiri (1.15.0-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.0-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.0-x86_64-darwin)
Expand Down Expand Up @@ -324,6 +328,8 @@ GEM
sprockets (>= 3.0.0)
stimulus-rails (1.1.0)
railties (>= 6.0.0)
tailwindcss-rails (2.0.8-aarch64-linux)
railties (>= 6.0.0)
tailwindcss-rails (2.0.8-arm64-darwin)
railties (>= 6.0.0)
tailwindcss-rails (2.0.8-x86_64-darwin)
Expand Down Expand Up @@ -361,6 +367,7 @@ GEM
zeitwerk (2.6.8)

PLATFORMS
aarch64-linux
arm64-darwin-21
x86_64-darwin-21
x86_64-linux
Expand Down Expand Up @@ -389,6 +396,7 @@ DEPENDENCIES
countries
debug
devise
dockerfile-rails (>= 1.3)
dotenv-rails
factory_bot_rails
faker
Expand Down
8 changes: 8 additions & 0 deletions bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

# If running the rails server then create or migrate existing database
if [ "${*}" == "./bin/rails server" ]; then
./bin/rails db:prepare
fi

exec "${@}"
6 changes: 6 additions & 0 deletions config/dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# generated by dockerfile-rails

---
options:
label:
fly_launch_runtime: rails
47 changes: 47 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# fly.toml app configuration file generated for avodemo on 2023-05-19T21:42:47+03:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "avodemo"
kill_signal = "SIGINT"
kill_timeout = 5
primary_region = "mia"
processes = []

[build]

[env]

[experimental]
auto_rollback = true

[[services]]
http_checks = []
internal_port = 3000
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

[[statics]]
guest_path = "/rails/public"
url_prefix = "/"

0 comments on commit 3bedaf9

Please sign in to comment.