From 53eb5461fe2d65bcc2fea3305b6915b6feed4f07 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 26 Oct 2023 16:13:23 +0200 Subject: [PATCH] Add ENV vars to config file, switch to ERB template --- .github/workflows/ruby.yml | 2 +- .gitignore | 1 + config.yml.erb.example | 17 +++++++++++++++++ config.yml.example.s3 | 26 -------------------------- lib/remote_storage/s3.rb | 2 +- liquor-cabinet.rb | 2 +- spec/s3/app_spec.rb | 2 +- 7 files changed, 22 insertions(+), 30 deletions(-) create mode 100644 config.yml.erb.example delete mode 100644 config.yml.example.s3 diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 864c8f0..af92abc 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -28,6 +28,6 @@ jobs: with: redis-version: ${{ matrix.redis-version }} - name: Configure - run: cp config.yml.example.s3 config.yml + run: cp config.yml.erb.example config.yml.erb - name: Run tests run: bundle exec rake test diff --git a/.gitignore b/.gitignore index 6e8fc4a..ca1cbb6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config.yml +config.yml.erb cs_credentials.json pids .bundle diff --git a/config.yml.erb.example b/config.yml.erb.example new file mode 100644 index 0000000..3180337 --- /dev/null +++ b/config.yml.erb.example @@ -0,0 +1,17 @@ +development: &defaults + maintenance: false + redis: + host: <%= ENV["REDIS_HOST"] || "localhost" %> + port: <%= ENV["REDIS_PORT"] || "6379" %> + s3: &s3_defaults + endpoint: <%= ENV["S3_ENDPOINT"] || "http://127.0.0.1:9000" %> + region: <%= ENV["S3_REGION"] %> + access_key_id: <%= ENV["S3_ACCESS_KEY"] || "minioadmin" %> + secret_key_id: <%= ENV["S3_SECRET_KEY"] || "minioadmin" %> + bucket: <%= ENV["S3_BUCKET"] || "rs-development" %> +test: + <<: *defaults +staging: + <<: *defaults +production: + <<: *defaults diff --git a/config.yml.example.s3 b/config.yml.example.s3 deleted file mode 100644 index a0e654e..0000000 --- a/config.yml.example.s3 +++ /dev/null @@ -1,26 +0,0 @@ -development: &defaults - maintenance: false - s3: - endpoint: "https://some-endpoint" - region: "region" - access_key_id: "" - secret_key_id: "" - bucket: "test-bucket" - redis: - host: localhost - port: 6379 - -test: - <<: *defaults - s3: - endpoint: "https://some-endpoint" - region: "region" - access_key_id: "" - secret_key_id: "" - bucket: "test-bucket" - -staging: - <<: *defaults - -production: - <<: *defaults diff --git a/lib/remote_storage/s3.rb b/lib/remote_storage/s3.rb index c9ea3f2..e6c2a2a 100644 --- a/lib/remote_storage/s3.rb +++ b/lib/remote_storage/s3.rb @@ -106,7 +106,7 @@ module RemoteStorage end def container_url_for(user) - "#{base_url}#{settings.s3["bucket"]}/#{user}" + "#{base_url}/#{settings.s3["bucket"]}/#{user}" end end diff --git a/liquor-cabinet.rb b/liquor-cabinet.rb index 6568eb3..f823375 100644 --- a/liquor-cabinet.rb +++ b/liquor-cabinet.rb @@ -18,7 +18,7 @@ class LiquorCabinet < Sinatra::Base register Sinatra::ConfigFile set :environments, %w{development test production staging} - config_file 'config.yml' + config_file 'config.yml.erb' end configure :development do diff --git a/spec/s3/app_spec.rb b/spec/s3/app_spec.rb index 64f2e3d..f750070 100644 --- a/spec/s3/app_spec.rb +++ b/spec/s3/app_spec.rb @@ -2,7 +2,7 @@ require_relative "../spec_helper" describe "S3 provider" do def container_url_for(user) - "#{app.settings.s3["endpoint"]}#{app.settings.s3["bucket"]}/#{user}" + "#{app.settings.s3["endpoint"]}/#{app.settings.s3["bucket"]}/#{user}" end def storage_class