Skip to content

Commit

Permalink
Switch from Render.com to Kamal on private server.
Browse files Browse the repository at this point in the history
Dockerize the website and test app.
Upgrade to Rails 7.1.
Fix show_exceptions setting for Rails 7.1.
Fix ransack for rails 7.1.
Fix simplecov for Rails 7.1.
Fix issue where simplecov is imported in non-test processes.
Add solid_queue to test it out in case we need scheduled jobs in the
website.
Refactor GH action pipeline to deploy using Kamal to private server.
Upgrade some actions to fix some node 16 errors.
  • Loading branch information
gregschmit committed Mar 22, 2024
1 parent d7ad8d4 commit fc51df5
Show file tree
Hide file tree
Showing 32 changed files with 733 additions and 226 deletions.
51 changes: 33 additions & 18 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby/Gems
uses: ruby/setup-ruby@v1
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run code checks
Expand All @@ -19,7 +17,7 @@ jobs:
fail-fast: false
matrix:
ruby: [2.7.5, 3.0.6, 3.1.4, 3.2.2]
rails: [6.0.6, 6.1.7, 7.0.4]
rails: [6.0.6, 6.1.7, 7.0.4, 7.1.3]
exclude:
- ruby: 3.1.4
rails: 6.0.6
Expand All @@ -29,12 +27,10 @@ jobs:
RAILS_VERSION: ${{ matrix.rails }}
CUSTOM_RUBY_VERSION: ${{ matrix.ruby }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Remove `Gemfile.lock` because this is a matrix job
run: rm Gemfile.lock
- name: Install Ruby/Gems
uses: ruby/setup-ruby@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
Expand All @@ -44,7 +40,7 @@ jobs:
run: BACKTRACE=1 bin/rails test
- name: Check if coverage LCOV file exists
id: lcov_exists
uses: andstor/file-existence-action@v2
uses: andstor/file-existence-action@v3
with:
files: coverage/lcov.info
- name: Submit coverage to `coveralls.io` if LCOV file exists
Expand All @@ -57,23 +53,42 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
steps:
- name: Trigger render.com deploy hook
run: curl -X POST '${{ secrets.RENDER_COM_DEPLOY_HOOK }}'
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.APPSERVER_DEPLOY_SSH_KEY }}
- name: Setup appserver known_hosts
run: cat config/appserver.known_hosts >> ~/.ssh/known_hosts
- name: Set up Docker Buildx for cache
uses: docker/setup-buildx-action@v3
- name: Expose GitHub Runtime for cache
uses: crazy-max/ghaction-github-runtime@v3
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Build and deploy using Kamal
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bundle exec kamal deploy
release:
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Ensure latest tag is fetched
run: git fetch --unshallow --prune --tags --force
- name: Install Ruby/Gems
uses: ruby/setup-ruby@v1
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Build the gem
run: gem build rest_framework.gemspec -o rest_framework.gem
- name: Display VERSION
run: cat VERSION
- name: Push to RubyGems
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .rails-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.4
7.1.3
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ruby:3.2.2-bookworm as base
LABEL org.opencontainers.image.source=https://github.com/gregschmit/rails-rest-framework
WORKDIR /app
ENV BUNDLE_PATH="/usr/local/bundle"
ENV RAILS_ENV="production"
ENV DISABLE_DATABASE_ENVIRONMENT_CHECK="1"

# Throw-away build stage to reduce size of final image
FROM base as build

# Setup application gems.
COPY .ruby-version .rails-version rest_framework.gemspec Gemfile Gemfile.lock ./
RUN bundle install

# Setup application.
COPY . .
RUN bin/rails runner "RESTFramework::Version.stamp_version"
RUN bin/rails db:reset
RUN LOGS=all bin/rails log:clear tmp:clear
RUN rm -rf ~/.bundle "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
RUN rm -rf .git

# Final stage for app image.
FROM base

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

EXPOSE 3000
CMD ["bin/rails", "server"]
21 changes: 13 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ RAILS_VERSION = Gem::Version.new(
gem "rails", "~> #{RAILS_VERSION}"
gem "rake"
gem "sqlite3"
gem "puma"

# Only include ransack for Rails >=7.
# Only Rails >=7.1 gems.
if RAILS_VERSION >= Gem::Version.new("7")
gem "kamal"
gem "ransack", ">= 4.0"
end

# Ruby 3 removed webrick, so we need to install it manually.
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3")
gem "webrick"
gem "solid_queue"
end

# Include `active_model_serializers` for custom integration (Rails >=6 only).
if RAILS_VERSION >= Gem::Version.new("6")
gem "active_model_serializers", "0.10.13"
gem "active_model_serializers", "0.10.14"
end

# Include `translate_enum` for custom integration.
Expand All @@ -47,6 +45,12 @@ elsif ENV["ASSET_PIPELINE"] == "propshaft"
gem "propshaft"
end

if ENV["ASSET_PIPELINE"]
# Requires an asset pipeline. Originally to schedule a periodic data wipe for demo data, however
# that would require the worker to restart which is not currently possible in Ruby.
# gem "mission_control-jobs"
end

gem "kramdown"
gem "kramdown-parser-gfm"

Expand All @@ -55,6 +59,7 @@ group :development do
gem "better_errors", "2.9.1" # Avoid `sassc` dependency.
gem "binding_of_caller"
gem "byebug"
gem "foreman"
gem "pry-rails"
gem "rubocop-shopify", require: false
gem "web-console"
Expand All @@ -70,6 +75,6 @@ end

group :test do
gem "minitest"
gem "simplecov"
gem "simplecov", require: false
gem "simplecov-lcov", "0.8.0", require: false
end
Loading

0 comments on commit fc51df5

Please sign in to comment.