From c37649f7376df6941f03e97e29e30c79fca4aee3 Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Fri, 15 Sep 2023 14:54:20 -0400 Subject: [PATCH 1/7] Dockerize app, update README --- Dockerfile | 13 +++++ README.md | 116 ++++++++++++++++++++++++++++++++++++++++----- docker-compose.yml | 19 ++++++++ 3 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..afbdfe49 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:16 +WORKDIR /usr/src/app +COPY package.json yarn.lock ./ +RUN yarn install +EXPOSE 3000 +ENV YARN_COMMAND=dev + +# If you want to use a different command, pass the YARN_COMMAND env variable to +# docker-compose up --build + +# Ex. YARN_COMMAND=build docker-compose up --build + +ENTRYPOINT ["sh", "-c", "yarn $YARN_COMMAND"] diff --git a/README.md b/README.md index ea359ac4..e41c87d9 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,74 @@ git clone https://github.com/GTBitsOfGood/southface.git cd southface ``` +## Running with Docker (recommended): + +3. Install docker and docker-compose + +MacOS: [Docker Desktop for MacOS](https://docs.docker.com/desktop/install/mac-install/) +Windows: [Docker Desktop for Windows](https://docs.docker.com/desktop/install/windows-install/) +Linux: [Docker Desktop for Linux](https://docs.docker.com/desktop/install/linux-install/) + +4. Obtain your secrets -- Linux or MacOS (Skip if Windows); you will need to obtain a password from your Engineering Manager: + +First, install BitWarden CLI and FX with npm + +``` +npm install -g @bitwarden/cli fx +``` + +Or, if you're using Homebrew, + +``` +brew install bitwarden-cli fx +``` + +Now fetch the secrets from BitWarden + +``` +yarn secrets:linux +``` + +4. Obtain your secrets -- Windows Machines (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: + +First, install BitWarden CLI and FX with npm + +``` +npm install -g @bitwarden/cli fx +``` + +Now fetch the secrets from BitWarden + +``` +yarn secrets:windows +``` + +Contact your EM for the Bitwarden password. **NEVER EVER** commit `.env.local` to your version control system. + +5. Run the dev enviromnent, build, etc. + +To run the dev environment, run the default command. + +``` +docker-compose up --build +``` + +To run build or any other script specified in the package.json, provide the YARN_COMMAND environment variable before the command. + +``` +YARN_COMMAND=build docker-compose up --build +``` + +### Development + +- Run `docker-compose up --build` + +### Production + +- Run `YARN_COMMAND=start docker-compose up --build` + +## Running outside of Docker (not recommended): + 3. Install Node Version Manager (NVM) - follow [this guide](https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/) if you don't have NVM already to install it onto your machine. @@ -42,38 +110,47 @@ cd southface nvm install 16 && nvm use 16 ``` -4. Install the dependencies (make sure to use yarn and not npm): +5. Install the dependencies (make sure to use yarn and not npm): ``` yarn ``` -5. Obtain your secrets -- Linux or MacOS (Skip if Windows); you will need to obtain a password from your Engineering Manager: +4. Obtain your secrets -- Linux or MacOS (Skip if Windows); you will need to obtain a password from your Engineering Manager: + +First, install BitWarden CLI with npm ``` -yarn secrets:linux +npm install -g @bitwarden/cli ``` -5. Obtain your secrets -- Windows Machines (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: +Or, if you're using Homebrew, ``` -yarn secrets:windows +brew install bitwarden-cli ``` -Contact your EM for the Bitwarden password. **NEVER EVER** commit `.env.local` to your version control system. +Now fetch the secrets from BitWarden -## MongoDB +``` +yarn secrets:linux +``` -A running instance of MongoDB is required this project. +4. Obtain your secrets -- Windows Machines (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: -- Download [mongoDB compass](https://www.mongodb.com/try/download/compass) -- Launch MongoDB Compass. When prompted for the connection URL, copy and paste `DB_URL` from your `.env.local` file. +First, install BitWarden CLI with npm -You should now have write access to the different collections available. +``` +npm install -g @bitwarden/cli +``` -## Running +Now fetch the secrets from BitWarden -To understand this code better, read the [Code Tour](/CODETOUR.md). +``` +yarn secrets:windows +``` + +Contact your EM for the Bitwarden password. **NEVER EVER** commit `.env.local` to your version control system. ### Development @@ -83,6 +160,19 @@ To understand this code better, read the [Code Tour](/CODETOUR.md). - Run `yarn start` +## MongoDB + +If you're using Docker, Docker will run MongoDB inside its container. If you aren't, you'll have to run it yourself. Installing MongoDB Compass will allow you to do that. Regardless, download it so you can view the remote database from your machine. + +- Download [MongoDB compass](https://www.mongodb.com/try/download/compass) +- Launch MongoDB Compass. When prompted for the connection URL, copy and paste `DB_URL` from your `.env.local` file. + +You should now have write access to the different collections available. + +## Running + +To understand this code better, read the [Code Tour](/CODETOUR.md). + ## Additional Information - Use `[INITIALS]/[ISSUE_NUMBER]-[SHORT_DESCRIPTION]` when naming your feature branches diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..bde6fa0d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3" + +services: + earthcraft: + build: + context: . + environment: + - YARN_COMMAND=${YARN_COMMAND:-dev} + ports: + - "3000:3000" + env_file: + - .env.local + volumes: + - .:/usr/src/app + - /usr/src/app/node_modules + mongo: + image: mongo:latest + ports: + - "27017:27017" From 94542e3a39588210baa08f4e66f4291465db8436 Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Fri, 15 Sep 2023 15:02:06 -0400 Subject: [PATCH 2/7] Update husky for commit validation --- .husky/commit-msg | 2 +- .husky/pre-commit | 4 ++-- docker-compose.yml | 1 + package.json | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index b5676766..244a31f9 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx --no -- commitlint --edit "$1" +COMMIT_MSG=$1 YARN_COMMAND=commitlint docker-compose up --build earthcraft \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 29691cea..60ca6b43 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,5 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn lint:fix -yarn prettier \ No newline at end of file +YARN_COMMAND=lint:fix docker-compose up --build earthcraft +YARN_COMMAND=prettier docker-compose up --build earthcraft \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index bde6fa0d..dc56a75e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: context: . environment: - YARN_COMMAND=${YARN_COMMAND:-dev} + - COMMIT_MSG=${COMMIT_MSG:-""} ports: - "3000:3000" env_file: diff --git a/package.json b/package.json index 6c286ae5..9f01ed2f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "secrets:windows": "set /p BW_PASSWORD=Enter Bitwarden Password:&& (bw logout || VER>NUL) && yarn secrets:login", "secrets:login": "FOR /F %a IN ('bw login product@bitsofgood.org %BW_PASSWORD% --raw') DO SET BW_SESSION=%a && yarn secrets:get", "secrets:get": "bw sync && bw get item 8ccfc499-cfc2-4e66-9e82-af0801429e85 | fx .notes > \".env.local\"", - "prepare": "npx husky install" + "prepare": "npx husky install", + "commitlint": "cross-env npx commitlint --edit $COMMIT_MSG" }, "husky": { "hooks": { From 44b7985c9bb20a2297fbe99573d4a64c0ee61747 Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Fri, 15 Sep 2023 15:03:15 -0400 Subject: [PATCH 3/7] Update husky for commit validation --- .husky/pre-push | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-push b/.husky/pre-push index 0beb023e..0769a590 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn build +YARN_COMMAND=build docker-compose up --build earthcraft From 4540c04aacf455938b8029b161c806423f95864e Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Fri, 15 Sep 2023 15:11:03 -0400 Subject: [PATCH 4/7] Update README --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e41c87d9..73869217 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,14 @@ cd southface 3. Install docker and docker-compose MacOS: [Docker Desktop for MacOS](https://docs.docker.com/desktop/install/mac-install/) + Windows: [Docker Desktop for Windows](https://docs.docker.com/desktop/install/windows-install/) + Linux: [Docker Desktop for Linux](https://docs.docker.com/desktop/install/linux-install/) 4. Obtain your secrets -- Linux or MacOS (Skip if Windows); you will need to obtain a password from your Engineering Manager: -First, install BitWarden CLI and FX with npm +First, install BitWarden CLI and fx with npm ``` npm install -g @bitwarden/cli fx @@ -62,7 +64,7 @@ yarn secrets:linux 4. Obtain your secrets -- Windows Machines (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: -First, install BitWarden CLI and FX with npm +First, install BitWarden CLI and fx with npm ``` npm install -g @bitwarden/cli fx @@ -76,15 +78,15 @@ yarn secrets:windows Contact your EM for the Bitwarden password. **NEVER EVER** commit `.env.local` to your version control system. -5. Run the dev enviromnent, build, etc. +5. Run the app -To run the dev environment, run the default command. +To run the dev environment, run the default docker-compose command ``` docker-compose up --build ``` -To run build or any other script specified in the package.json, provide the YARN_COMMAND environment variable before the command. +To run build or any other script specified in the package.json, provide the YARN_COMMAND environment variable before docker-compose ``` YARN_COMMAND=build docker-compose up --build From 6e5f665845a8b742489914fce6d47f78fbd8af8c Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Fri, 15 Sep 2023 15:12:39 -0400 Subject: [PATCH 5/7] Update README --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 73869217..7588efff 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ cd southface ## Running with Docker (recommended): -3. Install docker and docker-compose +3. Install **docker** and **docker-compose** MacOS: [Docker Desktop for MacOS](https://docs.docker.com/desktop/install/mac-install/) @@ -42,9 +42,9 @@ Windows: [Docker Desktop for Windows](https://docs.docker.com/desktop/install/wi Linux: [Docker Desktop for Linux](https://docs.docker.com/desktop/install/linux-install/) -4. Obtain your secrets -- Linux or MacOS (Skip if Windows); you will need to obtain a password from your Engineering Manager: +4. Obtain your secrets -- **Linux or MacOS** (Skip if Windows); you will need to obtain a password from your Engineering Manager: -First, install BitWarden CLI and fx with npm +First, install **BitWarden CLI** and **fx** with npm ``` npm install -g @bitwarden/cli fx @@ -62,9 +62,9 @@ Now fetch the secrets from BitWarden yarn secrets:linux ``` -4. Obtain your secrets -- Windows Machines (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: +4. Obtain your secrets -- **Windows Machines** (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: -First, install BitWarden CLI and fx with npm +First, install **BitWarden CLI** and **fx** with npm ``` npm install -g @bitwarden/cli fx @@ -118,9 +118,9 @@ nvm install 16 && nvm use 16 yarn ``` -4. Obtain your secrets -- Linux or MacOS (Skip if Windows); you will need to obtain a password from your Engineering Manager: +4. Obtain your secrets -- **Linux** or **MacOS** (Skip if Windows); you will need to obtain a password from your Engineering Manager: -First, install BitWarden CLI with npm +First, install **BitWarden CLI** with npm ``` npm install -g @bitwarden/cli @@ -138,7 +138,7 @@ Now fetch the secrets from BitWarden yarn secrets:linux ``` -4. Obtain your secrets -- Windows Machines (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: +4. Obtain your secrets -- **Windows Machines** (Skip if MacOS or Linux); you will need to obtain a password from your Engineering Manager: First, install BitWarden CLI with npm From 444471137d29253d624905f793d2a627341359b9 Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Sun, 17 Sep 2023 20:12:17 -0400 Subject: [PATCH 6/7] fix: husky commit status codes to block invalid commit messages --- .husky/commit-msg | 2 +- .husky/pre-commit | 4 ++-- .husky/pre-push | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index 244a31f9..657e5853 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -COMMIT_MSG=$1 YARN_COMMAND=commitlint docker-compose up --build earthcraft \ No newline at end of file +COMMIT_MSG=$1 YARN_COMMAND=commitlint docker-compose up --build --exit-code-from earthcraft earthcraft \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 60ca6b43..7a531169 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,5 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -YARN_COMMAND=lint:fix docker-compose up --build earthcraft -YARN_COMMAND=prettier docker-compose up --build earthcraft \ No newline at end of file +YARN_COMMAND=lint:fix docker-compose up --build --exit-code-from earthcraft earthcraft +YARN_COMMAND=prettier docker-compose up --build --exit-code-from earthcraft earthcraft \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push index 0769a590..321448e9 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -YARN_COMMAND=build docker-compose up --build earthcraft +YARN_COMMAND=build docker-compose up --build --exit-code-from earthcraft earthcraft From 62162ad06bc6180214a7af1ddfe6e383ca04b0fa Mon Sep 17 00:00:00 2001 From: Hayden Carpenter Date: Sun, 17 Sep 2023 20:28:55 -0400 Subject: [PATCH 7/7] feat: add netlify link to readme --- LICENSE | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8750c0bd..43044c6a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 GT Bits of Good +Copyright (c) 2023 GT Bits of Good Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 7588efff..2f0267ca 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Make sure you have gone through this walkthrough and all the links down below: - [Code Tour](/CODETOUR.md) - [Engineering Onboarding Guide](https://gtbitsofgood.notion.site/Engineering-Onboarding-Guide-a22683c9388a4b9fb03de442f6664aae) - [Figma/Design](https://www.figma.com/file/YTJqtLkjyxYdS3UkfR9dza/Southface-%2F-Fall22?node-id=0%3A1&t=HjMuBBxgKAeaLCzm-1) +- [Netlify Production Build](https://southface.netlify.app) ## Stack