diff --git a/.gitignore b/.gitignore index 26b0080..7166374 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,5 @@ yarn-error.log* next-env.d.ts # Local Netlify folder .netlify + +bitwarden.env \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..089d646 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,12 @@ +FROM node:16 AS deps +WORKDIR /app + +COPY package.json yarn.lock ./ +RUN yarn config set network-timeout 600000 -g +RUN yarn install --legacy-peer-deps + +FROM node:16 as dev + +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . \ No newline at end of file diff --git a/README.md b/README.md index 1e17e81..3bf8441 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,25 @@ Boggers is still growing and we hope to add many new features to facilitate club ## Getting Started -Run the development server: +### Run With Docker + +1. Install [Docker](https://docs.docker.com/engine/install/) +2. Obtain the Bitwarden password from your EM. Create a `bitwarden.env` file and fill it in with the following contents: + ``` + BW_PASSWORD= + ``` + This only needs to be done on your first run. After that, you should delete the file from your repository to avoid pushing it to Github. +3. Start the application with Docker Compose: `docker compose up` + +If you make any changes to the packages, you may need to rebuild the images. To do this, append --build to the above docker compose up command. + +The Dockerized application will have live-reloading of changes made on the host machine. + +Note: On linux-based operating systems, if you come across an entrypoint permission error (i.e. `process: exec: "./entrypoint.sh": permission denied: unknown`), run `chmod +x ./entrypoint.sh` to make the shell file an executable. + +Windows Users: If you come across this error `exec ./entrypoint.sh: no such file or directory` when running the docker compose command, please follow this [Stackoverflow thread](https://stackoverflow.com/questions/40452508/docker-error-on-an-entrypoint-script-no-such-file-or-directory) to fix it. + +### Run the development server: ```bash yarn dev diff --git a/bitwarden.env.example b/bitwarden.env.example new file mode 100644 index 0000000..9d78ade --- /dev/null +++ b/bitwarden.env.example @@ -0,0 +1 @@ +BW_PASSWORD= \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..179b4fb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + app: + env_file: + - bitwarden.env + build: + dockerfile: ./Dockerfile.dev + volumes: + - ./:/app + - /app/node_modules + - /app/.next + ports: + - "3000:3000" + entrypoint: ./entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..220da90 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ ! -f "./.env" ]; then + echo "Secrets not found. Pulling files from Bitwarden..." + if [[ -z "${BW_PASSWORD}" ]]; then + echo "Error: BW_PASSWORD envvar is not defined. Please inject BW_PASSWORD into container!" + exit 1; + fi + + npm install -g @bitwarden/cli fx + # get secrets + bw logout + export BW_SESSION=$(bw login product@bitsofgood.org ${BW_PASSWORD} --raw); + bw sync --session $BW_SESSION + bw get item c2786b92-f3e9-404e-9288-b089015adf37 | fx .notes > ".env.local" + + echo "Secrets successfully retrieved." +fi + +yarn run dev