Skip to content

Commit 8bfd20d

Browse files
authored
Merge pull request #93 from Owen000/main
Make postgres password dynamic
2 parents ee5cbb7 + 9abc873 commit 8bfd20d

8 files changed

Lines changed: 30 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ riderModule.iml
55
/_ReSharper.Caches/
66
.DS_Store
77
.idea/
8+
.env
89

910
src/Zilean.Scraper/python/
1011
src/Zilean.ApiService/python/

docs/Writerside/snippets/compose-file.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ services:
99
restart: unless-stopped
1010
container_name: zilean
1111
tty: true
12+
environment:
13+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
1214
ports:
1315
- "8181:8181"
1416
volumes:
@@ -31,12 +33,12 @@ services:
3133
environment:
3234
PGDATA: /var/lib/postgresql/data/pgdata
3335
POSTGRES_USER: postgres
34-
POSTGRES_PASSWORD: postgres
36+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
3537
POSTGRES_DB: zilean
3638
volumes:
3739
- postgres_data:/var/lib/postgresql/data/pgdata
3840
healthcheck:
3941
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
4042
interval: 10s
4143
timeout: 5s
42-
retries: 5
44+
retries: 5

docs/Writerside/snippets/default-settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"EnableEndpoint": true
1616
},
1717
"Database": {
18-
"ConnectionString": "Host=postgres;Database=zilean;Username=postgres;Password=postgres;Include Error Detail=true;Timeout=30;CommandTimeout=3600;"
18+
"ConnectionString": "Host=postgres;Database=zilean;Username=postgres;Password=$POSTGRES_PASSWORD;Include Error Detail=true;Timeout=30;CommandTimeout=3600;"
1919
},
2020
"Torrents": {
2121
"EnableEndpoint": false,

docs/Writerside/snippets/settings-with-ingestion.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"EnableEndpoint": true
1616
},
1717
"Database": {
18-
"ConnectionString": "Host=localhost;Database=zilean;Username=postgres;Password=postgres;Include Error Detail=true;Timeout=30;CommandTimeout=3600;"
18+
"ConnectionString": "Host=localhost;Database=zilean;Username=postgres;Password=$POSTGRES_PASSWORD;Include Error Detail=true;Timeout=30;CommandTimeout=3600;"
1919
},
2020
"Torrents": {
2121
"EnableEndpoint": true,

docs/Writerside/topics/Configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ _Default: `true`_
6767
### Database Configuration
6868
**Database.ConnectionString**
6969
_The connection string for the PostgreSQL database._
70-
_Default: `Host=localhost;Database=zilean;Username=postgres;Password=postgres;Include Error Detail=true;Timeout=30;CommandTimeout=3600;`_
70+
_$POSTGRES_PASSWORD should be replaced with the password in your .env_
71+
_Default: `Host=localhost;Database=zilean;Username=postgres;Password=$POSTGRES_PASSWORD;Include Error Detail=true;Timeout=30;CommandTimeout=3600;`_
7172

7273
The database connection string comprises of the following:
7374
- `Host`: The host of the database, this will usually be the `containername` if you are using docker compose of the postgres instance.

docs/Writerside/topics/Getting-Started.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ The easiest way to get up and running with %Product% is to use the provided dock
1818
Ensure you have the following installed:
1919
- Docker, Docker Desktop or Podman
2020

21+
First, generate your postgres password with
22+
23+
```bash
24+
echo "POSTGRES_PASSWORD=$(openssl rand -base64 42 | tr -dc A-Za-z0-9 | cut -c -32 | tr -d '\n')" > .env
25+
```
26+
2127
The example compose file below can be copied, and used to get the system running locally.
2228

2329
```yaml
@@ -40,4 +46,4 @@ docker compose pull %product%
4046

4147
> Please Note - Always make sure you check the [github release notes](https://github.com/iPromKnight/zilean/releases) for the latest release, to ensure there are no breaking changes.
4248
> The changelog can also be viewed [here](https://github.com/iPromKnight/zilean/blob/main/CHANGELOG.md).
43-
{ style="note" }
49+
{ style="note" }

eng/compose-dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ services:
66
environment:
77
PGDATA: /var/lib/postgresql/data/pgdata
88
POSTGRES_USER: postgres
9-
POSTGRES_PASSWORD: postgres
9+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
1010
POSTGRES_DB: postgres
1111
ports:
1212
- "5432:5432"
1313
healthcheck:
1414
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
1515
interval: 10s
1616
timeout: 5s
17-
retries: 5
17+
retries: 5

src/Zilean.Shared/Features/Configuration/DatabaseConfiguration.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,16 @@ namespace Zilean.Shared.Features.Configuration;
22

33
public class DatabaseConfiguration
44
{
5-
public string ConnectionString { get; set; } = "Host=postgres;Database=zilean;Username=postgres;Password=postgres;Include Error Detail=true;Timeout=30;CommandTimeout=3600;";
5+
public string ConnectionString { get; set; }
6+
7+
public DatabaseConfiguration()
8+
{
9+
var password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD");
10+
if (string.IsNullOrWhiteSpace(password))
11+
{
12+
throw new InvalidOperationException("Environment variable POSTGRES_PASSWORD is not set.");
13+
}
14+
15+
ConnectionString = $"Host=postgres;Database=zilean;Username=postgres;Password={password};Include Error Detail=true;Timeout=30;CommandTimeout=3600;";
16+
}
617
}

0 commit comments

Comments
 (0)