Repository navigation
Use env files instead of environment variables declared in docker-compose. Closes #1088 #1091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
71000fb
add makefile to create env files
guidopetri 1d5b1bb
convert docker compose to use env files. closes #1088
guidopetri 49f1c0a
update docker compose docs
guidopetri 4be1046
upgrade docker compose version
guidopetri efc05a1
convert makefile to rakefile commands
guidopetri 75dd1b5
remove : prefix from generate stringer rake cmd
guidopetri f19ed10
rubocop fixes
guidopetri 349e962
incorporate pr feedback
guidopetri 2aa84ee
use single .env file
guidopetri b24bdb6
add dependencies on env file creation or update
guidopetri ed2a2b4
add skeleton for init or update env
guidopetri 0f4db01
init or update env script
guidopetri f0bb1d5
don't require app initialization
guidopetri 9299a2b
use has_key instead of present
guidopetri e28ed30
add missing brace
guidopetri 072d395
move env volume to within /app folder
guidopetri 03e7166
fix docker compose env command
guidopetri f9daae6
fix hanging reference to postgres service
guidopetri 338a5a6
rubocop fixes
guidopetri ab14e88
fix docker compose to not require postgres health check
guidopetri c0ce367
remove old erb files
guidopetri ca621a2
update docs
guidopetri 38f8135
pr feedback
guidopetri 61fcd4f
set container names
guidopetri 973d481
missing comma
guidopetri de06a13
rubocop
guidopetri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,4 @@ spec/examples.txt | |
|
|
||
| # Ignore local .env files | ||
| *.local | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,46 @@ | ||
| version: '2' | ||
| version: '3' | ||
|
|
||
| services: | ||
| postgres: | ||
| stringer-setup: | ||
| image: stringerrss/stringer:latest | ||
| container_name: stringer-setup | ||
| restart: no | ||
| env_file: .env | ||
| volumes: | ||
| - ./.env:/app/.env | ||
| entrypoint: ["ruby"] | ||
| command: ["/app/docker/init_or_update_env.rb"] | ||
|
|
||
| stringer-postgres: | ||
| image: postgres:9.5-alpine | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Postgres raises an error when running within the container, but it seems unrelated to this PR. Upgrading the image to postgres 16 fixed the error, so I think this might just be a bad image that won't get updated now that 9.5 is out of date. |
||
| container_name: stringer-postgres | ||
| restart: always | ||
| depends_on: | ||
| stringer-setup: | ||
| condition: service_completed_successfully | ||
| networks: | ||
| - stringer-network | ||
| volumes: | ||
| - ~/stringer:/var/lib/postgresql/data | ||
| environment: | ||
| - POSTGRES_PASSWORD=super_secret_password | ||
| - POSTGRES_USER=db_user | ||
| - POSTGRES_DB=stringer | ||
| env_file: .env | ||
|
|
||
| web: | ||
| stringer: | ||
| image: stringerrss/stringer:latest | ||
| container_name: stringer | ||
| build: . | ||
| depends_on: | ||
| - postgres | ||
| stringer-postgres: | ||
| condition: service_started | ||
| stringer-setup: | ||
| condition: service_completed_successfully | ||
| restart: always | ||
| ports: | ||
| - 80:8080 | ||
| networks: | ||
| - stringer-network | ||
| environment: | ||
| - SECRET_KEY_BASE=<your configuration> | ||
| - ENCRYPTION_PRIMARY_KEY=<your configuration> | ||
| - ENCRYPTION_DETERMINISTIC_KEY=<your configuration> | ||
| - ENCRYPTION_KEY_DERIVATION_SALT=<your configuration> | ||
| - PORT=8080 | ||
| - DATABASE_URL=postgres://db_user:super_secret_password@postgres:5432/stringer | ||
| env_file: .env | ||
|
|
||
| networks: | ||
| stringer-network: | ||
| external: false | ||
| name: stringer-network | ||
| name: stringer-network | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Secrets | ||
| def self.generate_secret(length) | ||
| `openssl rand -hex #{length}`.strip | ||
| end | ||
| end | ||
|
|
||
| pg_user = ENV.fetch("POSTGRES_USER", "stringer") | ||
| pg_password = ENV.fetch("POSTGRES_PASSWORD", Secrets.generate_secret(32)) | ||
| pg_host = ENV.fetch("POSTGRES_HOSTNAME", "stringer-postgres") | ||
| pg_db = ENV.fetch("POSTGRES_DB", "stringer") | ||
|
|
||
| required_env = { | ||
| "SECRET_KEY_BASE" => Secrets.generate_secret(64), | ||
| "ENCRYPTION_PRIMARY_KEY" => Secrets.generate_secret(64), | ||
| "ENCRYPTION_DETERMINISTIC_KEY" => Secrets.generate_secret(64), | ||
| "ENCRYPTION_KEY_DERIVATION_SALT" => Secrets.generate_secret(64), | ||
| "POSTGRES_USER" => pg_user, | ||
| "POSTGRES_PASSWORD" => pg_password, | ||
| "POSTGRES_HOSTNAME" => pg_host, | ||
| "POSTGRES_DB" => pg_db, | ||
| "FETCH_FEEDS_CRON" => "*/5 * * * *", | ||
| "CLEANUP_CRON" => "0 0 * * *", | ||
| "DATABASE_URL" => "postgres://#{pg_user}:#{pg_password}@#{pg_host}/#{pg_db}" | ||
| } | ||
|
|
||
| required_env.each do |key, value| | ||
| next if ENV.key?(key) | ||
|
|
||
| File.open("/app/.env", "a") { |file| file << "#{key}=#{value}\n" } | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.