Skip to content

Fixing Thruster port binding #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2024
Merged
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
6 changes: 5 additions & 1 deletion lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ def procfile
nginx: '/usr/sbin/nginx -g "daemon off;"',
rails: "./bin/rails server -p 3001"
}
elsif options.thruster? || @gemfile.include?("thruster")
elsif using_thruster?
{
rails: "bundle exec thrust ./bin/rails server"
}
Expand All @@ -1180,6 +1180,10 @@ def procfile
end
end

def using_thruster?
options.thruster? || @gemfile.include?("thruster")
end

def fly_processes
return unless File.exist? "fly.toml"
return unless using_sidekiq? || using_solidq?
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/Dockerfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ EOF

<% end -%>
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
EXPOSE <%= using_thruster? ? '80' : '3000' %>
<% if deploy_database == 'sqlite3' -%>
VOLUME /data
<% end -%>
Expand Down
72 changes: 72 additions & 0 deletions test/results/thruster/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# syntax = docker/dockerfile:1

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

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development:test" \
RAILS_ENV="production"

# 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
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential pkg-config

# 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

# 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=1 ./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 curl libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
mkdir /data && \
chown -R 1000:1000 db log storage tmp /data
USER 1000:1000

# Deployment options
ENV DATABASE_URL="sqlite3:///data/production.sqlite3"

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 80
VOLUME /data
CMD ["bundle", "exec", "thrust", "./bin/rails", "server"]
11 changes: 11 additions & 0 deletions test/test_thruster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require_relative "base"

class TestThruster < TestBase
@generate_options = "--thruster"

def test_thruster
check_dockerfile
end
end
Loading