diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..b0c246e --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,18 @@ +# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ + +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/Dockerfile b/Dockerfile index ae6eeae..249f01c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,30 +2,37 @@ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile ARG RUBY_VERSION=3.2.2 -FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base +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_DEPLOYMENT="1" \ +ENV BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ - BUNDLE_WITHOUT="development" + BUNDLE_WITHOUT="development:test" \ + RAILS_ENV="production" \ + DATABASE_URL="dummy.url" + +# 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 +FROM base AS build # Install packages needed to build gems RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libvips pkg-config + apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config # Install application gems COPY Gemfile Gemfile.lock ./ RUN bundle install && \ - rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ - bundle exec bootsnap precompile --gemfile + bundle exec bootsnap precompile --gemfile && \ + rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git # Copy application code COPY . . @@ -42,17 +49,18 @@ FROM base # Install packages needed for deployment RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \ + apt-get install --no-install-recommends -y curl libsqlite3-0 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 "${BUNDLE_PATH}" "${BUNDLE_PATH}" 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 +RUN groupadd --system --gid 1000 rails && \ + useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ + chown -R 1000:1000 db log storage tmp +USER 1000:1000 # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint"] diff --git a/Gemfile b/Gemfile index bd8e78c..01f7f0e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'bootsnap', require: false gem 'devise', github: 'heartcombo/devise', ref: 'f8d1ea90bc3' gem 'importmap-rails' gem 'jbuilder' +gem 'mailgun-ruby', '~>1.2.14' gem 'omniauth' gem 'puma', '>= 5.0' gem 'rails', '~> 7.1.4' @@ -56,3 +57,7 @@ group :test do end gem 'tailwindcss-rails', '~> 2.7' + +gem 'dockerfile-rails', '>= 1.6', group: :development + +gem 'pg', '~> 1.5' diff --git a/Gemfile.lock b/Gemfile.lock index 462d8e2..1b09bff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,6 +118,9 @@ GEM irb (~> 1.10) reline (>= 0.3.8) diff-lcs (1.5.1) + dockerfile-rails (1.6.22) + rails (>= 3.0.0) + domain_name (0.6.20240107) drb (2.2.1) erubi (1.13.0) factory_bot (6.4.6) @@ -140,6 +143,9 @@ GEM globalid (1.2.1) activesupport (>= 6.1) hashie (5.0.0) + http-accept (1.7.0) + http-cookie (1.0.7) + domain_name (~> 0.5) i18n (1.14.5) concurrent-ruby (~> 1.0) importmap-rails (2.0.1) @@ -170,8 +176,14 @@ GEM net-imap net-pop net-smtp + mailgun-ruby (1.2.14) + rest-client (>= 2.0.2) marcel (1.0.4) matrix (0.4.2) + mime-types (3.6.0) + logger + mime-types-data (~> 3.2015) + mime-types-data (3.2024.1001) mini_mime (1.1.5) minitest (5.25.1) msgpack (1.7.2) @@ -185,6 +197,7 @@ GEM timeout net-smtp (0.5.0) net-protocol + netrc (0.11.0) nio4r (2.7.3) nokogiri (1.16.7-aarch64-linux) racc (~> 1.4) @@ -203,6 +216,7 @@ GEM rack (>= 2.2.3) rack-protection orm_adapter (0.5.0) + pg (1.5.8) psych (5.1.2) stringio public_suffix (6.0.1) @@ -270,6 +284,11 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) rexml (3.3.6) strscan rspec-core (3.13.0) @@ -375,12 +394,15 @@ DEPENDENCIES capybara debug devise! + dockerfile-rails (>= 1.6) factory_bot_rails faker importmap-rails jbuilder letter_opener + mailgun-ruby (~> 1.2.14) omniauth + pg (~> 1.5) puma (>= 5.0) rails (~> 7.1.4) rails_live_reload diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index b77f4d6..a76bb6b 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -4,7 +4,7 @@ <%= link_to root_path do %>
Hudson Valley
-Tool Library
+Tool Share