diff --git a/.husky/commit-msg b/.husky/commit-msg index b5676766..657e5853 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 --exit-code-from earthcraft earthcraft \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 29691cea..7a531169 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 --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 0beb023e..321448e9 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 --exit-code-from earthcraft earthcraft 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/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 ea359ac4..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 @@ -32,6 +33,76 @@ 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 app + +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 docker-compose + +``` +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 +113,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 +163,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..dc56a75e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: "3" + +services: + earthcraft: + build: + context: . + environment: + - YARN_COMMAND=${YARN_COMMAND:-dev} + - COMMIT_MSG=${COMMIT_MSG:-""} + ports: + - "3000:3000" + env_file: + - .env.local + volumes: + - .:/usr/src/app + - /usr/src/app/node_modules + mongo: + image: mongo:latest + ports: + - "27017:27017" 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": {