forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a .devcontainer folder and its contents when creating a new …
…app. The devcontainer folder includes everything needed to boot the app and do development in a remote container. The container setup includes: - A redis container for Sidekiq and Action Cable - A database (SQLite, Postgres, MySQL or MariaDB) - A Headless chrome container for system tests - Active Storage configured to use the local disk and with preview features working If any of these options are skipped in the app setup they will not be included in the container configuration. Co-authored-by: Rafael Mendonça França <rafael@franca.dev> wip
- Loading branch information
1 parent
74e52ee
commit 7dda73c
Showing
14 changed files
with
372 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
railties/lib/rails/generators/rails/app/templates/.devcontainer/Dockerfile.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM mcr.microsoft.com/devcontainers/ruby:1-3-bookworm | ||
|
||
<%- unless options.skip_active_storage -%> | ||
# Install packages needed to build gems | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y \ | ||
libvips \ | ||
# For video thumbnails | ||
ffmpeg \ | ||
# For pdf thumbnails. If you want to use mupdf instead of poppler, | ||
# you can install the following packages instead: | ||
# mupdf mupdf-tools | ||
poppler-utils | ||
<%- end -%> |
34 changes: 34 additions & 0 deletions
34
railties/lib/rails/generators/rails/app/templates/.devcontainer/devcontainer.json.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby | ||
{ | ||
"name": "<%= app_name %>", | ||
"dockerComposeFile": "docker-compose.yml", | ||
"service": "rails-app", | ||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
"features": { | ||
"ghcr.io/devcontainers/features/github-cli:1": {} | ||
}, | ||
|
||
<%- if !devcontainer_variables.empty? -%> | ||
"containerEnv": { | ||
<%= devcontainer_variables.map { |key, value| "\"#{key}\": \"#{value}\"" }.join(",\n ") %> | ||
}, | ||
<%- end -%> | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root", | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
"postCreateCommand": "bin/setup" | ||
} |
78 changes: 78 additions & 0 deletions
78
railties/lib/rails/generators/rails/app/templates/.devcontainer/docker-compose.yml.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
services: | ||
rails-app: | ||
build: | ||
context: .. | ||
dockerfile: .devcontainer/Dockerfile | ||
|
||
volumes: | ||
- ../..:/workspaces:cached | ||
|
||
# Overrides default command so things don't shut down after the process ends. | ||
command: sleep infinity | ||
|
||
networks: | ||
- default | ||
|
||
# Uncomment the next line to use a non-root user for all processes. | ||
# user: vscode | ||
|
||
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
ports: | ||
- 45678:45678 | ||
<%- if !devcontainer_dependencies.empty? -%> | ||
depends_on: | ||
<%- devcontainer_dependencies.each do |dependency| -%> | ||
- <%= dependency %> | ||
<%- end -%> | ||
<%- end -%> | ||
|
||
<%- if depends_on_system_test? -%> | ||
selenium: | ||
image: seleniarm/standalone-chromium | ||
restart: unless-stopped | ||
networks: | ||
- default | ||
<%- end -%> | ||
|
||
<%- unless options.skip_active_job? && options.skip_action_cable? -%> | ||
redis: | ||
image: redis:7.2 | ||
restart: unless-stopped | ||
networks: | ||
- default | ||
ports: | ||
- 6379:6379 | ||
<%- end -%> | ||
|
||
<%- if options.database == "postgresql" -%> | ||
postgres: | ||
image: postgres:16.1 | ||
restart: unless-stopped | ||
networks: | ||
- default | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
<%- end -%> | ||
|
||
<%- if options.database == "mysql" -%> | ||
mysql: | ||
image: mysql/mysql-server:8.0 | ||
restart: unless-stopped | ||
environment: | ||
MYSQL_ALLOW_EMPTY_PASSWORD: true | ||
MYSQL_ROOT_HOST: "%" | ||
networks: | ||
- default | ||
<%- end -%> | ||
|
||
<%- if options.database == "trilogy" -%> | ||
mariadb: | ||
image: mariadb:10.5 | ||
restart: unless-stopped | ||
networks: | ||
- default | ||
environment: | ||
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true | ||
<%- end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
railties/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
require "test_helper" | ||
|
||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase | ||
<% if skip_devcontainer? -%> | ||
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] | ||
<% else -%> | ||
if ENV["CAPYBARA_SERVER_PORT"] | ||
served_by host: "rails-app", port: ENV["CAPYBARA_SERVER_PORT"] | ||
|
||
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ], options: { | ||
browser: :remote, | ||
url: "http://#{ENV["SELENIUM_HOST"]}:4444", | ||
} | ||
else | ||
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] | ||
end | ||
<% end -%> | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.