Skip to content

Commit

Permalink
replacing hardcoded local db info with env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
adl-trey committed Oct 15, 2024
1 parent a16c7e3 commit 453e48f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 24 deletions.
5 changes: 5 additions & 0 deletions cts/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
HOSTNAME=localhost

DB_HOST=rdbms
DB_NAME=catapult_player
DB_USERNAME=catapult
DB_PASSWORD=quartz

PLAYER_ROOT_PATH=/player
PLAYER_BASE_URL=http://player:3398/player
PLAYER_CONTENT_URL=http://localhost/player/content
Expand Down
10 changes: 7 additions & 3 deletions cts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ services:
- ./seeds:/usr/src/app/seeds:ro
environment:
- HOSTNAME
- DATABASE_USER=catapult
- DATABASE_USER_PASSWORD=quartz
- DATABASE_NAME=catapult_cts
- DB_HOST
- DB_NAME
- DB_USERNAME
- DB_PASSWOD
# - DATABASE_USER=catapult
# - DATABASE_USER_PASSWORD=quartz
# - DATABASE_NAME=catapult_cts
- PLAYER_BASE_URL
- PLAYER_KEY
- PLAYER_SECRET
Expand Down
3 changes: 2 additions & 1 deletion cts/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const provision = async () => {
}
};

await waitPort({host: "rdbms", port: 3306});
const DB_HOST = (process.env.DB_HOST || "rdbms");
await waitPort({host: DB_HOST, port: 3306});

const db = await require("./lib/db")();

Expand Down
25 changes: 17 additions & 8 deletions cts/service/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,33 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
const DB_HOST = (process.env.DB_HOST || "rdbms");
const DB_NAME = (process.env.DB_NAME || "catapult_player");
const DB_USERNAME = (process.env.DB_USERNAME || "catapult");
const DB_PASSWORD = (process.env.DB_PASSWORD || "quartz");

const Hoek = require("@hapi/hoek"),
waitPort = require("wait-port"),
{
MYSQL_HOST: HOST = "rdbms",
// MYSQL_HOST: HOST = "rdbms",
MYSQL_HOST_FILE: HOST_FILE,
DATABASE_USER: USER = "catapult",
// DATABASE_USER: USER = "catapult",
DATABASE_USER_FILE: USER_FILE,
DATABASE_USER_PASSWORD: PASSWORD = "quartz",
// DATABASE_USER_PASSWORD: DB_PASSWORD,
DATABASE_USER_PASSWORD_FILE: PASSWORD_FILE,
DATABASE_NAME: DB = "catapult_player",
// DATABASE_NAME: DB = "catapult_player",
DATABASE_NAME_FILE: DB_FILE,
} = process.env;

module.exports = async () => {
const host = HOST_FILE ? fs.readFileSync(HOST_FILE) : HOST,
user = USER_FILE ? fs.readFileSync(USER_FILE) : USER,
password = PASSWORD_FILE ? fs.readFileSync(PASSWORD_FILE) : PASSWORD,
database = DB_FILE ? fs.readFileSync(DB_FILE) : DB;
// const host = HOST_FILE ? fs.readFileSync(HOST_FILE) : HOST,
// user = USER_FILE ? fs.readFileSync(USER_FILE) : USER,
// password = PASSWORD_FILE ? fs.readFileSync(PASSWORD_FILE) : PASSWORD,
// database = DB_FILE ? fs.readFileSync(DB_FILE) : DB;
const host = HOST_FILE ? fs.readFileSync(HOST_FILE) : DB_HOST,
user = USER_FILE ? fs.readFileSync(USER_FILE) : DB_USERNAME,
password = PASSWORD_FILE ? fs.readFileSync(PASSWORD_FILE) : DB_PASSWORD,
database = DB_FILE ? fs.readFileSync(DB_FILE) : DB_NAME;

await waitPort({host, port: 3306});

Expand Down
5 changes: 5 additions & 0 deletions player/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
HOSTNAME=localhost
HOST_PORT=63398

DB_HOST=rdbms
DB_NAME=catapult_player
DB_USERNAME=catapult
DB_PASSWORD=quartz

CONTENT_URL=http://localhost:63398/content

API_KEY="some API access key"
Expand Down
10 changes: 7 additions & 3 deletions player/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ services:
- LRS_USERNAME
- LRS_PASSWORD
- LRS_XAPI_VERSIONs
- DATABASE_USER=catapult
- DATABASE_USER_PASSWORD=quartz
- DATABASE_NAME=catapult_player
- DB_HOST
- DB_NAME
- DB_USERNAME
- DB_PASSWOD
# - DATABASE_USER=catapult
# - DATABASE_USER_PASSWORD=quartz
# - DATABASE_NAME=catapult_player
- FIRST_TENANT_NAME
- PLAYER_API_ROOT=${PLAYER_ROOT_PATH}
- PLAYER_STANDALONE_LAUNCH_URL_BASE
Expand Down
3 changes: 2 additions & 1 deletion player/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const provision = async () => {
}
};

await waitPort({host: "rdbms", port: 3306});
const DB_HOST = (process.env.DB_HOST || "rdbms");
await waitPort({host: DB_HOST, port: 3306});

const db = await require("./lib/db")();

Expand Down
27 changes: 19 additions & 8 deletions player/service/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,35 @@
See the License for the specific language governing permissions and
limitations under the License.
*/

const DB_HOST = (process.env.DB_HOST || "rdbms");
const DB_NAME = (process.env.DB_NAME || "catapult_player");
const DB_USERNAME = (process.env.DB_USERNAME || "catapult");
const DB_PASSWORD = (process.env.DB_PASSWORD || "quartz");

const Hoek = require("@hapi/hoek"),
waitPort = require("wait-port"),
{
MYSQL_HOST: HOST = "rdbms",
// MYSQL_HOST: HOST = "rdbms",
MYSQL_HOST_FILE: HOST_FILE,
DATABASE_USER: USER = "catapult",
// DATABASE_USER: USER = "catapult",
DATABASE_USER_FILE: USER_FILE,
DATABASE_USER_PASSWORD: PASSWORD = "quartz",
// DATABASE_USER_PASSWORD: DB_PASSWORD,
DATABASE_USER_PASSWORD_FILE: PASSWORD_FILE,
DATABASE_NAME: DB = "catapult_player",
// DATABASE_NAME: DB = "catapult_player",
DATABASE_NAME_FILE: DB_FILE,
} = process.env;

module.exports = async () => {
const host = HOST_FILE ? fs.readFileSync(HOST_FILE) : HOST,
user = USER_FILE ? fs.readFileSync(USER_FILE) : USER,
password = PASSWORD_FILE ? fs.readFileSync(PASSWORD_FILE) : PASSWORD,
database = DB_FILE ? fs.readFileSync(DB_FILE) : DB;
// const host = HOST_FILE ? fs.readFileSync(HOST_FILE) : HOST,
// user = USER_FILE ? fs.readFileSync(USER_FILE) : USER,
// password = PASSWORD_FILE ? fs.readFileSync(PASSWORD_FILE) : PASSWORD,
// database = DB_FILE ? fs.readFileSync(DB_FILE) : DB;
const host = HOST_FILE ? fs.readFileSync(HOST_FILE) : DB_HOST,
user = USER_FILE ? fs.readFileSync(USER_FILE) : DB_USERNAME,
password = PASSWORD_FILE ? fs.readFileSync(PASSWORD_FILE) : DB_PASSWORD,
database = DB_FILE ? fs.readFileSync(DB_FILE) : DB_NAME;


await waitPort({host, port: 3306});

Expand Down

0 comments on commit 453e48f

Please sign in to comment.