From 786b5c7be7fa30f54067ab3e729165c92413004f Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Fri, 24 Mar 2023 14:16:28 +0700 Subject: [PATCH 1/9] [gh394] Remove the figaro dependency in favor of dotenv gem and a .env.example file --- .gitignore.rb | 3 +++ .template/.env.example | 22 +++++++++++++++++++ .template/addons/docker/Dockerfile.tt | 7 +++++- .template/spec/base/bin/template_spec.rb | 5 ----- .template/spec/base/config/template_spec.rb | 4 ++-- .template/spec/base/template_spec.rb | 8 +++++++ Gemfile.tt | 2 +- bin/docker-assets-precompile | 24 --------------------- config/database.yml | 23 -------------------- config/database.yml.tt | 23 ++++++++++++++++++++ config/template.rb | 3 +-- template.rb | 1 + 12 files changed, 67 insertions(+), 58 deletions(-) create mode 100644 .template/.env.example delete mode 100755 bin/docker-assets-precompile delete mode 100644 config/database.yml create mode 100644 config/database.yml.tt diff --git a/.gitignore.rb b/.gitignore.rb index 5160ebf0..39dbe8cd 100644 --- a/.gitignore.rb +++ b/.gitignore.rb @@ -10,5 +10,8 @@ # Ignore the test coverage results from SimpleCov /coverage + + # Ignore environment variables files (as it might contain sensitive data) + .env IGNORE end diff --git a/.template/.env.example b/.template/.env.example new file mode 100644 index 00000000..3560f90e --- /dev/null +++ b/.template/.env.example @@ -0,0 +1,22 @@ +# Used to verify the integrity of signed cookies. so ensure a secure value is set +SECRET_KEY_BASE=replace_with_lengthy_secure_hex + +PORT=80 +REDIS_URL=redis://localhost:6379 + +# CI/CD +TEST_RETRY=0 +CI=false +DOCKER_IMAGE=nimblehq/rails_template +DOCKER_REGISTRY_HOST=docker.io + + +# Mail +MAILER_DEFAULT_HOST=localhost +MAILER_DEFAULT_PORT=3000 +MAILER_SENDER=Test + +# Locales +AVAILABLE_LOCALES=en +DEFAULT_LOCALE=en +FALLBACK_LOCALES=en diff --git a/.template/addons/docker/Dockerfile.tt b/.template/addons/docker/Dockerfile.tt index 22bb1f9e..958166cb 100644 --- a/.template/addons/docker/Dockerfile.tt +++ b/.template/addons/docker/Dockerfile.tt @@ -98,8 +98,13 @@ COPY . ./ RUN rm -rf tmp/docker <%- if WEB_VARIANT -%> +# Provide fallback for env variables +RUN cp .env.example .env + # Compile assets -RUN bin/docker-assets-precompile +RUN bin/rails i18n:js:export +RUN bin/rails assets:precompile +RUN yarn postcss <%- end -%> EXPOSE $PORT diff --git a/.template/spec/base/bin/template_spec.rb b/.template/spec/base/bin/template_spec.rb index d5e7e629..4943515d 100644 --- a/.template/spec/base/bin/template_spec.rb +++ b/.template/spec/base/bin/template_spec.rb @@ -30,9 +30,4 @@ expect(file('bin/docker-prepare')).to exist expect(file('bin/docker-prepare')).to be_executable end - - it 'creates the docker asset precompile script' do - expect(file('bin/docker-assets-precompile')).to exist - expect(file('bin/docker-assets-precompile')).to be_executable - end end diff --git a/.template/spec/base/config/template_spec.rb b/.template/spec/base/config/template_spec.rb index 412862d1..8bbf2228 100644 --- a/.template/spec/base/config/template_spec.rb +++ b/.template/spec/base/config/template_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true describe '/config template' do - it 'creates the Figaro configuration for application variables' do - expect(file('config/application.yml')).to exist + it 'does NOT create the application.yml config' do + expect(file('config/application.yml')).not_to exist end it 'creates the database configuration' do diff --git a/.template/spec/base/template_spec.rb b/.template/spec/base/template_spec.rb index 430f1fef..05816e90 100644 --- a/.template/spec/base/template_spec.rb +++ b/.template/spec/base/template_spec.rb @@ -30,4 +30,12 @@ it 'creates Reek configuration files' do expect(file('.reek.yml')).to exist end + + it 'creates .env.example file' do + expect(file('.env.example')).to exist + end + + it 'does NOT creates .env file' do + expect(file('.env')).not_to exist + end end diff --git a/Gemfile.tt b/Gemfile.tt index 8d603fe6..7a48a9fb 100644 --- a/Gemfile.tt +++ b/Gemfile.tt @@ -8,6 +8,7 @@ gem 'puma' # Use Puma as the app server gem 'mini_magick' # A ruby wrapper for ImageMagick or GraphicsMagick command line gem 'pagy' # A pagination gem that is very light and fast gem 'discard' # Soft deletes for ActiveRecord +gem 'dotenv-rails' # Shim to load environment variables from .env into ENV in development gem 'sidekiq' # background processing for Ruby gem 'sassc' # bootsnap dependency gem 'bootsnap', require: false # Reduces boot times through caching; required in config/boot.rb @@ -41,7 +42,6 @@ group :development, :test do # gem 'debug', platforms: %i[ mri mingw x64_mingw ] # Official debug # Utilities - gem 'figaro' # Simple Rails app configuration gem 'listen' # Listens to file modifications gem 'letter_opener' # Preview mail in the browser instead of sending gem 'ffaker' # A library for generating fake data such as names, addresses, and phone numbers diff --git a/bin/docker-assets-precompile b/bin/docker-assets-precompile deleted file mode 100755 index a5b95c27..00000000 --- a/bin/docker-assets-precompile +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# For building production docker image -# -# It sets the envs inside the docker image for precompiling the assets -# Because to precompile the assets, Rails initializes the app. -# And it requires the envs as we always use `ENV.fetch` to setup the variables -# -# Related issue: https://github.com/rails/rails/issues/32947 -# TODO: https://github.com/nimblehq/rails-templates/issues/326 - -require 'yaml' - -rails_env = ENV.fetch('RAILS_ENV', 'production') - -if rails_env == 'production' - docker_build_envs = YAML.load_file('config/application.yml')['docker_build'] - docker_build_envs.each { |name, value| ENV[name] = value } - - ENV['DATABASE_URL'] = 'postgres://postgres:postgres@postgres:5432/postgres' -end - -exit system('bin/rails i18n:js:export && bin/rails assets:precompile && yarn postcss') diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index c75c989a..00000000 --- a/config/database.yml +++ /dev/null @@ -1,23 +0,0 @@ -default: &default - adapter: postgresql - encoding: unicode - pool: 5 - -development: - <<: *default - host: <%= ENV['DB_HOST'] %> - port: <%= ENV['DB_PORT'] %> - username: <%= ENV['DB_USERNAME'] %> - password: <%= ENV['DB_PASSWORD'] %> - database: <%= ENV['DB_NAME'] %>_development - -test: - <<: *default - host: <%= ENV['DB_HOST'] %> - port: <%= ENV['DB_PORT'] %> - username: <%= ENV['DB_USERNAME'] %> - password: <%= ENV['DB_PASSWORD'] %> - database: <%= ENV['DB_NAME'] %>_test - -production: - url: <%= ENV['DATABASE_URL'] %> diff --git a/config/database.yml.tt b/config/database.yml.tt new file mode 100644 index 00000000..5e6440a4 --- /dev/null +++ b/config/database.yml.tt @@ -0,0 +1,23 @@ +default: &default + adapter: postgresql + encoding: unicode + pool: 5 + +development: + <<: *default + host: <%= ENV.fetch('DB_HOST') { 'localhost' } %> + port: <%= ENV.fetch('DB_PORT') { 5432 } %> + username: <%= ENV.fetch('DB_USERNAME') { 'postgres' } %> + password: <%= ENV.fetch('DB_PASSWORD') { 'postgres' } %> + database: <%= ENV.fetch('DB_NAME') { '<%= APP_NAME %>' } %>_development + +test: + <<: *default + host: <%= ENV.fetch('DB_HOST') { 'localhost' } %> + port: <%= ENV.fetch('DB_PORT') { 5432 } %> + username: <%= ENV.fetch('DB_USERNAME') { 'postgres' } %> + password: <%= ENV.fetch('DB_PASSWORD') { 'postgres' } %> + database: <%= ENV.fetch('DB_NAME') { '<%= APP_NAME %>' } %>_test + +production: + url: <%= ENV.fetch('DATABASE_URL') diff --git a/config/template.rb b/config/template.rb index 74caecb6..69f0091d 100644 --- a/config/template.rb +++ b/config/template.rb @@ -2,8 +2,7 @@ apply 'config/application.rb' -template 'config/application.yml.tt' -copy_file 'config/database.yml', force: true +template 'config/database.yml.tt', force: true copy_file 'config/sidekiq.yml' apply 'config/environments/development.rb' diff --git a/template.rb b/template.rb index f8bb4a87..47a0fd2a 100644 --- a/template.rb +++ b/template.rb @@ -34,6 +34,7 @@ def apply_template!(template_root) copy_file '.flayignore' copy_file 'Dangerfile' + copy_file '.env.example' copy_file '.rubocop.yml' copy_file '.reek.yml' From afc46b33dcd3274a038344d5088a2a8ac83a8180 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Fri, 28 Apr 2023 08:33:59 +0700 Subject: [PATCH 2/9] Move .env.example to root --- .template/.env.example => .env.example | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .template/.env.example => .env.example (100%) diff --git a/.template/.env.example b/.env.example similarity index 100% rename from .template/.env.example rename to .env.example From b513d5dc27eaae91c46ea88b1d93c37e27257635 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Fri, 28 Apr 2023 08:44:12 +0700 Subject: [PATCH 3/9] Remove application.ymk.tt --- bin/template.rb | 1 - config/application.yml.tt | 25 ------------------------- config/database.yml.tt | 6 +++--- 3 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 config/application.yml.tt diff --git a/bin/template.rb b/bin/template.rb index eabab904..5a92ad14 100644 --- a/bin/template.rb +++ b/bin/template.rb @@ -7,4 +7,3 @@ copy_file 'bin/worker.sh', mode: :preserve copy_file 'bin/dev', mode: :preserve copy_file 'bin/docker-prepare', mode: :preserve -copy_file 'bin/docker-assets-precompile', mode: :preserve diff --git a/config/application.yml.tt b/config/application.yml.tt deleted file mode 100644 index cdc23963..00000000 --- a/config/application.yml.tt +++ /dev/null @@ -1,25 +0,0 @@ -default: &default - DB_NAME: "<%= APP_NAME %>" - DB_HOST: "localhost" - DB_PORT: "5432" - DB_USERNAME: "postgres" - DB_PASSWORD: "postgres" - MAILER_DEFAULT_HOST: "localhost" - MAILER_DEFAULT_PORT: "3000" - MAILER_SENDER: "Test " - AVAILABLE_LOCALES: "en" - DEFAULT_LOCALE: "en" - FALLBACK_LOCALES: "en" - -development: - <<: *default - -test: - <<: *default - TEST_RETRY: "0" - -# Set environment variables required in the initializers in order to precompile the assets. -# Because it initializes the app, so all variables need to exist in the Docker build stage (used in bin/docker-assets-precompile). -docker_build: - <<: *default - SECRET_KEY_BASE: dummy_secret_key_base diff --git a/config/database.yml.tt b/config/database.yml.tt index 5e6440a4..2e473563 100644 --- a/config/database.yml.tt +++ b/config/database.yml.tt @@ -9,7 +9,7 @@ development: port: <%= ENV.fetch('DB_PORT') { 5432 } %> username: <%= ENV.fetch('DB_USERNAME') { 'postgres' } %> password: <%= ENV.fetch('DB_PASSWORD') { 'postgres' } %> - database: <%= ENV.fetch('DB_NAME') { '<%= APP_NAME %>' } %>_development + database: <%= ENV.fetch('DB_NAME') { APP_NAME } %>_development test: <<: *default @@ -17,7 +17,7 @@ test: port: <%= ENV.fetch('DB_PORT') { 5432 } %> username: <%= ENV.fetch('DB_USERNAME') { 'postgres' } %> password: <%= ENV.fetch('DB_PASSWORD') { 'postgres' } %> - database: <%= ENV.fetch('DB_NAME') { '<%= APP_NAME %>' } %>_test + database: <%= ENV.fetch('DB_NAME') { APP_NAME } %>_test production: - url: <%= ENV.fetch('DATABASE_URL') + url: <%= ENV.fetch('DATABASE_URL') { '' } %> From feeeff682a5da59c80687fc01f5f80216bd97926 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Fri, 28 Apr 2023 09:29:55 +0700 Subject: [PATCH 4/9] Merge the .env from docker adddon with .env.example --- .env.example | 1 - .template/addons/docker/.env.tt | 6 ------ .template/addons/docker/template.rb | 12 +++++++++++- .template/hooks/before_complete/copy_env_example.rb | 9 +++++++++ .template/spec/base/template_spec.rb | 4 ++-- template.rb | 3 +++ 6 files changed, 25 insertions(+), 10 deletions(-) delete mode 100644 .template/addons/docker/.env.tt create mode 100644 .template/hooks/before_complete/copy_env_example.rb diff --git a/.env.example b/.env.example index 3560f90e..54add52a 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,6 @@ # Used to verify the integrity of signed cookies. so ensure a secure value is set SECRET_KEY_BASE=replace_with_lengthy_secure_hex -PORT=80 REDIS_URL=redis://localhost:6379 # CI/CD diff --git a/.template/addons/docker/.env.tt b/.template/addons/docker/.env.tt deleted file mode 100644 index 7be3e1c5..00000000 --- a/.template/addons/docker/.env.tt +++ /dev/null @@ -1,6 +0,0 @@ -DOCKER_REGISTRY_HOST=<%= DOCKER_REGISTRY_HOST %> -DOCKER_IMAGE=<%= DOCKER_IMAGE %> -BRANCH_TAG=latest -PORT=80 -CI=false -TEST_RETRY=0 diff --git a/.template/addons/docker/template.rb b/.template/addons/docker/template.rb index 18b65679..ca46b687 100644 --- a/.template/addons/docker/template.rb +++ b/.template/addons/docker/template.rb @@ -6,5 +6,15 @@ template 'docker-compose.dev.yml.tt' template 'docker-compose.test.yml.tt' template 'docker-compose.yml.tt' -template '.env.tt' template '.dockerignore.tt' + +append_to_file '.env.example' do + <<~ENVEXAMPLE + + # Docker + DOCKER_REGISTRY_HOST=#{DOCKER_REGISTRY_HOST} + DOCKER_IMAGE=#{DOCKER_IMAGE} + BRANCH_TAG=latest + PORT=80 + ENVEXAMPLE +end diff --git a/.template/hooks/before_complete/copy_env_example.rb b/.template/hooks/before_complete/copy_env_example.rb new file mode 100644 index 00000000..8bfcee75 --- /dev/null +++ b/.template/hooks/before_complete/copy_env_example.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +def copy_env_example + use_source_path __dir__ + + run 'cp .env.example .env' +end + +copy_env_example diff --git a/.template/spec/base/template_spec.rb b/.template/spec/base/template_spec.rb index 05816e90..52d03f75 100644 --- a/.template/spec/base/template_spec.rb +++ b/.template/spec/base/template_spec.rb @@ -35,7 +35,7 @@ expect(file('.env.example')).to exist end - it 'does NOT creates .env file' do - expect(file('.env')).not_to exist + it 'creates .env file' do + expect(file('.env')).to exist end end diff --git a/template.rb b/template.rb index 47a0fd2a..5841e41a 100644 --- a/template.rb +++ b/template.rb @@ -80,6 +80,9 @@ def apply_template!(template_root) apply '.template/variants/web/template.rb' if WEB_VARIANT # A list necessary jobs that run before complete, ex: Fixing rubocop on Ruby files that generated by Rails + # before_bundle + apply '.template/hooks/before_complete/copy_env_example.rb' + # after_bundle apply '.template/hooks/before_complete/fix_rubocop.rb' apply '.template/hooks/before_complete/report.rb' end From 6b4ec94ac62899a5d8b68a92d0caaee685ea015b Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Fri, 2 Jun 2023 11:55:22 +0700 Subject: [PATCH 5/9] Fix tests errors --- .template/addons/docker/Dockerfile.tt | 4 +++- .template/variants/web/package.json.rb | 1 + Makefile | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.template/addons/docker/Dockerfile.tt b/.template/addons/docker/Dockerfile.tt index 958166cb..f769324a 100644 --- a/.template/addons/docker/Dockerfile.tt +++ b/.template/addons/docker/Dockerfile.tt @@ -104,7 +104,9 @@ RUN cp .env.example .env # Compile assets RUN bin/rails i18n:js:export RUN bin/rails assets:precompile -RUN yarn postcss +RUN bundle exec rake i18n:js:export +RUN yarn build +RUN yarn build:css <%- end -%> EXPOSE $PORT diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index 8754d306..d3d0fd6e 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -31,6 +31,7 @@ run 'yarn add --dev @nimblehq/eslint-config-nimble@2.2.1' run 'yarn add --dev stylelint' run 'yarn add --dev @nimblehq/stylelint-config-nimble' + # Setup scripts run 'npm set-script eslint "eslint . --color"' run 'npm set-script eslint:fix "eslint . --color --fix"' diff --git a/Makefile b/Makefile index 4015127d..755c4ff3 100644 --- a/Makefile +++ b/Makefile @@ -18,16 +18,19 @@ create_api: build: cd $(APP_NAME) && \ + cp .env.example .env && \ bin/docker-prepare && \ docker-compose -f docker-compose.test.yml build build_production: cd $(APP_NAME) && \ + cp .env.example .env && \ bin/docker-prepare && \ docker-compose build test_variant_app: cd $(APP_NAME) && \ + cp .env.example .env && \ docker-compose -f docker-compose.test.yml run test base_addon_spec = spec/addons/base/**/*_spec.rb @@ -44,6 +47,7 @@ test_template: docker-compose -f docker-compose.test.yml run test bash -c "./bin/inject_port_into_nginx.sh && nginx -c /etc/nginx/conf.d/default.conf -t" && \ docker-compose -f docker-compose.test.yml run --detach test bin/start.sh && \ cd ../.template && \ + cp .env.example .env && \ bundle install; \ if [ $(VARIANT) = web ]; then \ bundle exec rspec --pattern="${base_spec}, ${web_spec}, ${base_addon_spec}, ${web_addon_spec}" --format progress; \ From 9e9a73d5b0f68411898ad05570c1964d670a3abc Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Fri, 2 Jun 2023 14:55:25 +0700 Subject: [PATCH 6/9] Test with .env.local for non sensistive ENV VAR --- .env.example => .env | 7 ++----- .env.development.example | 5 +++++ .gitignore.rb | 4 ++-- .template/addons/docker/Dockerfile.tt | 2 -- .template/addons/docker/template.rb | 3 ++- .template/hooks/before_complete/copy_env_example.rb | 9 --------- .template/spec/addons/base/docker/template_spec.rb | 4 ---- .template/spec/base/template_spec.rb | 8 ++++---- .template/spec/support/serverspec.rb | 8 ++++++++ Makefile | 4 ---- template.rb | 6 ++---- 11 files changed, 25 insertions(+), 35 deletions(-) rename .env.example => .env (54%) create mode 100644 .env.development.example delete mode 100644 .template/hooks/before_complete/copy_env_example.rb diff --git a/.env.example b/.env similarity index 54% rename from .env.example rename to .env index 54add52a..4f03e15b 100644 --- a/.env.example +++ b/.env @@ -1,14 +1,11 @@ -# Used to verify the integrity of signed cookies. so ensure a secure value is set -SECRET_KEY_BASE=replace_with_lengthy_secure_hex +# DO NOT STORE SECRETS HERE. +# Use .env.development for local secrets. REDIS_URL=redis://localhost:6379 # CI/CD TEST_RETRY=0 CI=false -DOCKER_IMAGE=nimblehq/rails_template -DOCKER_REGISTRY_HOST=docker.io - # Mail MAILER_DEFAULT_HOST=localhost diff --git a/.env.development.example b/.env.development.example new file mode 100644 index 00000000..f73db68f --- /dev/null +++ b/.env.development.example @@ -0,0 +1,5 @@ +# DO NOT COMMIT THIS FILE. +# Rename it to `.env.development` and use it for local secrets only. + +# Used to verify the integrity of signed cookies. so ensure a secure value is set +SECRET_KEY_BASE=replace_with_lengthy_secure_hex diff --git a/.gitignore.rb b/.gitignore.rb index 39dbe8cd..a6687030 100644 --- a/.gitignore.rb +++ b/.gitignore.rb @@ -11,7 +11,7 @@ # Ignore the test coverage results from SimpleCov /coverage - # Ignore environment variables files (as it might contain sensitive data) - .env + # Ignore environment variables files + .env.development IGNORE end diff --git a/.template/addons/docker/Dockerfile.tt b/.template/addons/docker/Dockerfile.tt index f769324a..a9e1293a 100644 --- a/.template/addons/docker/Dockerfile.tt +++ b/.template/addons/docker/Dockerfile.tt @@ -98,8 +98,6 @@ COPY . ./ RUN rm -rf tmp/docker <%- if WEB_VARIANT -%> -# Provide fallback for env variables -RUN cp .env.example .env # Compile assets RUN bin/rails i18n:js:export diff --git a/.template/addons/docker/template.rb b/.template/addons/docker/template.rb index ca46b687..a2ee54ce 100644 --- a/.template/addons/docker/template.rb +++ b/.template/addons/docker/template.rb @@ -8,10 +8,11 @@ template 'docker-compose.yml.tt' template '.dockerignore.tt' -append_to_file '.env.example' do +append_to_file '.env' do <<~ENVEXAMPLE # Docker + APP_NAME=#{APP_NAME} DOCKER_REGISTRY_HOST=#{DOCKER_REGISTRY_HOST} DOCKER_IMAGE=#{DOCKER_IMAGE} BRANCH_TAG=latest diff --git a/.template/hooks/before_complete/copy_env_example.rb b/.template/hooks/before_complete/copy_env_example.rb deleted file mode 100644 index 8bfcee75..00000000 --- a/.template/hooks/before_complete/copy_env_example.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -def copy_env_example - use_source_path __dir__ - - run 'cp .env.example .env' -end - -copy_env_example diff --git a/.template/spec/addons/base/docker/template_spec.rb b/.template/spec/addons/base/docker/template_spec.rb index 208b3741..875edc76 100644 --- a/.template/spec/addons/base/docker/template_spec.rb +++ b/.template/spec/addons/base/docker/template_spec.rb @@ -5,10 +5,6 @@ expect(file('Dockerfile')).to exist end - it 'creates the docker env file' do - expect(file('.env')).to exist - end - it 'creates the docker ignore file' do expect(file('.dockerignore')).to exist end diff --git a/.template/spec/base/template_spec.rb b/.template/spec/base/template_spec.rb index 52d03f75..68e015e9 100644 --- a/.template/spec/base/template_spec.rb +++ b/.template/spec/base/template_spec.rb @@ -31,11 +31,11 @@ expect(file('.reek.yml')).to exist end - it 'creates .env.example file' do - expect(file('.env.example')).to exist - end - it 'creates .env file' do expect(file('.env')).to exist end + + it 'creates .env.development.example file' do + expect(file('.env.development.example')).to exist + end end diff --git a/.template/spec/support/serverspec.rb b/.template/spec/support/serverspec.rb index 03527d6e..3f08a971 100644 --- a/.template/spec/support/serverspec.rb +++ b/.template/spec/support/serverspec.rb @@ -7,7 +7,13 @@ module ServerSpecHelpers # Prebuild and run docker image before running the test # Because the docker api does not support docker compose def self.test_container + puts 'HERERERERERE' + puts 'HERERERERERE' + puts ENV.fetch('APP_NAME') + puts `docker ps` container_id = `docker ps -qf "name=#{ENV.fetch('APP_NAME')}_test"` + puts 'Container ID:' + puts container_id Docker::Container.get(container_id.strip) end @@ -15,6 +21,7 @@ def self.test_container RSpec.configure do |config| config.before(:suite) do + puts 'BEFORE SUITE' container = ServerSpecHelpers.test_container set :os, family: :debian @@ -23,6 +30,7 @@ def self.test_container end config.after(:suite) do + puts 'AFTER SUITE' container = ServerSpecHelpers.test_container container.stop diff --git a/Makefile b/Makefile index 755c4ff3..4015127d 100644 --- a/Makefile +++ b/Makefile @@ -18,19 +18,16 @@ create_api: build: cd $(APP_NAME) && \ - cp .env.example .env && \ bin/docker-prepare && \ docker-compose -f docker-compose.test.yml build build_production: cd $(APP_NAME) && \ - cp .env.example .env && \ bin/docker-prepare && \ docker-compose build test_variant_app: cd $(APP_NAME) && \ - cp .env.example .env && \ docker-compose -f docker-compose.test.yml run test base_addon_spec = spec/addons/base/**/*_spec.rb @@ -47,7 +44,6 @@ test_template: docker-compose -f docker-compose.test.yml run test bash -c "./bin/inject_port_into_nginx.sh && nginx -c /etc/nginx/conf.d/default.conf -t" && \ docker-compose -f docker-compose.test.yml run --detach test bin/start.sh && \ cd ../.template && \ - cp .env.example .env && \ bundle install; \ if [ $(VARIANT) = web ]; then \ bundle exec rspec --pattern="${base_spec}, ${web_spec}, ${base_addon_spec}, ${web_addon_spec}" --format progress; \ diff --git a/template.rb b/template.rb index 5841e41a..df16ab4c 100644 --- a/template.rb +++ b/template.rb @@ -34,7 +34,8 @@ def apply_template!(template_root) copy_file '.flayignore' copy_file 'Dangerfile' - copy_file '.env.example' + copy_file '.env' + copy_file '.env.development.example' copy_file '.rubocop.yml' copy_file '.reek.yml' @@ -80,9 +81,6 @@ def apply_template!(template_root) apply '.template/variants/web/template.rb' if WEB_VARIANT # A list necessary jobs that run before complete, ex: Fixing rubocop on Ruby files that generated by Rails - # before_bundle - apply '.template/hooks/before_complete/copy_env_example.rb' - # after_bundle apply '.template/hooks/before_complete/fix_rubocop.rb' apply '.template/hooks/before_complete/report.rb' end From 18fc0ac59e578ea7c3d361883efd970cf7a60687 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Mon, 5 Jun 2023 15:42:30 +0700 Subject: [PATCH 7/9] Test to comment the server spec part --- .env | 2 ++ .env.development.example | 2 +- .template/addons/docker/Dockerfile.tt | 4 +--- .template/spec/support/serverspec.rb | 8 -------- .template/variants/web/package.json.rb | 2 +- .template/variants/web/template.rb | 2 +- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.env b/.env index 4f03e15b..62e1ed87 100644 --- a/.env +++ b/.env @@ -16,3 +16,5 @@ MAILER_SENDER=Test AVAILABLE_LOCALES=en DEFAULT_LOCALE=en FALLBACK_LOCALES=en + +SECRET_KEY_BASE=replace_with_lengthy_secure_hex diff --git a/.env.development.example b/.env.development.example index f73db68f..6ab4e54b 100644 --- a/.env.development.example +++ b/.env.development.example @@ -1,4 +1,4 @@ -# DO NOT COMMIT THIS FILE. +# DO NOT COMMIT THIS FILE (`.env.development`) # Rename it to `.env.development` and use it for local secrets only. # Used to verify the integrity of signed cookies. so ensure a secure value is set diff --git a/.template/addons/docker/Dockerfile.tt b/.template/addons/docker/Dockerfile.tt index a9e1293a..8492d744 100644 --- a/.template/addons/docker/Dockerfile.tt +++ b/.template/addons/docker/Dockerfile.tt @@ -102,9 +102,7 @@ RUN rm -rf tmp/docker # Compile assets RUN bin/rails i18n:js:export RUN bin/rails assets:precompile -RUN bundle exec rake i18n:js:export -RUN yarn build -RUN yarn build:css +RUN yarn postcss <%- end -%> EXPOSE $PORT diff --git a/.template/spec/support/serverspec.rb b/.template/spec/support/serverspec.rb index 3f08a971..03527d6e 100644 --- a/.template/spec/support/serverspec.rb +++ b/.template/spec/support/serverspec.rb @@ -7,13 +7,7 @@ module ServerSpecHelpers # Prebuild and run docker image before running the test # Because the docker api does not support docker compose def self.test_container - puts 'HERERERERERE' - puts 'HERERERERERE' - puts ENV.fetch('APP_NAME') - puts `docker ps` container_id = `docker ps -qf "name=#{ENV.fetch('APP_NAME')}_test"` - puts 'Container ID:' - puts container_id Docker::Container.get(container_id.strip) end @@ -21,7 +15,6 @@ def self.test_container RSpec.configure do |config| config.before(:suite) do - puts 'BEFORE SUITE' container = ServerSpecHelpers.test_container set :os, family: :debian @@ -30,7 +23,6 @@ def self.test_container end config.after(:suite) do - puts 'AFTER SUITE' container = ServerSpecHelpers.test_container container.stop diff --git a/.template/variants/web/package.json.rb b/.template/variants/web/package.json.rb index d3d0fd6e..c0f2b80d 100644 --- a/.template/variants/web/package.json.rb +++ b/.template/variants/web/package.json.rb @@ -29,7 +29,7 @@ run 'yarn add postcss postcss-cli autoprefixer' run 'yarn add --dev @nimblehq/eslint-config-nimble@2.2.1' -run 'yarn add --dev stylelint' +run 'yarn add --dev stylelint@14' run 'yarn add --dev @nimblehq/stylelint-config-nimble' # Setup scripts diff --git a/.template/variants/web/template.rb b/.template/variants/web/template.rb index 83660a38..52d58d03 100644 --- a/.template/variants/web/template.rb +++ b/.template/variants/web/template.rb @@ -30,7 +30,7 @@ def apply_web_variant! use_source_path __dir__ # Generate translation file - run 'bin/rake i18n:js:export' + run 'bundle exec rake i18n:js:export' # Fix the default Rails template that does not put trailing commas run 'yarn run codebase:fix' From b0df8471e3ae771c19238eb0d44ad1666f8e98c9 Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Mon, 5 Jun 2023 19:56:12 +0700 Subject: [PATCH 8/9] Test --- .template/addons/docker/Dockerfile.tt | 4 ++-- .template/variants/web/template.rb | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.template/addons/docker/Dockerfile.tt b/.template/addons/docker/Dockerfile.tt index 8492d744..aa9f41a9 100644 --- a/.template/addons/docker/Dockerfile.tt +++ b/.template/addons/docker/Dockerfile.tt @@ -100,8 +100,8 @@ RUN rm -rf tmp/docker <%- if WEB_VARIANT -%> # Compile assets -RUN bin/rails i18n:js:export -RUN bin/rails assets:precompile +RUN bundle exec rails i18n:js:export +RUN bundle exec rails assets:precompile --trace RUN yarn postcss <%- end -%> diff --git a/.template/variants/web/template.rb b/.template/variants/web/template.rb index 52d58d03..fa1bdc3b 100644 --- a/.template/variants/web/template.rb +++ b/.template/variants/web/template.rb @@ -28,14 +28,13 @@ def apply_web_variant! after_bundle do use_source_path __dir__ - - # Generate translation file - run 'bundle exec rake i18n:js:export' - # Fix the default Rails template that does not put trailing commas run 'yarn run codebase:fix' apply 'spec/template.rb' + + # Generate translation file + run 'bundle exec rake i18n:js:export' end end From 771ccd206760881bd492b95688ffb364ef96e64e Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 6 Jun 2023 12:06:36 +0700 Subject: [PATCH 9/9] Try bundle install update before start.sh --- Makefile | 2 +- bin/start.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4015127d..8a89c20e 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ test_template: if [ $(VARIANT) = web ]; then \ bundle exec rspec --pattern="${base_spec}, ${web_spec}, ${base_addon_spec}, ${web_addon_spec}" --format progress; \ elif [ $(VARIANT) = api ]; then \ - bundle exec rspec --pattern="${base_spec}, ${api_spec}, ${base_addon_spec}, ${api_addon_spec}" --format progress; \ + bundle exec rspec --pattern="${base_spec}, ${api_spec}, ${base_addon_spec}, ${api_addon_spec}"; \ fi; cleanup: diff --git a/bin/start.sh b/bin/start.sh index 941c7423..9b28fbf4 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -7,6 +7,9 @@ if [ -f tmp/pids/server.pid ]; then rm -f tmp/pids/server.pid fi +bundle install +bundle update + # Run pending migrations (if any) and start rails bundle exec rails db:migrate bundle exec rails s -p $PORT -b 0.0.0.0