Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build and start scripts to DRGON #35

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DRGON_POSTGRES_PORT=XXXXXX
DRGON_POSTGRES_ADMIN_PASSWORD=XXXXXX
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/node_modules/*
.env
2 changes: 2 additions & 0 deletions Dockerfiles/Dockerfile.drgon-postgres
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM ubuntu:22.04
USER root

ARG DRGON_POSTGRES_ADMIN_PASSWORD="admin"

RUN apt update

# Install sudo (required by Ansible)
Expand Down
1 change: 1 addition & 0 deletions Dockerfiles/Dockerfile.drgon-server
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM ubuntu:20.04

ARG DRGON_POSTGRES_ADMIN_PASSWORD="admin"
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update

Expand Down
5 changes: 3 additions & 2 deletions ansible-playbooks/drgon-postgres-playbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
create: yes
- name: Set postgres' password
become_user: postgres
community.postgresql.postgresql_query:
query: ALTER USER postgres PASSWORD 'admin';
community.postgresql.postgresql_user:
name: postgres
password: "{{ lookup('env', 'DRGON_POSTGRES_ADMIN_PASSWORD') }}"
- name: Create new Postgres database
become_user: postgres
community.postgresql.postgresql_db:
Expand Down
34 changes: 34 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
echo "Building DRGON... this should only take a few minutes."
sh .env

export ENV_LOADED_STATUS=$(echo $?)
if [[ $ENV_LOADED_STATUS -ne 0 ]]; then
echo "Error: Could not load .env file."
exit 1
fi

command -v docker | export DOCKER_INSTALLED=$?
command -v docker-compose | export DOCKER_COMPOSE_INSTALLED=$?


if [[ $DOCKER_INSTALLED -ne 0 ]]; then
echo "Error: Docker is not installed on this machine."
exit 1
fi

if [[ $DOCKER_COMPOSE_INSTALLED -ne 0 ]]; then
echo "Error: Docker Compose is not installed on this machine."
exit 1
fi

docker compose build --build-arg DRGON_POSTGRES_ADMIN_PASSWORD

export BUILD_STATUS=$(echo $?)
if [[ $BUILD_STATUS -ne 0 ]]; then
echo "Error: DRGON did not build successfully."
exit 1
fi

echo "Done! You can start your DRGON instance by running the 'start.sh' script."
exit 0

6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
ports:
- "8000:8000"
hostname: drgon-server
environment:
DRGON_POSTGRES_ADMIN_PASSWORD: ${DRGON_POSTGRES_ADMIN_PASSWORD}
networks:
- drgon-network
drgon-postgres:
Expand All @@ -17,8 +19,10 @@ services:
dockerfile: ./Dockerfiles/Dockerfile.drgon-postgres
image: ghcr.io/geocml/drgon:postgres
ports:
- "5433:5433"
- "${DRGON_POSTGRES_PORT}:5433"
hostname: drgon-postgres
environment:
DRGON_POSTGRES_ADMIN_PASSWORD: ${DRGON_POSTGRES_ADMIN_PASSWORD}
networks:
- drgon-network
networks:
Expand Down
2 changes: 1 addition & 1 deletion src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { wipeDB } from "./utils.js"

const pgp = pgPromise({})

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

db.connect()
.then(async (obj) => {
Expand Down
34 changes: 34 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
echo "Starting DRGON... this should only take a moment."
sh .env

export ENV_LOADED_STATUS=$(echo $?)
if [[ $ENV_LOADED_STATUS -ne 0 ]]; then
echo "Error: Could not load .env file."
exit 1
fi

command -v docker | export DOCKER_INSTALLED=$?
command -v docker-compose | export DOCKER_COMPOSE_INSTALLED=$?


if [[ $DOCKER_INSTALLED -ne 0 ]]; then
echo "Error: Docker is not installed on this machine."
exit 1
fi

if [[ $DOCKER_COMPOSE_INSTALLED -ne 0 ]]; then
echo "Error: Docker Compose is not installed on this machine."
exit 1
fi

docker compose up -d

export START_STATUS=$(echo $?)
if [[ $START_STATUS -ne 0 ]]; then
echo "Error: DRGON did not start successfully."
exit 1
fi

echo "Done! You can stop your DRGON instance at any time with 'docker compose down'."
exit 0

Loading