diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a0ba4f3 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +DRGON_POSTGRES_PORT=XXXXXX +DRGON_POSTGRES_ADMIN_PASSWORD=XXXXXX diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f45c0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +src/node_modules/* +.env diff --git a/Dockerfiles/Dockerfile.drgon-postgres b/Dockerfiles/Dockerfile.drgon-postgres index 8031c32..d8e668a 100644 --- a/Dockerfiles/Dockerfile.drgon-postgres +++ b/Dockerfiles/Dockerfile.drgon-postgres @@ -1,6 +1,8 @@ FROM ubuntu:22.04 USER root +ARG DRGON_POSTGRES_ADMIN_PASSWORD="admin" + RUN apt update # Install sudo (required by Ansible) diff --git a/Dockerfiles/Dockerfile.drgon-server b/Dockerfiles/Dockerfile.drgon-server index 5ab3ad7..399a3d7 100644 --- a/Dockerfiles/Dockerfile.drgon-server +++ b/Dockerfiles/Dockerfile.drgon-server @@ -1,5 +1,6 @@ FROM ubuntu:20.04 +ARG DRGON_POSTGRES_ADMIN_PASSWORD="admin" ARG DEBIAN_FRONTEND=noninteractive RUN apt update diff --git a/ansible-playbooks/drgon-postgres-playbook.yaml b/ansible-playbooks/drgon-postgres-playbook.yaml index 451a60e..b953082 100644 --- a/ansible-playbooks/drgon-postgres-playbook.yaml +++ b/ansible-playbooks/drgon-postgres-playbook.yaml @@ -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: diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..2601121 --- /dev/null +++ b/build.sh @@ -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 + diff --git a/docker-compose.yml b/docker-compose.yml index a0d4190..de490dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,27 +1,31 @@ --- version: "3.7" services: - drgon-server: + drgon-server-dev: build: context: . dockerfile: ./Dockerfiles/Dockerfile.drgon-server image: ghcr.io/geocml/drgon:server ports: - - "8000:8000" + - "8080:8000" hostname: drgon-server + environment: + DRGON_POSTGRES_ADMIN_PASSWORD: ${DRGON_POSTGRES_ADMIN_PASSWORD} networks: - - drgon-network - drgon-postgres: + - drgon-network-dev + drgon-postgres-dev: build: context: . 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 + - drgon-network-dev networks: - drgon-network: + drgon-network-dev: external: true driver: bridge diff --git a/src/db.js b/src/db.js index 77ce59b..343252a 100644 --- a/src/db.js +++ b/src/db.js @@ -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) => { diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..bdea2be --- /dev/null +++ b/start.sh @@ -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 +