Skip to content

Commit 4fb6bf4

Browse files
committed
Add build and start scripts to DRGON
1 parent 456edce commit 4fb6bf4

File tree

9 files changed

+84
-4
lines changed

9 files changed

+84
-4
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DRGON_POSTGRES_PORT=XXXXXX
2+
DRGON_POSTGRES_ADMIN_PASSWORD=XXXXXX

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/node_modules/*
2+
.env

Dockerfiles/Dockerfile.drgon-postgres

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM ubuntu:22.04
22
USER root
33

4+
ARG DRGON_POSTGRES_ADMIN_PASSWORD="admin"
5+
46
RUN apt update
57

68
# Install sudo (required by Ansible)

Dockerfiles/Dockerfile.drgon-server

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM ubuntu:20.04
22

3+
ARG DRGON_POSTGRES_ADMIN_PASSWORD="admin"
34
ARG DEBIAN_FRONTEND=noninteractive
45
RUN apt update
56

ansible-playbooks/drgon-postgres-playbook.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
create: yes
2727
- name: Set postgres' password
2828
become_user: postgres
29-
community.postgresql.postgresql_query:
30-
query: ALTER USER postgres PASSWORD 'admin';
29+
community.postgresql.postgresql_user:
30+
name: postgres
31+
password: "{{ lookup('env', 'DRGON_POSTGRES_ADMIN_PASSWORD') }}"
3132
- name: Create new Postgres database
3233
become_user: postgres
3334
community.postgresql.postgresql_db:

build.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
echo "Building DRGON... this should only take a few minutes."
2+
sh .env
3+
4+
export ENV_LOADED_STATUS=$(echo $?)
5+
if [[ $ENV_LOADED_STATUS -ne 0 ]]; then
6+
echo "Error: Could not load .env file."
7+
exit 1
8+
fi
9+
10+
command -v docker | export DOCKER_INSTALLED=$?
11+
command -v docker-compose | export DOCKER_COMPOSE_INSTALLED=$?
12+
13+
14+
if [[ $DOCKER_INSTALLED -ne 0 ]]; then
15+
echo "Error: Docker is not installed on this machine."
16+
exit 1
17+
fi
18+
19+
if [[ $DOCKER_COMPOSE_INSTALLED -ne 0 ]]; then
20+
echo "Error: Docker Compose is not installed on this machine."
21+
exit 1
22+
fi
23+
24+
docker compose build --build-arg DRGON_POSTGRES_ADMIN_PASSWORD
25+
26+
export BUILD_STATUS=$(echo $?)
27+
if [[ $BUILD_STATUS -ne 0 ]]; then
28+
echo "Error: DRGON did not build successfully."
29+
exit 1
30+
fi
31+
32+
echo "Done! You can start your DRGON instance by running the 'start.sh' script."
33+
exit 0
34+

docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ services:
99
ports:
1010
- "8000:8000"
1111
hostname: drgon-server
12+
environment:
13+
DRGON_POSTGRES_ADMIN_PASSWORD: ${DRGON_POSTGRES_ADMIN_PASSWORD}
1214
networks:
1315
- drgon-network
1416
drgon-postgres:
@@ -17,8 +19,10 @@ services:
1719
dockerfile: ./Dockerfiles/Dockerfile.drgon-postgres
1820
image: ghcr.io/geocml/drgon:postgres
1921
ports:
20-
- "5433:5433"
22+
- "${DRGON_POSTGRES_PORT}:5433"
2123
hostname: drgon-postgres
24+
environment:
25+
DRGON_POSTGRES_ADMIN_PASSWORD: ${DRGON_POSTGRES_ADMIN_PASSWORD}
2226
networks:
2327
- drgon-network
2428
networks:

src/db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { wipeDB } from "./utils.js"
33

44
const pgp = pgPromise({})
55

6-
export const db = pgp("postgres://postgres:admin@drgon-postgres:5433/drgon_db")
6+
export const db = pgp(`postgres://postgres:${process.env.DRGON_POSTGRES_ADMIN_PASSWORD}@drgon-postgres:5433/drgon_db`)
77

88
db.connect()
99
.then(async (obj) => {

start.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
echo "Starting DRGON... this should only take a moment."
2+
sh .env
3+
4+
export ENV_LOADED_STATUS=$(echo $?)
5+
if [[ $ENV_LOADED_STATUS -ne 0 ]]; then
6+
echo "Error: Could not load .env file."
7+
exit 1
8+
fi
9+
10+
command -v docker | export DOCKER_INSTALLED=$?
11+
command -v docker-compose | export DOCKER_COMPOSE_INSTALLED=$?
12+
13+
14+
if [[ $DOCKER_INSTALLED -ne 0 ]]; then
15+
echo "Error: Docker is not installed on this machine."
16+
exit 1
17+
fi
18+
19+
if [[ $DOCKER_COMPOSE_INSTALLED -ne 0 ]]; then
20+
echo "Error: Docker Compose is not installed on this machine."
21+
exit 1
22+
fi
23+
24+
docker compose up -d
25+
26+
export START_STATUS=$(echo $?)
27+
if [[ $START_STATUS -ne 0 ]]; then
28+
echo "Error: DRGON did not start successfully."
29+
exit 1
30+
fi
31+
32+
echo "Done! You can stop your DRGON instance at any time with 'docker compose down'."
33+
exit 0
34+

0 commit comments

Comments
 (0)