From 519377723489a95a384c9c09f2247342c031a1f1 Mon Sep 17 00:00:00 2001
From: ChakshuGautam <chaks.gautam@gmail.com>
Date: Sat, 11 Mar 2023 08:15:05 +0530
Subject: [PATCH] Fix: Add minio and central

---
 .env                                       |   5 +-
 .gitpod.yml                                |  25 +++-
 central-config/.env                        |  35 +++++
 central-config/postgres-upgrade.dockerfile |  16 +++
 docker-compose.central.yaml                | 152 ---------------------
 docker-compose.gitpod.yaml                 |  15 +-
 install-central.sh                         |  15 ++
 7 files changed, 108 insertions(+), 155 deletions(-)
 create mode 100644 central-config/.env
 create mode 100644 central-config/postgres-upgrade.dockerfile
 delete mode 100644 docker-compose.central.yaml
 create mode 100644 install-central.sh

diff --git a/.env b/.env
index 61722d4..b1bd93c 100644
--- a/.env
+++ b/.env
@@ -3,4 +3,7 @@ POSTGRES_PASSWORD=postgres
 DATABASE_USERNAME=fusionauth
 DATABASE_PASSWORD=hkaLBM3RVnyYeYeqE3WI1w2e4Avpy0Wd5O3s3
 ES_JAVA_OPTS="-Xms512m -Xmx512m"
-FUSIONAUTH_APP_MEMORY=512M
\ No newline at end of file
+FUSIONAUTH_APP_MEMORY=512M
+
+MINIO_USERNAME=workflow-dev
+MINIO_PASSWORD=workflow-dev
\ No newline at end of file
diff --git a/.gitpod.yml b/.gitpod.yml
index 06fa2f6..e5782ed 100644
--- a/.gitpod.yml
+++ b/.gitpod.yml
@@ -1,7 +1,15 @@
 tasks:
+  - name: Setup Development Env
+    openMode: tab-after
+    init: |
+      sudo apt update
+      sudo apt install gh
+      gp sync-done dev-setup
+  - name: Install ODK Central
   - name: Setup Enketo Express
     openMode: tab-after
     init: |
+      gp sync-done dev-setup
       bash install-node.sh
       nvm use 14
       cd packages/enketo-express && pnpm i && pnpm i -g grunt
@@ -53,4 +61,19 @@ ports:
   - port: 9011 
     onOpen: ignore
     visibility: public
