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 5eec208..b7b6346 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,7 @@ 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 && \ - chown -R rails:rails db log storage tmp + chown -R rails:rails db log storage tmp data USER 1000:1000 # Entrypoint prepares the database. diff --git a/Gemfile b/Gemfile index 3bdd24e..f3dc569 100644 --- a/Gemfile +++ b/Gemfile @@ -36,3 +36,5 @@ group :test do gem "capybara" gem "selenium-webdriver" end + +gem "dockerfile-rails", ">= 1.7", :group => :development diff --git a/Gemfile.lock b/Gemfile.lock index 1b3aad3..d03e6d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,6 +101,8 @@ GEM debug (1.10.0) irb (~> 1.10) reline (>= 0.3.8) + dockerfile-rails (1.7.9) + rails (>= 3.0.0) drb (2.2.1) erubi (1.13.1) et-orbi (1.2.11) @@ -340,6 +342,7 @@ DEPENDENCIES brakeman capybara debug + dockerfile-rails (>= 1.7) importmap-rails jbuilder nanoid diff --git a/app/controllers/instance_controller.rb b/app/controllers/instance_controller.rb index 198c526..46c5f7b 100644 --- a/app/controllers/instance_controller.rb +++ b/app/controllers/instance_controller.rb @@ -14,7 +14,11 @@ class InstanceController < ApplicationController def show @instance = Instance.includes(:pops, :fairies).find_by(public_id: show_instance_params) - @forecast = Weather.forecast(@instance.zone.to_sym) + if @instance + @forecast = Weather.forecast(@instance.zone.to_sym) + else + redirect_to root_path + end end def pop diff --git a/config/database.yml b/config/database.yml index 1293309..af5637f 100644 --- a/config/database.yml +++ b/config/database.yml @@ -84,15 +84,19 @@ production: database: ecoffee_production username: ecoffee password: <%= ENV["ECOFFEE_DATABASE_PASSWORD"] %> + url: <%= ENV["DATABASE_URL"] %> cache: <<: *primary_production database: ecoffee_production_cache migrations_paths: db/cache_migrate + url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_cache" } if ENV["DATABASE_URL"] %> queue: <<: *primary_production database: ecoffee_production_queue migrations_paths: db/queue_migrate + url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_queue" } if ENV["DATABASE_URL"] %> cable: <<: *primary_production database: ecoffee_production_cable migrations_paths: db/cable_migrate + url: <%= URI.parse(ENV["DATABASE_URL"]).tap { |url| url.path += "_cable" } if ENV["DATABASE_URL"] %> diff --git a/config/dockerfile.yml b/config/dockerfile.yml new file mode 100644 index 0000000..223e505 --- /dev/null +++ b/config/dockerfile.yml @@ -0,0 +1,6 @@ +# generated by dockerfile-rails + +--- +options: + label: + fly_launch_runtime: rails diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..9863fcb --- /dev/null +++ b/fly.toml @@ -0,0 +1,44 @@ +# fly.toml app configuration file generated for ecoffee on 2025-03-11T20:11:31+01:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'ecoffee' +primary_region = 'fra' +console_command = '/rails/bin/rails console' + +[build] + +[env] +PORT = '8080' + +[processes] +app = './bin/rails server' + +[deploy] +release_command = "./bin/rails db:prepare" + +[http_service] +internal_port = 8080 +force_https = true +auto_stop_machines = 'stop' +auto_start_machines = true +min_machines_running = 1 +processes = ['app'] + +[[http_service.checks]] +interval = '10s' +timeout = '2s' +grace_period = '5s' +method = 'GET' +path = '/up' +protocol = 'http' +tls_skip_verify = false + +[http_service.checks.headers] +X-Forwarded-Proto = 'https' + +[[vm]] +memory = '1gb' +cpu_kind = 'shared' +cpus = 1