Skip to content

Commit

Permalink
Add docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Jan 18, 2024
1 parent bfc98f5 commit 4293694
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 128 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ apps/promisetracker/public/data/**
!apps/promisetracker/public/data/README.md

# Storybook
storybook-static
storybook-static

mongo-keyfile
1 change: 1 addition & 0 deletions Dockerfile.charterafrica
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ARG NEXT_TELEMETRY_DISABLED=1 \
PAYLOAD_PUBLIC_APP_URL=http://localhost:3000 \
PAYLOAD_SECRET_KEY

RUN cd apps/charterafrica && npx payload migrate && cd ../../
RUN pnpm build-next --filter=charterafrica

# Needed by Payload at Payload build time
Expand Down
108 changes: 0 additions & 108 deletions Dockerfile.dev.charterafrica

This file was deleted.

19 changes: 0 additions & 19 deletions charterafrica-dev.yml

This file was deleted.

59 changes: 59 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: "3.8"

services:
charterafrica:
depends_on:
mongodb_container:
condition: service_healthy
build:
context: .
dockerfile: Dockerfile.charterafrica
args:
MONGO_URL: mongodb://root:rootpassword@host.docker.internal:27017/charterafrica?authSource=admin
PAYLOAD_SECRET_KEY: ${PAYLOAD_SECRET_KEY}
SENTRY_AUTH_TOKEN: ${SENTRY_AUTH_TOKEN}
SENTRY_ORG: ${SENTRY_ORG}
NEXT_PUBLIC_SENTRY_DSN: ${CHARTERAFRICA_SENTRY_DSN}
SENTRY_ENV: ${SENTRY_ENV}
SENTRY_PROJECT: ${SENTRY_PROJECT}
ports:
- 3000:3000
container_name: charterafrica
env_file:
- apps/charterafrica/.env.local
networks:
- net

mongodb_container:
container_name: mongodb_container
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: rootpassword
ports:
- 27017:27017
volumes:
- data_container:/data/db
- ./mongo-keyfile:/etc/mongo-keyfile
- ./scripts/db-init.sh:/scripts/db-init.sh
restart: always
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh mongodb_container:27017/charterafrica --quiet
interval: 10s
timeout: 5s
retries: 3
command:
[
"--replSet",
"dbrs",
"--bind_ip_all",
"--keyFile",
"/etc/mongo-keyfile/mongo-keyfile",
]
networks:
- net
volumes:
data_container:
networks:
net:
driver: bridge
8 changes: 8 additions & 0 deletions scripts/charterafrica.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

docker-compose --env-file apps/charterafrica/.env.local up charterafrica --build -d

sleep 5

docker exec mongodb_container /scripts/db-init.sh

31 changes: 31 additions & 0 deletions scripts/db-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

DELAY=5

mongosh -u root -p rootpassword --authenticationDatabase admin <<EOF
var config = {
"_id": "dbrs",
"version": 1,
"members": [
{
"_id": 1,
"host": "mongodb_container:27017",
"priority": 1
},
]
};
rs.initiate(config, { force: true });
EOF

echo "****** Waiting for ${DELAY} seconds for replicaset configuration to be applied ******"

sleep $DELAY

mongosh -u root -p rootpassword --authenticationDatabase admin <<EOF
rs.status();
db.createUser({
user: "root",
pwd: "rootpassword",
roles: [{ role: "root", db: "admin" }],
});
EOF

0 comments on commit 4293694

Please sign in to comment.