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 68bf0f65..3351fc43 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 assets:precompile 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..d7ef9854 100644 --- a/.template/spec/support/serverspec.rb +++ b/.template/spec/support/serverspec.rb @@ -7,6 +7,9 @@ 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') container_id = `docker ps -qf "name=#{ENV.fetch('APP_NAME')}_test"` Docker::Container.get(container_id.strip) 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