-    description: Fusion Auth
\ No newline at end of file
+    description: Fusion Auth
+
+  - port: 8090 
+    onOpen: ignore
+    visibility: public
+    description: ODK Central
+
+  - port: 9001 
+    onOpen: ignore
+    visibility: public
+    description: Minio UI
+  
+  - port: 9000 
+    onOpen: ignore
+    visibility: public
+    description: Minio API
\ No newline at end of file
diff --git a/central-config/.env b/central-config/.env
new file mode 100644
index 0000000..6d74a3c
--- /dev/null
+++ b/central-config/.env
@@ -0,0 +1,35 @@
+# Use fully qualified domain names. Set to DOMAIN=local if SSL_TYPE=selfsign.
+DOMAIN=local
+
+# Used for Let's Encrypt expiration emails and Enketo technical support emails
+SYSADMIN_EMAIL=chakshu@samagragovernance.in
+
+# Options: letsencrypt, customssl, upstream, selfsign
+SSL_TYPE=upstream
+
+# Do not change if using SSL_TYPE=letsencrypt
+HTTP_PORT=8090
+HTTPS_PORT=8093
+
+# Optional: configure Node
+# SERVICE_NODE_OPTIONS=
+
+# Optional: connect to a custom database server
+# DB_HOST=
+# DB_USER=
+# DB_PASSWORD=
+# DB_NAME=
+
+# Optional: configure a custom mail server
+# EMAIL_FROM=
+# EMAIL_HOST=
+# EMAIL_PORT=
+# EMAIL_SECURE=
+# EMAIL_IGNORE_TLS=
+# EMAIL_USER=
+# EMAIL_PASSWORD=
+
+# Optional: configure error reporting
+# SENTRY_ORG_SUBDOMAIN=
+# SENTRY_KEY=
+# SENTRY_PROJECT=
\ No newline at end of file
diff --git a/central-config/postgres-upgrade.dockerfile b/central-config/postgres-upgrade.dockerfile
new file mode 100644
index 0000000..a169932
--- /dev/null
+++ b/central-config/postgres-upgrade.dockerfile
@@ -0,0 +1,16 @@
+# see: https://github.com/tianon/docker-postgres-upgrade/blob/master/9.6-to-14/Dockerfile
+FROM tianon/postgres-upgrade:9.6-to-14
+
+# This file is required to encourage human validation of the process.
+# It's expected it will be provided by the sysadmin performing the upgrade.
+# Docker build will fail if this file is missing.
+# COPY ./files/allow-postgres14-upgrade .
+
+COPY files/postgres/upgrade-postgres.sh /usr/local/bin/
+
+# we can't rename/remap this directory, as it's an anonymous volume
+ENV PGDATAOLD=/var/lib/postgresql/data
+
+# N.B. postgres is not started automatically in this image as we are overriding CMD.
+ENTRYPOINT []
+CMD upgrade-postgres.sh
\ No newline at end of file
diff --git a/docker-compose.central.yaml b/docker-compose.central.yaml
deleted file mode 100644
index dada2cf..0000000
--- a/docker-compose.central.yaml
+++ /dev/null
@@ -1,152 +0,0 @@
-version: "3"
-services:
-  postgres14:
-    build:
-      context: .
-      dockerfile: postgres14.dockerfile
-    volumes:
-      - postgres14:/var/lib/odk/postgresql/14
-    environment:
-      POSTGRES_USER: odk
-      POSTGRES_PASSWORD: odk
-      POSTGRES_DATABASE: odk
-    restart: always
-  postgres:
-    # This service upgrades from postgres 9.6 to 14.
-    # The legacy name must be maintained to allow access to the anonymous volume.
-    build:
-      context: .
-      dockerfile: postgres-upgrade.dockerfile
-    volumes:
-      - /var/lib/postgresql/data
-      - postgres14:/var/lib/postgresql/14
-      - ./files/postgres14/upgrade:/postgres14-upgrade
-    environment:
-      PGUSER: odk
-      POSTGRES_INITDB_ARGS: -U odk
-      POSTGRES_PASSWORD: odk
-      POSTGRES_DATABASE: odk
-  mail:
-    image: "ixdotai/smtp:v0.2.0"
-    volumes:
-      - ./files/dkim/config:/etc/exim4/_docker_additional_macros:ro
-      - ./files/dkim/rsa.private:/etc/exim4/domain.key:ro
-    environment:
-      - MAILNAME=${DOMAIN}
-    restart: always
-  service:
-    build:
-      context: .
-      dockerfile: service.dockerfile
-    depends_on:
-      - secrets
-      - postgres14
-      - mail
-      - pyxform
-      - enketo
-    volumes:
-      - secrets:/etc/secrets
-      - /data/transfer:/data/transfer
-    environment:
-      - DOMAIN=${DOMAIN}
-      - SYSADMIN_EMAIL=${SYSADMIN_EMAIL}
-      - HTTPS_PORT=${HTTPS_PORT:-443}
-      - NODE_OPTIONS=${SERVICE_NODE_OPTIONS:-''}
-      - DB_HOST=${DB_HOST:-postgres14}
-      - DB_USER=${DB_USER:-odk}
-      - DB_PASSWORD=${DB_PASSWORD:-odk}
-      - DB_NAME=${DB_NAME:-odk}
-      - DB_SSL=${DB_SSL:-null}
-      - EMAIL_FROM=${EMAIL_FROM:-no-reply@${DOMAIN}}
-      - EMAIL_HOST=${EMAIL_HOST:-mail}
-      - EMAIL_PORT=${EMAIL_PORT:-25}
-      - EMAIL_SECURE=${EMAIL_SECURE:-false}
-      - EMAIL_IGNORE_TLS=${EMAIL_IGNORE_TLS:-true}
-      - EMAIL_USER=${EMAIL_USER:-''}
-      - EMAIL_PASSWORD=${EMAIL_PASSWORD:-''}
-      - SENTRY_ORG_SUBDOMAIN=${SENTRY_ORG_SUBDOMAIN:-o130137}
-      - SENTRY_KEY=${SENTRY_KEY:-3cf75f54983e473da6bd07daddf0d2ee}
-      - SENTRY_PROJECT=${SENTRY_PROJECT:-1298632}
-    command:
-      [
-        "./wait-for-it.sh",
-        "${DB_HOST:-postgres14}:5432",
-        "--",
-        "./start-odk.sh"
-      ]
-    restart: always
-    logging:
-      driver: local
-  nginx:
-    build:
-      context: .
-      dockerfile: nginx.dockerfile
-    depends_on:
-      - service
-      - enketo
-    environment:
-      - DOMAIN=${DOMAIN}
-      - CERTBOT_EMAIL=${SYSADMIN_EMAIL}
-      - SSL_TYPE=${SSL_TYPE:-letsencrypt}
-      - SENTRY_ORG_SUBDOMAIN=${SENTRY_ORG_SUBDOMAIN:-o130137}
-      - SENTRY_KEY=${SENTRY_KEY:-3cf75f54983e473da6bd07daddf0d2ee}
-      - SENTRY_PROJECT=${SENTRY_PROJECT:-1298632}
-    ports:
-      - "${HTTP_PORT:-80}:80"
-      - "${HTTPS_PORT:-443}:443"
-    healthcheck:
-      test: [ "CMD-SHELL", "nc -z localhost 80 || exit 1" ]
-    restart: always
-    logging:
-      driver: local
-      options:
-        max-file: "30"
-  pyxform:
-    image: 'ghcr.io/getodk/pyxform-http:v1.12.0'
-    restart: always
-  secrets:
-    volumes:
-      - secrets:/etc/secrets
-    build:
-      context: .
-      dockerfile: secrets.dockerfile
-    command: './generate-secrets.sh'
-  enketo:
-    volumes:
-      - secrets:/etc/secrets
-    build:
-      context: .
-      dockerfile: enketo.dockerfile
-    restart: always
-    depends_on:
-      - secrets
-      - enketo_redis_main
-      - enketo_redis_cache
-    environment:
-      - DOMAIN=${DOMAIN}
-      - SUPPORT_EMAIL=${SYSADMIN_EMAIL}
-      - HTTPS_PORT=${HTTPS_PORT:-443}
-  enketo_redis_main:
-    image: redis:7.0.8
-    volumes:
-      - ./files/enketo/redis-enketo-main.conf:/usr/local/etc/redis/redis.conf:ro
-      - enketo_redis_main:/data
-    command:
-      - redis-server
-      - /usr/local/etc/redis/redis.conf
-    restart: always
-  enketo_redis_cache:
-    image: redis:7.0.8
-    volumes:
-      - ./files/enketo/redis-enketo-cache.conf:/usr/local/etc/redis/redis.conf:ro
-      - enketo_redis_cache:/data
-    command:
-      - redis-server
-      - /usr/local/etc/redis/redis.conf
-    restart: always
-volumes:
-  secrets:
-  transfer:
-  postgres14:
-  enketo_redis_main:
-  enketo_redis_cache:
diff --git a/docker-compose.gitpod.yaml b/docker-compose.gitpod.yaml
index e6b9a12..b3e97fb 100644
--- a/docker-compose.gitpod.yaml
+++ b/docker-compose.gitpod.yaml
@@ -127,7 +127,19 @@ services:
       - HASURA_GRAPHQL_MIGRATIONS_DISABLE_TRANSACTION=true
       - HASURA_GRAPHQL_CONSOLE_ASSETS_DIR=/srv/console-assets
       - HASURA_GRAPHQL_ADMIN_SECRET=myadminsecretkey
