From 01a95d133caebf64b010691dd3d3aabccc02e6cf Mon Sep 17 00:00:00 2001 From: Fergus Mok Date: Wed, 20 Mar 2024 13:18:40 +0800 Subject: [PATCH 1/3] Add production config --- .../java/teammates/common/util/Config.java | 38 ++++++++++--------- .../ui/servlets/HibernateContextListener.java | 3 +- .../resources/build-dev.template.properties | 7 ++++ src/main/resources/build.template.properties | 9 +++++ 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/main/java/teammates/common/util/Config.java b/src/main/java/teammates/common/util/Config.java index 0e87e7da67d..0d2c758fdfd 100644 --- a/src/main/java/teammates/common/util/Config.java +++ b/src/main/java/teammates/common/util/Config.java @@ -25,6 +25,21 @@ public final class Config { /** The value of the "app.frontend.url" in build.properties file. */ public static final String APP_FRONTEND_URL; + /** The value of the "app.postgres.host" in build.properties file. */ + public static final String POSTGRES_HOST; + + /** The value of the "app.postgres.port" in build.properties file. */ + public static final String POSTGRES_PORT; + + /** The value of the "app.postgres.databasename" in build.properties file. */ + public static final String POSTGRES_DATABASENAME; + + /** The value of the "app.postgres.username" in build.properties file. */ + public static final String POSTGRES_USERNAME; + + /** The value of the "app.postgres.password" in build.properties file. */ + public static final String POSTGRES_PASSWORD; + /** The value of the "app.production.gcs.bucketname" in build.properties file. */ public static final String PRODUCTION_GCS_BUCKETNAME; @@ -100,18 +115,6 @@ public final class Config { /** The value of the "app.localdatastore.port" in build-dev.properties file. */ public static final int APP_LOCALDATASTORE_PORT; - /** The value of the "app.localpostgres.port" in build-dev.properties file. */ - public static final int APP_LOCALPOSTGRES_PORT; - - /** The value of the "app.localpostgres.username" in build-dev.properties file. */ - public static final String APP_LOCALPOSTGRES_USERNAME; - - /** The value of the "app.localpostgres.password" in build-dev.properties file. */ - public static final String APP_LOCALPOSTGRES_PASSWORD; - - /** The value of the "app.localpostgres.db" in build-dev.properties file. */ - public static final String APP_LOCALPOSTGRES_DB; - /** The value of the "app.enable.devserver.login" in build-dev.properties file. */ public static final boolean ENABLE_DEVSERVER_LOGIN; @@ -158,6 +161,11 @@ public final class Config { CSRF_KEY = getProperty(properties, devProperties, "app.csrf.key"); BACKDOOR_KEY = getProperty(properties, devProperties, "app.backdoor.key"); PRODUCTION_GCS_BUCKETNAME = getProperty(properties, devProperties, "app.production.gcs.bucketname"); + POSTGRES_HOST = getProperty(properties, devProperties, "app.postgres.host"); + POSTGRES_PORT = getProperty(properties, devProperties, "app.postgres.port"); + POSTGRES_DATABASENAME = getProperty(properties, devProperties, "app.postgres.databasename"); + POSTGRES_USERNAME = getProperty(properties, devProperties, "app.postgres.username"); + POSTGRES_PASSWORD = getProperty(properties, devProperties, "app.postgres.password"); BACKUP_GCS_BUCKETNAME = getProperty(properties, devProperties, "app.backup.gcs.bucketname"); ENCRYPTION_KEY = getProperty(properties, devProperties, "app.encryption.key"); AUTH_TYPE = getProperty(properties, devProperties, "app.auth.type"); @@ -186,10 +194,6 @@ public final class Config { // The following properties are not used in production server. // So they will only be read from build-dev.properties file. APP_LOCALDATASTORE_PORT = Integer.parseInt(devProperties.getProperty("app.localdatastore.port", "8484")); - APP_LOCALPOSTGRES_PORT = Integer.parseInt(devProperties.getProperty("app.localpostgres.port", "5432")); - APP_LOCALPOSTGRES_USERNAME = devProperties.getProperty("app.localpostgres.username", "teammates"); - APP_LOCALPOSTGRES_PASSWORD = devProperties.getProperty("app.localpostgres.password", "teammates"); - APP_LOCALPOSTGRES_DB = devProperties.getProperty("app.localpostgres.db", "teammates"); ENABLE_DEVSERVER_LOGIN = Boolean.parseBoolean(devProperties.getProperty("app.enable.devserver.login", "false")); TASKQUEUE_ACTIVE = Boolean.parseBoolean(devProperties.getProperty("app.taskqueue.active", "true")); } @@ -302,7 +306,7 @@ public static boolean isUsingFirebase() { * Returns db connection URL. */ public static String getDbConnectionUrl() { - return "jdbc:postgresql://localhost:" + APP_LOCALPOSTGRES_PORT + "/" + APP_LOCALPOSTGRES_DB; + return String.format("jdbc:postgresql://%s:%s/%s", POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DATABASENAME); } public static boolean isUsingSendgrid() { diff --git a/src/main/java/teammates/ui/servlets/HibernateContextListener.java b/src/main/java/teammates/ui/servlets/HibernateContextListener.java index e377c9645e3..9497dbae1f2 100644 --- a/src/main/java/teammates/ui/servlets/HibernateContextListener.java +++ b/src/main/java/teammates/ui/servlets/HibernateContextListener.java @@ -14,8 +14,7 @@ public class HibernateContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent event) { // Invoked by Jetty at application startup. - HibernateUtil.buildSessionFactory(Config.getDbConnectionUrl(), Config.APP_LOCALPOSTGRES_USERNAME, - Config.APP_LOCALPOSTGRES_PASSWORD); + HibernateUtil.buildSessionFactory(Config.getDbConnectionUrl(), Config.POSTGRES_USERNAME, Config.POSTGRES_PASSWORD); } @Override diff --git a/src/main/resources/build-dev.template.properties b/src/main/resources/build-dev.template.properties index f95923f804d..c787699433e 100644 --- a/src/main/resources/build-dev.template.properties +++ b/src/main/resources/build-dev.template.properties @@ -14,6 +14,13 @@ app.frontend.url = http\://localhost:4200 # This is the port to connect with local Datastore emulator. app.localdatastore.port = 8484 +# Configurations for postgres +app.postgres.host=localhost +app.postgres.port=5432 +app.postgres.databasename=teammates +app.postgres.username=teammates +app.postgres.password=teammates + # This indicates whether task queues are active (e.g. items added to task queue will be queued for execution). # This flag is only used during development mode; in production, task queue will always be active. # In addition, during development mode, there is no "queueing", i.e. all tasks will be immediately executed. diff --git a/src/main/resources/build.template.properties b/src/main/resources/build.template.properties index 269aaefbe88..2e22898bdad 100644 --- a/src/main/resources/build.template.properties +++ b/src/main/resources/build.template.properties @@ -26,6 +26,15 @@ app.version = 8-0-0 # when running locally, the default domain name is http://localhost:8080 # app.frontend.url= +# This is the Google Cloud SQL Configurations for production purposes. +# Using the Severless VPC Access, host should be Private IP of the SQL instance. +# For dev server, leaving it blank will do. +app.postgres.host=10.15.176.3 +app.postgres.port=5432 +app.postgres.databasename=postgres +app.postgres.username=postgres +app.postgres.password=teammatesrocks + # This is the Google Cloud Storage bucket name used by the app for production purposes, e.g. user profile pictures. # For dev server, any name will do. # For staging server, if you use the default bucket for your project, it should be .appspot.com From a451ec7116eaa714a526ffbfa550de2f4221dab7 Mon Sep 17 00:00:00 2001 From: Fergus Mok Date: Wed, 20 Mar 2024 13:41:18 +0800 Subject: [PATCH 2/3] Remove forgotten host and password --- src/main/resources/build.template.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/build.template.properties b/src/main/resources/build.template.properties index 2e22898bdad..c6dd675502f 100644 --- a/src/main/resources/build.template.properties +++ b/src/main/resources/build.template.properties @@ -29,11 +29,11 @@ app.version = 8-0-0 # This is the Google Cloud SQL Configurations for production purposes. # Using the Severless VPC Access, host should be Private IP of the SQL instance. # For dev server, leaving it blank will do. -app.postgres.host=10.15.176.3 +app.postgres.host= app.postgres.port=5432 app.postgres.databasename=postgres app.postgres.username=postgres -app.postgres.password=teammatesrocks +app.postgres.password= # This is the Google Cloud Storage bucket name used by the app for production purposes, e.g. user profile pictures. # For dev server, any name will do. From bf59b3ed33cd05cfbc4fc544bd7214e8adb10c3e Mon Sep 17 00:00:00 2001 From: Fergus Mok Date: Wed, 20 Mar 2024 13:45:57 +0800 Subject: [PATCH 3/3] Fix lint --- src/main/java/teammates/common/util/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/teammates/common/util/Config.java b/src/main/java/teammates/common/util/Config.java index 0d2c758fdfd..4ec6f7971b8 100644 --- a/src/main/java/teammates/common/util/Config.java +++ b/src/main/java/teammates/common/util/Config.java @@ -39,7 +39,7 @@ public final class Config { /** The value of the "app.postgres.password" in build.properties file. */ public static final String POSTGRES_PASSWORD; - + /** The value of the "app.production.gcs.bucketname" in build.properties file. */ public static final String PRODUCTION_GCS_BUCKETNAME;