Skip to content

Commit

Permalink
Test with .env.local for non sensistive ENV VAR
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jun 2, 2023
1 parent 9f69741 commit a2d409d
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 35 deletions.
7 changes: 2 additions & 5 deletions .env.example → .env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions .env.development.example
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .gitignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions .template/addons/docker/Dockerfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .template/addons/docker/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions .template/hooks/before_complete/copy_env_example.rb

This file was deleted.

4 changes: 0 additions & 4 deletions .template/spec/addons/base/docker/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .template/spec/base/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .template/spec/support/serverspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; \
Expand Down
6 changes: 2 additions & 4 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a2d409d

Please sign in to comment.