From c08304beb2c7668d252f4b83d64da72fa0e2148a Mon Sep 17 00:00:00 2001 From: Michael Tamaki Date: Tue, 3 Oct 2023 16:57:31 -1000 Subject: [PATCH 1/2] Update local dev setup steps (#148) * Update local dev setup steps * New files * Update .env.defaults * Update .env.defaults * Update .env.defaults * removing polis surveys to test if build still fails * Update .env.defaults putting pol.is surveys back in * Replicate copy .env build step in Github actions --------- Co-authored-by: avenmia Co-authored-by: Tyler Chong --- .env.example | 8 ++++ .github/workflows/test-build.yml | 8 ++-- .gitignore | 1 - .nvmrc | 1 + compose.yaml | 15 ++++++++ src/README.md | 65 +++++++++++++++++++++++++------- 6 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 .env.example create mode 100644 .nvmrc create mode 100644 compose.yaml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..4790ae9 --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +DATABASE_URL="sqlserver://localhost:1433;database=HIERR;user=sa;password=;encrypt=DANGER_PLAINTEXT;" +NEXTAUTH_URL="http://localhost:3000" +NEXTAUTH_SECRET=DUMMY +EMAIL_SERVER="smtp://localhost:25" +EMAIL_FROM="test@example.com" +NEXT_PUBLIC_POLIS_SURVEYS='[{"id": "yourSurveyID1", "title": "yourSurveyTitle1", "description": "yourSurveyDescription1"}]' +NEXT_PUBLIC_SEARCH_API='{your ArcGIS Search Api Key}' +AUTHORIZED_POLIS_CONVERT_EMAILS_FILE={path to file that contains a list of email addresses (one per line) whose users are authorized to export POLIS data} diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index b9f41c1..03b3468 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -24,10 +24,8 @@ jobs: cache: "npm" - run: npm ci - - name: Make envfile - uses: SpicyPizza/create-envfile@v1.3 - with: - envkey_NEXT_PUBLIC_POLIS_SURVEYS: ${{ secrets.NEXT_PUBLIC_POLIS_SURVEYS }} - - run: SKIP_ENV_VALIDATION=1 npm run build --if-present + - name: Create .env file + run: cp -f .env.example .env + - run: npm run build --if-present env: CI: true diff --git a/.gitignore b/.gitignore index f7bea96..2971a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,6 @@ yarn-error.log* # do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables .env .env*.local -.env.example # vercel .vercel diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..c32828c --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/hydrogen \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..39e5201 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,15 @@ +services: + sql: + image: mcr.microsoft.com/mssql/server:2017-latest + environment: + ACCEPT_EULA: Y + MSSQL_SA_PASSWORD: + ports: + - 1433:1433 + smtp: + image: rnwood/smtp4dev:v3 + ports: + - 3001:80 + - 25:25 + environment: + - ServerOptions__HostName=smtp4dev diff --git a/src/README.md b/src/README.md index 0f7680b..b693e28 100644 --- a/src/README.md +++ b/src/README.md @@ -1,28 +1,61 @@ # Local project installation and setup -``` +Run these commands to set up and run the project locally for the first time. + +```bash git clone https://github.com/CodeforHawaii/HIERR.git cd HIERR +# Use nvm to set the NodeJS version https://github.com/nvm-sh/nvm +nvm use npm install -touch .env +cp -f .env.example .env # Note: You may have to update the .env file with your specific secret values. +# Use docker to set up SQL and SMTP servers locally https://www.docker.com/ +# See "SMTP Cloud Server Setup" and "Prisma SQL Server Migration" sections if +# wanting to use a different set up. +docker compose up -d +``` + +Next, create database table `HIERR`. Enter the bash shell in the docker image: + +```bash +docker exec -it hierr-sql-1 "bash" +``` + +Enter the SQL Server CLI tool + +```bash +/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "" +``` + +Create a new database and check that it was created + +```bash +CREATE DATABASE HIERR; +SELECT Name from sys.databases; +GO ``` -- Add the following to the .env: - 1. DATABASE_URL="file:./db.sqlite" - 2. NEXTAUTH_URL="http://localhost:3000" - 3. EMAIL_SERVER={your email server} - 4. EMAIL_FROM={the email to send the verification link} - 5. NEXT_PUBLIC_POLIS_SURVEYS='[{"id": "{yourSurveyID1}", "title": "{yourSurveyTitle1}", "description", "{yourSurveyDescription1}"}, ...]' - 6. NEXT_PUBLIC_SEARCH_API='{your ArcGIS Search Api Key}' - 7. AUTHORIZED_POLIS_CONVERT_EMAILS_FILE={path to file that contains a list of email addresses (one per line) whose users are authorized to export POLIS data} +Then, you may exit: +```bash +exit ``` + +Finally, run the DB migration scripts and run the dev server: + +```bash +npx prisma migrate dev npx prisma db push +# Run dev server on http://localhost:3000 npm run dev ``` +The SMTP email web interface is available at http://localhost:3001. + # Update Prisma +Run these commands for specific Prisma tasks. + 1. Update schema.prisma with your model Validate your prisma model @@ -49,7 +82,9 @@ Update the database npx prisma db push ``` -# SMTP Server Setup +# SMTP Cloud Server Setup + +Follow these directions for setting up an SMTP server in the cloud, as opposed to setting one up on your local machine. - Gmail - Follow the steps at this YouTube video for setting up an SMTP gmail account @@ -67,13 +102,15 @@ npx prisma db push # Prisma SQL Server Migration +Follow these directions for easier database editing. + - Windows - Install SQL Server - Docker - [Docker Microsoft SQL Server Images Download](https://hub.docker.com/_/microsoft-mssql-server) - docker pull mcr.microsoft.com/mssql/server:2017-latest - Start SQL Server (2017) - - docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest + - docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest - Microsoft - [Miscrosoft SQL Server Download](https://www.microsoft.com/en-us/sql-server/sql-server-downloads) - Enable SQL Server TCP/IP @@ -86,10 +123,10 @@ npx prisma db push - SQL Server 2019 (local install): - sqlserver://localhost:1433;initial catalog=HIERR;integratedSecurity=true;trustServerCertificate=true; - SQL Server 2017 (docker): - - sqlserver://localhost:1433;database=HIERR;user=sa;password=yourStrong(!)Password;encrypt=DANGER_PLAINTEXT; + - sqlserver://localhost:1433;database=HIERR;user=sa;password=;encrypt=DANGER_PLAINTEXT; - Note: Connection string uses the default user and password from docker. Also the DANGER_PLAINTEXT is used because of an issue with TLS. - Other OS systems: - - sqlserver://HOST:PORT;database=HIERR;user=USER;password=PASSWORD;encrypt=true + - sqlserver://HOST:PORT;database=HIERR;user=sa;password=;encrypt=true - Note: Be sure to change USER and PASSWORD to your system's requirements - Docs: https://www.prisma.io/docs/concepts/database-connectors/sql-server - Run the following prisma commands From 99fa40ec5b0e947e74f32d0a490da01b2de62011 Mon Sep 17 00:00:00 2001 From: Hubert Liang <73650949+Hooobot@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:56:15 -1000 Subject: [PATCH 2/2] Update .env.example to include sqlite configurations (#159) --- .env.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.env.example b/.env.example index 4790ae9..5489133 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,7 @@ +# For SQLServer DATABASE_URL="sqlserver://localhost:1433;database=HIERR;user=sa;password=;encrypt=DANGER_PLAINTEXT;" +# For SQLite +# DATABASE_URL="file:./db.sqlite" NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET=DUMMY EMAIL_SERVER="smtp://localhost:25"