Skip to content

Commit 2e9d9db

Browse files
committed
cosmetic changes, improve readme, variable naming, remove redundancy
1 parent ce2761b commit 2e9d9db

File tree

4 files changed

+25
-60
lines changed

4 files changed

+25
-60
lines changed

common/db/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM samagragovernance/postgres:1.0.1-pg15
22

33
ARG ENABLE_BARMAN
4-
ARG ID_RSA
5-
ARG ID_RSA_PUB
4+
ARG DB_SSH_PRIVATE_KEY
5+
ARG DB_SSH_PUBLIC_KEY
66
ARG BARMAN_HOST
77

8+
ENV BARMAN_HOST=$BARMAN_HOST
9+
810
ADD config/postgresql.conf.template /etc/postgresql/postgresql.conf.template
911
ADD config/pg_hba.conf.template /etc/postgresql/pg_hba.conf.template
1012

@@ -29,8 +31,8 @@ RUN if [ "$ENABLE_BARMAN" = "true" ]; then \
2931
echo -e "PasswordAuthentication no" >> /etc/ssh/sshd_config && \
3032
mkdir -p /var/lib/postgresql/.ssh && \
3133
echo "" > /var/lib/postgresql/.ssh/known_hosts && \
32-
echo "$ID_RSA" | base64 -d > /var/lib/postgresql/.ssh/id_rsa && \
33-
echo "$ID_RSA_PUB" | base64 -d > /var/lib/postgresql/.ssh/id_rsa.pub && \
34+
echo "$DB_SSH_PRIVATE_KEY" | base64 -d > /var/lib/postgresql/.ssh/id_rsa && \
35+
echo "$DB_SSH_PUBLIC_KEY" | base64 -d > /var/lib/postgresql/.ssh/id_rsa.pub && \
3436
chmod 0600 /var/lib/postgresql/.ssh/id_rsa && \
3537
echo -e "Host *\n\tStrictHostKeyChecking no" > /var/lib/postgresql/.ssh/config && \
3638
passwd -u postgres && \

common/db/README.md

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
1-
#### How to sping up the db service along with disaster recovery setup.
1+
### Generating Key Pair for DB
22

3-
1. Create a clone of this repository
4-
2. Create a copy of [sample.env](./common/sample.env) file (`cp common/sample.env .env`)
5-
3. **Update the environment variables in the .env file as required** ( refer to below required environment variables)
6-
4. Create a copy of example docker-compose file (`cp docker-compose.yaml.example docker-compose.yaml`)
7-
5. Edit the docker-compose.yaml and uncomment the "db" service.
8-
6. Create a copy of example Caddyfile (`cp Caddyfile.example Caddyfile`)
9-
7. Run `make install-docker` to install docker
10-
8. Exit out of VM and re-connect to the VM to reflect the latest user changes
11-
9. Run `make setup-daemon` to configure the docker daemon
12-
10. Run `sudo make setup-webhook` to start the webhook service (use `kill -9 $(lsof -t -i:9000)` to kill any existing service on 9000 port)
13-
11. Run `make deploy` to deploy all the services
3+
1. RUN `ssh-keygen -t rsa` to generate a key pair
4+
2. Set value of `cat ~/.ssh/id_rsa | base64 -w 0` in DB_SSH_PRIVATE_KEY (change the location of private key in command if needed)
5+
3. Set value of `cat ~/.ssh/id_rsa.pub | base64 -w 0` in DB_SSH_PUBLIC_KEY (change the location of private key in command if needed)
146

7+
### Steps to follow after the db container is started (only if you have enabled barman)
158

16-
##### REQUIRED ENVIRONMENT VARIABLES IN .env FILE
9+
1. Currently the ssh server doesn't start automatically, run `docker exec -it DB_CONTAINER_ID /usr/sbin/sshd` to start the ssh server inside the db container
1710

