From bba8c34fbb96fe1539bcabec1dba05fb4ca1f59d Mon Sep 17 00:00:00 2001 From: Ajay Kumar Guthikonda Date: Thu, 18 Jul 2024 06:38:59 -0700 Subject: [PATCH 1/3] Bump ruby to 3.3.4 --- .circleci/config.yml | 2 +- .ruby-version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6a53c36e8..a48d6caa2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ aliases: paths: - node_modules - &ruby_node_browsers_docker_image - - image: cimg/ruby:3.3.3-browsers + - image: cimg/ruby:3.3.4-browsers environment: PGHOST: localhost PGUSER: untitled_application diff --git a/.ruby-version b/.ruby-version index 619b53766..a0891f563 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.3 +3.3.4 From a9a4b384131fe65c86bcf36e4db96b656d3f4b9d Mon Sep 17 00:00:00 2001 From: Ajay Kumar Guthikonda Date: Thu, 18 Jul 2024 07:02:29 -0700 Subject: [PATCH 2/3] Added support for devcontainer --- .devcontainer/Dockerfile | 3 ++ .devcontainer/compose.yaml | 50 +++++++++++++++++++++ .devcontainer/devcontainer.json | 60 +++++++++++++++++++++++++ bin/configure-scripts/update_configs.rb | 1 + bin/setup-devcontainer | 44 ++++++++++++++++++ bin/setup-scripts/utils.rb | 2 +- config/database.yml | 9 ++++ 7 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/compose.yaml create mode 100644 .devcontainer/devcontainer.json create mode 100755 bin/setup-devcontainer diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..22d476008 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,3 @@ +# [Choice] Ruby version: 3, 3.3, 3.2, 3.1, 3.0, 2, 2.7, 2.6 +ARG VARIANT="3.3.4" +FROM ghcr.io/rails/devcontainer/images/ruby:${VARIANT} diff --git a/.devcontainer/compose.yaml b/.devcontainer/compose.yaml new file mode 100644 index 000000000..a6a438e49 --- /dev/null +++ b/.devcontainer/compose.yaml @@ -0,0 +1,50 @@ +services: + rails: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + depends_on: + - postgres + - redis + # - memcached + - selenium + + # 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 + + selenium: + image: seleniarm/standalone-chromium + restart: unless-stopped + + redis: + image: redis:latest + restart: unless-stopped + volumes: + - redis-data:/data + + postgres: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + + # memcached: + # image: memcached:latest + # restart: unless-stopped + # command: ["-m", "1024"] + +volumes: + postgres-data: + redis-data: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..d94a618eb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,60 @@ +// For format details, see https://aka.ms/devcontainer.json. +{ + "name": "Untitled Application", + "dockerComposeFile": "compose.yaml", + "service": "rails", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, + "ghcr.io/rails/devcontainer/features/activestorage": {}, + "ghcr.io/rails/devcontainer/features/postgres-client": {} + }, + + // https://code.visualstudio.com/remote/advancedcontainers/environment-variables + // https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson + "containerEnv": { + "PGHOST": "postgres", + "PGUSER": "postgres", + "PGPASSWORD": "postgres", + "REDIS_URL": "redis://redis/0", + "CAPYBARA_SERVER_PORT": "45678", + "SELENIUM_HOST": "selenium", + // "MEMCACHE_SERVERS": "memcached:11211" + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 3000, + 5432, + 6379 + ], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "corepack enable && yarn set version 4.2.2 && bin/setup-devcontainer", + + // Configure tool-specific properties. + "customizations": { + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "marcoroth.stimulus-lsp", + "bradlc.vscode-tailwindcss", + // "manuelpuyol.erb-linter", + // "setobiralo.erb-commenter", + // "streetsidesoftware.code-spell-checker", + // "GitHub.copilot", + // "GitHub.copilot-chat", + // "donjayamanne.githistory", + // "esbenp.prettier-vscode", + // "jemmyw.rails-fast-nav", + // "tmikoss.rails-latest-migration" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/bin/configure-scripts/update_configs.rb b/bin/configure-scripts/update_configs.rb index a26ea6891..c1d8cf6f2 100755 --- a/bin/configure-scripts/update_configs.rb +++ b/bin/configure-scripts/update_configs.rb @@ -21,6 +21,7 @@ puts "" puts "Replacing instances of \"Untitled Application\" with \"#{human}\" throughout the codebase.".green replace_in_file("./.circleci/config.yml", "untitled_application", variable) +replace_in_file("./.devcontainer/devcontainer.json", "Untitled Application", human) replace_in_file("./config/application.rb", "untitled_application", connected_name) replace_in_file("./config/database.yml", "untitled_application", variable) replace_in_file("./config/database.yml", "UNTITLED_APPLICATION", environment_variable) diff --git a/bin/setup-devcontainer b/bin/setup-devcontainer new file mode 100755 index 000000000..5d3a8ad77 --- /dev/null +++ b/bin/setup-devcontainer @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +require 'bundler/inline' + +# First we require a util file that will install a few utility gems +# and define some utility methods used by other scirpts. +require "#{__dir__}/setup-scripts/utils" + + + +# path to your application root. +APP_ROOT = File.expand_path("..", __dir__) + + + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to individual scripts in `bin/setup-scripts` and then `require` them below. + + # We need to check for the same version of ruby as bin/configure, so we + # reuse this one from the configure-scritps directory. + require "#{__dir__}/configure-scripts/check_ruby" + require "#{__dir__}/setup-scripts/bundle_install" + + require "#{__dir__}/setup-scripts/check_node" + require "#{__dir__}/setup-scripts/check_yarn" + require "#{__dir__}/setup-scripts/yarn_install" + + # Now we check that you have base-level system dependencies installed. + # Not needed for devcontainer, as we have a compose file with postgres and redis. + # require "#{__dir__}/setup-scripts/check_postgres" + # require "#{__dir__}/setup-scripts/check_redis" + # require "#{__dir__}/setup-scripts/check_icu" + + require "#{__dir__}/setup-scripts/prepare_local_app" + + require "#{__dir__}/setup-scripts/build_assets" + + require "#{__dir__}/setup-scripts/check_overmind" + + puts "" + puts "You're set! Now you can run bin/dev to boot your server and access your new application.".blue +end diff --git a/bin/setup-scripts/utils.rb b/bin/setup-scripts/utils.rb index 46a57fe00..71da71812 100755 --- a/bin/setup-scripts/utils.rb +++ b/bin/setup-scripts/utils.rb @@ -5,7 +5,7 @@ gemfile do source "https://rubygems.org" require "fileutils" - require "colorize" + gem "colorize" require "json" end diff --git a/config/database.yml b/config/database.yml index 92b197d1a..00c2ecba8 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,6 +20,15 @@ default: &default # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + <% if ENV["PGHOST"] %> + host: <%= ENV["PGHOST"] %> + <% end %> + <% if ENV["PGUSER"] %> + username: <%= ENV["PGUSER"] %> + <% end %> + <% if ENV["PGPASSWORD"] %> + password: <%= ENV["PGPASSWORD"] %> + <% end %> development: <<: *default From 7707c78474c26ccbc017e4788cb6259e3c93aa98 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Guthikonda Date: Thu, 18 Jul 2024 17:10:44 -0700 Subject: [PATCH 3/3] Added graphviz to Dockerfile --- .devcontainer/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 22d476008..8ee2b4181 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,3 +1,5 @@ # [Choice] Ruby version: 3, 3.3, 3.2, 3.1, 3.0, 2, 2.7, 2.6 ARG VARIANT="3.3.4" FROM ghcr.io/rails/devcontainer/images/ruby:${VARIANT} + +RUN apt-get update && apt-get install -y graphviz