From 8edb8c6dba78624b02e4c67b28d330421b61c050 Mon Sep 17 00:00:00 2001 From: Blair Vanderlugt Date: Tue, 9 Feb 2021 17:32:36 +0000 Subject: [PATCH] meta docker compose --- README.md | 14 ++++- apps/cic-meta/docker/Dockerfile | 2 +- apps/cic-meta/scripts/initdb/postgresql.sh | 15 +++++ .../{server => initdb}/server.postgres.sql | 2 +- .../scripts/{server => initdb}/server.sql | 0 .../{server => initdb}/server.sqlite.sql | 0 docker-compose.yml | 62 ++++++++++--------- scripts/initdb/create_db.sql | 0 8 files changed, 63 insertions(+), 32 deletions(-) create mode 100755 apps/cic-meta/scripts/initdb/postgresql.sh rename apps/cic-meta/scripts/{server => initdb}/server.postgres.sql (81%) mode change 100644 => 100755 rename apps/cic-meta/scripts/{server => initdb}/server.sql (100%) mode change 100644 => 100755 rename apps/cic-meta/scripts/{server => initdb}/server.sqlite.sql (100%) mode change 100644 => 100755 mode change 100644 => 100755 scripts/initdb/create_db.sql diff --git a/README.md b/README.md index d43e638..9faa673 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ ## Getting started +### Prepare the repo + +This is stuff we need to put in makefile but for now... + +File mounts and permisssions need to be set +``` +chmod -R 755 scripts/initdb apps/cic-meta/scripts/initdb +```` + start cluster ``` docker-compose up @@ -20,6 +29,7 @@ docker-compose down -v rebuild an images ``` docker-compose up --build -`` +``` + +Deployment variables are writtend to service-configs/.env after everthing is up. -Deployment variables are writtend to service-configs/.env after everthing is up.` diff --git a/apps/cic-meta/docker/Dockerfile b/apps/cic-meta/docker/Dockerfile index d44ff4b..d344017 100644 --- a/apps/cic-meta/docker/Dockerfile +++ b/apps/cic-meta/docker/Dockerfile @@ -16,7 +16,7 @@ COPY cic-meta/scripts/ scripts/ RUN alias tsc=node_modules/typescript/bin/tsc COPY cic-meta/.config/ /usr/local/etc/cic-meta/ -COPY cic-meta/scripts/server/server.postgres.sql /usr/local/share/cic-meta/sql/server.sql +# COPY cic-meta/scripts/server/initdb/server.postgres.sql /usr/local/share/cic-meta/sql/server.sql COPY cic-meta/docker/db.sh ./db.sh RUN chmod 755 ./db.sh diff --git a/apps/cic-meta/scripts/initdb/postgresql.sh b/apps/cic-meta/scripts/initdb/postgresql.sh new file mode 100755 index 0000000..75b8ac0 --- /dev/null +++ b/apps/cic-meta/scripts/initdb/postgresql.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +psql -v ON_ERROR_STOP=1 --username grassroots --dbname cic_meta <<-EOSQL + create table if not exists store ( + id serial primary key not null, + owner_fingerprint text not null, + hash char(64) not null unique, + content text not null + ); + + create index if not exists idx_fp on store ((lower(owner_fingerprint))); +EOSQL + + diff --git a/apps/cic-meta/scripts/server/server.postgres.sql b/apps/cic-meta/scripts/initdb/server.postgres.sql old mode 100644 new mode 100755 similarity index 81% rename from apps/cic-meta/scripts/server/server.postgres.sql rename to apps/cic-meta/scripts/initdb/server.postgres.sql index 93a2d13..3eb032b --- a/apps/cic-meta/scripts/server/server.postgres.sql +++ b/apps/cic-meta/scripts/initdb/server.postgres.sql @@ -1,4 +1,4 @@ -create table if not exists store ( +create table if not exists cic_meta.store ( id serial primary key not null, owner_fingerprint text not null, hash char(64) not null unique, diff --git a/apps/cic-meta/scripts/server/server.sql b/apps/cic-meta/scripts/initdb/server.sql old mode 100644 new mode 100755 similarity index 100% rename from apps/cic-meta/scripts/server/server.sql rename to apps/cic-meta/scripts/initdb/server.sql diff --git a/apps/cic-meta/scripts/server/server.sqlite.sql b/apps/cic-meta/scripts/initdb/server.sqlite.sql old mode 100644 new mode 100755 similarity index 100% rename from apps/cic-meta/scripts/server/server.sqlite.sql rename to apps/cic-meta/scripts/initdb/server.sqlite.sql diff --git a/docker-compose.yml b/docker-compose.yml index 89f6d92..89836d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,12 +47,13 @@ services: image: postgres:12.5-alpine environment: POSTGRES_HOST_AUTH_METHOD: trust # for postgres user access w/o password. Obvioulsy not safe but allows easy elevated debugging. - PGDATA: /tmp/cic/postgres + # PGDATA: /tmp/cic/postgres ports: - 5432 volumes: - - ./scripts/initdb/create_db.sql:/docker-entrypoint-initdb.d/1-create_all_db.sql # init db scripts will run in order at container start - - postgres-db:/tmp/cic/postgres + - ./scripts/initdb/create_db.sql:/docker-entrypoint-initdb.d/1-create_all_db.sql + - ./apps/cic-meta/scripts/initdb/postgresql.sh:/docker-entrypoint-initdb.d/2-init-cic-meta.sh + - postgres-db:/var/lib/postgresql/data redis: image: redis:6.0.9-alpine @@ -394,31 +395,36 @@ services: command: "/root/start_tasker.sh -q cic-notify" -# cic-meta-server: -# image: grassrootseconomics:cic-meta-server -# environment: -# DATABASE_USER: $DATABASE_USER -# DATABASE_HOST: $DATABASE_HOST -# DATABASE_PORT: $DATABASE_PORT -# DATABASE_PASSWORD: $DATABASE_PASSWORD -# DATABASE_NAME: $DATABASE_NAME_CIC_META -# DATABASE_ENGINE: $DATABASE_ENGINE -# DATABASE_DRIVER: $DATABASE_DRIVER -# DATABASE_SCHEMA_SQL_PATH: $DATABASE_SCHEMA_SQL_PATH_CIC_META -# SERVER_PORT: 80 -# PGP_PASSPHRASE: $PGP_PASSPHRASE -# PGP_EXPORTS_DIR: $PGP_EXPORTS_DIR -# PGP_PRIVATEKEY_FILE: $PGP_PRIVATEKEY_FILE -# ports: -# - ${HTTP_PORT_CIC_META}:80 -# depends_on: -# - postgres -# deploy: -# restart_policy: -# condition: on-failure -# volumes: -# - ${LOCAL_VOLUME_DIR:-/tmp/cic}/pgp:/tmp/cic/pgp -# command: "/root/start_server.sh -vv" + cic-meta-server: + build: + context: apps/ + dockerfile: cic-meta/docker/Dockerfile + environment: + DATABASE_NAME: ${DATABASE_NAME:-cic_meta} + DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres} + DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2} + DATABASE_USER: ${DATABASE_USER:-grassroots} + DATABASE_HOST: ${DATABASE_HOST:-postgres} + DATABASE_PORT: ${DATABASE_PORT:-5432} + SERVER_HOST: ${SERVER_HOST:-localhost} + SERVER_PORT: ${SERVER_HOST:-80} + DATABASE_SCHEMA_SQL_PATH: "" + PGP_EXPORTS_DIR: /tmp/src/cic-meta/tests/ + PGP_PRIVATEKEY_FILE: privatekeys.asc + PGP_PASSPHRASE: merman + PGP_PUBLICKEY_TRUSTED_FILE: publickeys.asc + PGP_PUBLICKEY_ACTIVE_FILE: publickeys.asc + PGP_PUBLICKEY_ENCRYPT_FILE: publickeys.asc + ports: + - ${HTTP_PORT_CIC_META:-63380}:${SERVER_PORT:-80} + depends_on: + - postgres + deploy: + restart_policy: + condition: on-failure + volumes: + - ${LOCAL_VOLUME_DIR:-/tmp/cic}/pgp:/tmp/cic/pgp + command: "/root/start_server.sh -vv" # cic-ussd-server: # # image: grassrootseconomics:cic-ussd diff --git a/scripts/initdb/create_db.sql b/scripts/initdb/create_db.sql old mode 100644 new mode 100755