Skip to content
Merged
Show file tree
Hide file tree
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 Aug 26, 2023
1d5b1bb
convert docker compose to use env files. closes #1088
guidopetri Aug 26, 2023
49f1c0a
update docker compose docs
guidopetri Aug 26, 2023
4be1046
upgrade docker compose version
guidopetri Aug 26, 2023
efc05a1
convert makefile to rakefile commands
guidopetri Sep 8, 2023
75dd1b5
remove : prefix from generate stringer rake cmd
guidopetri Sep 9, 2023
f19ed10
rubocop fixes
guidopetri Sep 9, 2023
349e962
incorporate pr feedback
guidopetri Sep 9, 2023
2aa84ee
use single .env file
guidopetri Oct 23, 2023
b24bdb6
add dependencies on env file creation or update
guidopetri Oct 23, 2023
ed2a2b4
add skeleton for init or update env
guidopetri Oct 23, 2023
0f4db01
init or update env script
guidopetri Oct 27, 2023
f0bb1d5
don't require app initialization
guidopetri Oct 27, 2023
9299a2b
use has_key instead of present
guidopetri Oct 27, 2023
e28ed30
add missing brace
guidopetri Oct 27, 2023
072d395
move env volume to within /app folder
guidopetri Oct 27, 2023
03e7166
fix docker compose env command
guidopetri Oct 27, 2023
f9daae6
fix hanging reference to postgres service
guidopetri Oct 27, 2023
338a5a6
rubocop fixes
guidopetri Oct 27, 2023
ab14e88
fix docker compose to not require postgres health check
guidopetri Oct 27, 2023
c0ce367
remove old erb files
guidopetri Oct 27, 2023
ca621a2
update docs
guidopetri Oct 27, 2023
38f8135
pr feedback
guidopetri Nov 1, 2023
61fcd4f
set container names
guidopetri Nov 2, 2023
973d481
missing comma
guidopetri Nov 2, 2023
de06a13
rubocop
guidopetri Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ spec/examples.txt

# Ignore local .env files
*.local
.env
41 changes: 25 additions & 16 deletions docker-compose.yml
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:
Comment thread
mockdeep marked this conversation as resolved.
Resolved
image: postgres:9.5-alpine

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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
32 changes: 32 additions & 0 deletions docker/init_or_update_env.rb
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
10 changes: 9 additions & 1 deletion docs/Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

## Production ready setup using docker-compose

Download [docker-compose.yml](../docker-compose.yml) and in the corresponding folder, run `docker-compose up -d`, give it a second and visit `localhost`
Create a local environment file named `.env`, e.g. via `touch .env`.

Download [docker-compose.yml](../docker-compose.yml) and run:

```sh
touch .env && docker compose up -d
```

Give it a second and visit `localhost`!

## Production ready manual setup

Expand Down