diff --git a/README.md b/README.md index 7433069..45237d0 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,59 @@ VS Code is the editor of choice for this project (v1.71.2 or newer). Running the App (using source code) ----------------------------------- -1. At root level: `npm ci` -2. Setting up the Database: `npm run setup-database` -3. Starting the app: `npm start` +1. Set up dependencies: + - at root level: `npm ci` +2. Build the app: + - at root level: `npm run build-all` +3. Set up PostgreSQL (you can use these steps or do it the way `setup.sql` + specifies - one inconsistency is "superuser" so it appears that it isn't + actually needed and either "y" or "n" will do): + - `sudo -u postgres psql` + - `createuser --interactive` + - superuser: "n" + - allow to create databases: "y" + - allow to create new roles: "y" + - `\du` to see the user created + - `ALTER USER atoll PASSWORD '{pwd}'` (pick a password- you'll use this + later as well - `setup.sql` specifies `lim3atoll` but it is recommended + that you change this for security reasons!) + - `exit` (`\q` should work too) + - `sudo service postgresql restart` + - `sudo -u postgres createdb atoll` + - if you see `could not change directory to ...` you can ignore that error + - `sudo -u postgres psql` + - `ALTER DATABASE atoll OWNER TO atoll;` + - `\p` to see that the command was executed (it will repeat the line above) + - `\q` to quit +4. Follow the incomplete steps in `setup.sql` (up to, but not including, the + "RUN THE APP" step) +5. Set up environment variables: + - set ATOLL_DATABASE_URL to the database connection string + (it should look something like this replacing "{pwd}" with + atoll user password: `postgres://atoll:{pwd}@localhost:5432/atoll`) + - set ATOLL_DATABASE_USE_SSL to "true". + - set ATOLL_AUTH_KEY to something unique for security reasons + (come up with an obscure value that doesn't follow a typical pattern- + you'll lever have to look this up so it can anything at all). +6. Run the app to create the database structure: + - `npm start` + - watch the output + - if it was successful you'll see: + "Database & tables created!" + - kill the app. +7. Setting up atoll user in database: + - at root level: `npm run setup-database` + - if it was successful you'll see: + "Executed SQL statement to set up test user account successfully." +8. Set up sample data: + - use pgAdmin or psql to execute the script `data.sql` +9. Run the app to verify that everything is set up correctly: + - at root level: `npm start` + - console output will have something like + `App is running: http://localhost:8500` at the start + so you know what URL to use in the browser. + - the sample script created a user with login `test` and password `atoll`, so + you should be able to use those credentials to login Running the App (using source code + Docker) -------------------------------------------- diff --git a/docs/dataModel/DATA_MODEL_BACKLOG_ITEM_PARTS.md b/docs/dataModel/DATA_MODEL_BACKLOG_ITEM_PARTS.md index e4cb390..c33edbe 100644 --- a/docs/dataModel/DATA_MODEL_BACKLOG_ITEM_PARTS.md +++ b/docs/dataModel/DATA_MODEL_BACKLOG_ITEM_PARTS.md @@ -1,7 +1,7 @@ Backlog Item Parts ================== -See [DATA_MODEL_BACKLOG_ITES.md](./DATA_MODEL_BACKLOG_ITES.md) for story/issue definition. This document defines how backlog items +See [DATA_MODEL_BACKLOG_ITEMS.md](./DATA_MODEL_BACKLOG_ITEMS.md) for story/issue definition. This document defines how backlog items are split. Overview diff --git a/packages/web-app/docker/debug/docker-compose.yml b/packages/web-app/docker/debug/docker-compose.yml index 69f8294..bd615d5 100644 --- a/packages/web-app/docker/debug/docker-compose.yml +++ b/packages/web-app/docker/debug/docker-compose.yml @@ -7,10 +7,11 @@ services: environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres + - PGDATA=/var/lib/postgresql/data/ ports: - 25432:5432 volumes: - - $HOME/Docker/volumes/postgres/atoll-dev:/var/lib/postgresql/data + - $HOME/Docker/volumes/postgres/atoll-dev:/var/lib/postgresql/data:rw api: container_name: atoll-web-app-server-debug build: diff --git a/packages/web-app/docker/prod/docker-compose.yml b/packages/web-app/docker/prod/docker-compose.yml index 37bef6b..4a3d892 100644 --- a/packages/web-app/docker/prod/docker-compose.yml +++ b/packages/web-app/docker/prod/docker-compose.yml @@ -7,10 +7,11 @@ services: environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres + - PGDATA=/var/lib/postgresql/data/ ports: - 15432:5432 volumes: - - $HOME/Docker/volumes/postgres/atoll:/var/lib/postgresql/data + - $HOME/Docker/volumes/postgres/atoll:/var/lib/postgresql/data/:rw api: container_name: atoll-web-app-server build: diff --git a/packages/web-app/package.json b/packages/web-app/package.json index 78b8a83..5ca3ce1 100644 --- a/packages/web-app/package.json +++ b/packages/web-app/package.json @@ -9,7 +9,7 @@ "docker-build:prod": "npm run build && docker build -f ./docker/prod/Dockerfile -t atoll-web-app-server-image .", "docker-build:debug": "npm run build-debug && docker build -f ./docker/debug/Dockerfile -t atoll-web-app-server-debug-image .", "start:docker": "npm run docker-start:prod", - "docker-start:prod": "docker compose -f ./docker/prod/docker-compose.yml up", + "docker-start:prod": "docker compose -f ./docker/prod/docker-compose.yml up -d", "docker-start:debug": "docker compose -f ./docker/debug/docker-compose.yml up", "build-only": "echo Node Version && node --version && npx --no-install cross-env NODE_ENV=production node scripts/build.js", "build-debug-only": "echo Node Version && node --version && npx --no-install cross-env NODE_ENV=development node scripts/build.js", diff --git a/packages/web-app/scripts/setup.ts b/packages/web-app/scripts/setup.ts index ca87579..259e917 100644 --- a/packages/web-app/scripts/setup.ts +++ b/packages/web-app/scripts/setup.ts @@ -6,7 +6,9 @@ const cryptoLib = require("crypto"); const sharedLib = require("@atoll/shared"); const { Sequelize } = sequelizeLib; -const dbConfig = sharedLib.getDbConfig(); + +const verbose = true; +const dbConfig = sharedLib.getDbConfig(verbose); if (!dbConfig) { console.error("Unable to retrieve database configuration - set ATOLL_DATABASE_URL for local development"); @@ -14,12 +16,21 @@ if (!dbConfig) { console.log("Database configuration retrieved successfully."); } +let dialectOptions: any = {}; + +if (dbConfig.useSsl) { + dialectOptions.ssl = { + require: dbConfig.useSsl, + rejectUnauthorized: false + } +} else { + dialectOptions.ssl = false; +} + const buildOptions = () /*: Options*/ => ({ host: dbConfig.host, dialect: "postgres", - dialectOptions: { - ssl: dbConfig.useSsl - }, + dialectOptions, pool: { max: 10, min: 0, @@ -88,7 +99,7 @@ const sql = ` `; console.log( - `Executing query to create new user. You should see a successful message below- if you don't then something has gone wrong.` + `Executing query to create new test user. You should see a successful message below- if you don't then something has gone wrong.` ); const result = sequelize