-      - HASURA_GRAPHQL_JWT_SECRET={"type":"RS256","jwk_url":"http://fusionauth/.well-known/jwks.json"}
+      - HASURA_GRAPHQL_JWT_SECRET={"type":"RS256","jwk_url":"http://fusionauth:9011/.well-known/jwks.json"}
+
+  minio:
+    image: minio/minio
+    ports:
+      - "9000:9000"
+      - "9001:9001"
+    volumes:
+      - ./mnt/cqube_bucket/minio:/data
+    environment:
+      MINIO_ROOT_USER: cqube-dev
+      MINIO_ROOT_PASSWORD: cqubeDevPassTibil
+    command: server --console-address ":9001" /data
 
 networks:
   db_net:
@@ -139,3 +151,4 @@ volumes:
   db_data:
   search_data:
   fa-config:
+  minio_storage: {}
diff --git a/install-central.sh b/install-central.sh
new file mode 100644
index 0000000..5c1c70a
--- /dev/null
+++ b/install-central.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+git clone --recurse-submodules -j8 git@github.com:getodk/central.git
+cd central
+
+# overwrite files from central-config to current folder
+cp -r ../central-config/* .
+
+docker-compose build
+docker-compose up -d
+
+sleep 30
+
+docker compose exec service odk-cmd --email chakshu@samagragovernance.in user-create
+docker compose exec service odk-cmd --email chakshu@samagragovernance.in user-promote
\ No newline at end of file
-- 
GitLab