Skip to content
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

dev: setup devcontainer (DX improvement) #700

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM ghcr.io/rails/devcontainer/images/ruby:3.3.6
22 changes: 22 additions & 0 deletions .devcontainer/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "app"
services:
html2rss-web:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
ports:
- "3000:3000"
volumes:
- ../..:/workspaces:cached
- type: bind
source: ../config/feeds.yml
target: /app/config/feeds.yml
read_only: true
environment:
RACK_ENV: development
HEALTH_CHECK_USERNAME: health
HEALTH_CHECK_PASSWORD: please-set-YOUR-OWN-veeeeeery-l0ng-aNd-h4rd-to-gue55-Passw0rd!
AUTO_SOURCE_ENABLED: true
AUTO_SOURCE_USERNAME: foo
AUTO_SOURCE_PASSWORD: bar
AUTO_SOURCE_ALLOWED_ORIGINS: 127.0.0.1:3000
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "app",
"service": "html2rss-web",
"dockerComposeFile": "compose.yml",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"forwardPorts": [
3000
],
"customizations": {
"vscode": {
"settings": {
"ruby.format": true,
"ruby.lint": true
},
"extensions": [
"Shopify.ruby-lsp"
]
}
},
"postCreateCommand": "bundle install"
}
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AllCops:
Metrics/BlockLength:
Exclude:
- Rakefile
ExcludedMethods:
AllowedMethods:
- route

Naming/RescuedExceptionsVariableName:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.3.6
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ When you specify `SENTRY_DSN` in your environment variables, the application wil

Check out the git repository and…

### using Devcontainer (recommended)

Open the cloned repository in your devcontainer supporting IDE (i.e. VSCode). That's it. Happy coding.

### Using Docker

This approach allows you to experiment without installing Ruby on your machine.
Expand Down
16 changes: 2 additions & 14 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ def self.development? = ENV['RACK_ENV'] == 'development'
plugin :typecast_params
plugin :basic_auth

Dir['routes/**/*.rb'].each do |f|
if development?
Unreloader.require f
else
require_relative f
end
end
Dir['routes/**/*.rb'].each { |f| require_relative f }

route do |r|
r.public
Expand All @@ -83,13 +77,7 @@ def self.development? = ENV['RACK_ENV'] == 'development'
end
end

Dir['helpers/*.rb'].each do |f|
if development?
Unreloader.require f
else
require_relative f
end
end
Dir['helpers/*.rb'].each { |f| require_relative f }
end
end
end
7 changes: 6 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ if ENV.key?('SENTRY_DSN')
end

dev = ENV.fetch('RACK_ENV', nil) == 'development'
requires = Dir['app/**/*.rb']
requires = Dir[
'app/**/*.rb',
'helpers/**/*.rb',
'roda/**/*.rb',
'routes/**/*.rb',
]

if dev
require 'logger'
Expand Down
9 changes: 9 additions & 0 deletions spec/html2rss/web/helpers/auto_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

RSpec.describe Html2rss::Web::AutoSource do # rubocop:disable RSpec/SpecFilePathFormat
context 'when ENV variables are not set' do
around do |example|
ClimateControl.modify AUTO_SOURCE_ENABLED: nil,
AUTO_SOURCE_USERNAME: nil,
AUTO_SOURCE_PASSWORD: nil,
AUTO_SOURCE_ALLOWED_ORIGINS: nil do
example.run
end
end

describe '.enabled?' do
subject { described_class.enabled? }

Expand Down