18-
```
19-
DOMAIN_SCHEME=http
20-
DOMAIN_NAME=localdev.me
21-
ENABLE_BARMAN=
22-
BARMAN_HOST=
23-
ID_RSA=
24-
ID_RSA_PUB=
25-
POSTGRES_USER=
26-
POSTGRES_PASSWORD=
27-
```
28-
```
29-
1. ENABLE_BARMAN (required ) : To tell service if database needs to be configured with barman disaster recovery/
30-
2. BARMAN_HOST (required if ENABLE_BARMAN is set to true ) : IP of barman host where data needs to be replicated.
31-
3. ID_RSA (required if ENABLE_BARMAN is set to true ) : private key of postgres user which will be stored in /var/lib/postgresql/.ssh/id_rsa.
32-
4. ID_RSA_PUB= (required if ENABLE_BARMAN is set to true ) private key of postgres user which will be stored in /var/lib/postgresql/.ssh/id_rsa_pub.
33-
5. POSTGRES_USER= (required) : User for postgres database (e.g postgres)
34-
6. POSTGRES_PASSWORD= (required) : Password for postgres database user
35-
```
11+
### Steps to setup Barman
3612

13+
1. Run `make setup-barman` to setup barman
3714

38-
###### NOTE: If ENABLE_BARMAN was set to true there are three additional efforts :
39-
a) It requires a manual start of sshd service with below command.
40-
> docker exec -it CONTAINER_ID /usr/sbin/sshd
15+
> [!NOTE]
4116
42-
b) Key pair needs to be generated and set the required value to .env file. Refer to below example:
43-
> ssh-keygen
44-
45-
Content of below command should go to ID_RSA
46-
> cat ~/.ssh/id_rsa | base64 -w 0
47-
48-
Content of below command should go to ID_RSA_PUB
49-
> cat ~/.ssh/id_rsa.pub | base64 -w 0
50-
51-
52-
c) copy the public key of postgres user from container and add it in /var/lib/barman/.ssh/authorized_keys of barman server.
53-
> docker exec -it CONTAINER_ID cat /var/lib/postgresql/.ssh/id_rsa.pub
17+
> 1. We will require the public key generated here while we setup Barman

common/db/docker-compose.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ services:
44
context: ./
55
dockerfile: Dockerfile
66
args:
7-
ENABLE_BARMAN: ${ENABLE_BARMAN}
7+
ENABLE_BARMAN: ${ENABLE_BARMAN:-false}
88
BARMAN_HOST: ${BARMAN_HOST}
9-
ID_RSA: ${ID_RSA}
10-
ID_RSA_PUB: ${ID_RSA_PUB}
9+
DB_SSH_PUBLIC_KEY: ${DB_SSH_PUBLIC_KEY}
10+
DB_SSH_PRIVATE_KEY: ${DB_SSH_PRIVATE_KEY}
1111
restart: always
1212
volumes:
1313
- db:/var/lib/postgresql/data
@@ -21,11 +21,9 @@ services:
2121
timeout: 5s
2222
retries: 5
2323
environment:
24-
POSTGRES_USER: ${POSTGRES_USER:?Postgres user is not set in .env}
25-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Postgres password is not set in .env}
26-
BARMAN_HOST: ${BARMAN_HOST:?Barman host is not defined in .env}
24+
POSTGRES_USER: ${POSTGRES_USER:?POSTGRES_USER is not set in .env}
25+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is not set in .env}
2726

2827
volumes:
2928
db:
30-
ssh-vol:
3129

common/sample.env

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ MINIO_ACCESS_KEY=
55
MINIO_SECRET_KEY=
66

77

8-
## For db service
8+
# For db service
9+
# default value is false, set it to true to enable barman
910
ENABLE_BARMAN=
1011
BARMAN_HOST=
11-
ID_RSA=
12-
ID_RSA_PUB=
12+
DB_SSH_PRIVATE_KEY=
13+
DB_SSH_PUBLIC_KEY=
1314
POSTGRES_USER=
1415
POSTGRES_PASSWORD=
1516

0 commit comments

Comments
 (0)