Skip to content

Commit

Permalink
Merge pull request #52 from TylerOrtiz/feature/docker-compose-workflow
Browse files Browse the repository at this point in the history
Feature/docker compose workflow
  • Loading branch information
nfloersch authored Mar 20, 2024
2 parents 12537c4 + 0c5fb9d commit e473bce
Show file tree
Hide file tree
Showing 16 changed files with 24,660 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# None of these are necessary to change unless you want it to be different
# GOOGLE_APPLICATION_CREDENTIALS=<your-google-credentials-file-path>
# FIREBASE_CONFIG=<your-firebase-config-file-path>
7 changes: 7 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"projects": {
"c4btv": "baby-equipment-exchange"
},
"targets": {},
"etags": {}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ serviceAccount.json
#VSCODE Preferences
.vscode

.env
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# a Node.js base image that includes Node v18
FROM node:18-bullseye as base

RUN apt-get update && \
apt-get install -y jq default-jdk && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN wget https://chromedriver.storage.googleapis.com/94.0.4606.61/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && \
mv chromedriver /usr/bin/chromedriver && \
chmod +x /usr/bin/chromedriver && \
rm -f chromedriver_linux64.zip

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
dpkg -i google-chrome-stable_current_amd64.deb || true && \
apt-get install -f -y && \
rm -f google-chrome-stable_current_amd64.deb

ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome
ENV FIREBASE_TOOLS_VERSION=13.5.1

RUN npm install -g firebase-tools@${FIREBASE_TOOLS_VERSION} && \
firebase experiments:enable webframeworks

FROM base as firebase

WORKDIR /usr/src/app

FROM base as functions

WORKDIR /usr/src/app

COPY functions/package*.json functions/

RUN cd functions && npm install

FROM base as app

WORKDIR /usr/src/app

ENV CYPRESS_INSTALL_BINARY=0

COPY package*.json .

RUN npm install
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,46 @@

## Introduction...

This project assists the collection and distribution of unused and gently used baby and child equipment. Over twenty dif.ferent organizations are served by this exchange.
This project assists the collection and distribution of unused and gently used baby and child equipment. Over twenty different organizations are served by this exchange.

## Dev Local Setup - Docker Compose Option
[Docker compose](https://docs.docker.com/compose/intro/features-uses/) provides a way to manage and orchestrate local environment services.

Currently, we use 3 services:
- firebase - Our firebase emulator which provides access to local firebase services
- functions - A convenient wrapper around our firebase functions project which aims to automate the dev build + reloading of the functions compilation.
- nextjs - Our main nextjs application

Pre-requisities
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)

Config Setup
1. Create / Acquire firebase configuration, `firebase-config.json`, put in the root directory.
2. Acquire Service Account Credentials, `service-account.json`, put in the root directory.

** Both of these files should be ignored by git **

Quick Start: `docker compose build && docker compose up -d`

In general, the urls that should be available after doing this:
- http://localhost:3000 - nextjs app
- http://localhost:4000 - firebase emulator ui
- http://localhost:5001 - functions api

Common Commands:
- Build `docker compose build` (builds all images)
- Start `docker compose up -d` (starts all services)
- Stop `docker compose down --remove-orphans --volumes` (stops all containers and cleans up)

Other Commands:
- Logs `docker compose logs --follow` (shows logs across all services)
- Run `docker compose run --no-deps -T --rm <service> <command>` (runs a one time <command> on a <service> (--no-deps dont start any other services) (--rm remove after run) (-T if running a background command that requires no input/shell))

Cleanup Commands:
Over time, images, containers, volumes will need to be cleaned up.
- Everything `docker system prune -a`
- Images `docker image prune -a`
- Volumes `docker volume prune -a`

## Dev remote Setup (Recommended for consistency, you can dev local if you don't want to work with docker)

Expand Down
52 changes: 52 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
services:

firebase:
image: baby-equipment-exchange-firebase
build:
context: .
target: firebase
command: firebase emulators:start --only functions
environment:
- GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS:-service-account.json}
- FIREBASE_CONFIG=${FIREBASE_CONFIG:-firebase-config.json}
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
- /usr/src/app/functions/node_modules
ports:
# https://firebase.google.com/docs/emulator-suite/install_and_configure#port_configuration
- "4000:4000" # Emulator Suite UI
- "5001:5001" # Cloud Functions

functions:
image: baby-equipment-exchange-functions
build:
context: .
target: functions
working_dir: /usr/src/app/functions
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
- /usr/src/app/functions/node_modules
command: npm run build:watch
environment:
- GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS:-service-account.json}
- FIREBASE_CONFIG=${FIREBASE_CONFIG:-firebase-config.json}
- NODE_ENV=development
depends_on:
- firebase

nextjs:
image: baby-equipment-exchange-nextjs
build:
context: .
target: app
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
- /usr/src/app/functions/node_modules
ports:
- "3000:3000"
command: npm run alt-dev
environment:
- FIREBASE_CONFIG=${FIREBASE_CONFIG:-firebase-config.json}
68 changes: 68 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"source": ".",
"ignore": [
"firebase.json",
"*/.",
"*/node_modules/*"
],
"frameworksBackend": {
"region": "us-east1",
"maxInstances":10
}
},
"storage": {
"rules": "storage.rules"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"emulators": {
"auth": {
"enabled": false,
"host": "0.0.0.0",
"port": 9099
},
"firestore": {
"enabled": false,
"host": "0.0.0.0",
"port": 8080
},
"functions": {
"enabled": true,
"host": "0.0.0.0",
"port": 5001
},
"hosting": {
"enabled": true,
"host": "0.0.0.0",
"port": 5000
},
"storage": {
"enabled": false,
"host": "0.0.0.0",
"port": 9199
},
"ui": {
"enabled": true,
"host": "0.0.0.0",
"port": 4000
}
}
}
4 changes: 4 additions & 0 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
53 changes: 53 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
rules_version = '2';

service cloud.firestore {
match /databases/{database}/documents {
// Administrator role
match /Events/{document=**} {
allow read: if request.auth != null && request.auth.token.admin == true;
}
match /Donations/{document=**} {
allow read: if request.auth != null && request.auth.token.admin == true;
}
match /DonationDetails/{document=**} {
allow read: if request.auth != null && request.auth.token.admin == true;
}
match /Images/{document=**} {
allow read: if request.auth != null && request.auth.token.admin == true;
}
match /ImageDetails/{document=**} {
allow read: if request.auth != null && request.auth.token.admin == true;
}
match /Organizations/{document=**} {
allow create, read, update, write: if request.auth != null && request.auth.token.admin == true;
}
match /Storage/{document=**} {
allow create, read, update, write: if request.auth != null && request.auth.token.admin == true;
}
match /Users/{document=**} {
allow read: if request.auth != null && request.auth.token.admin == true;
}
match /UserDetails/{document=**} {
allow read, update: if request.auth != null && request.auth.token.admin == true;
}
// Standard user role
match /Donations/{document=**} {
allow create, read, update, write: if request.auth != null;
}
match /DonationDetails/{document=**} {
allow create, read, update, write: if request.auth != null;
}
match /Images/{document=**} {
allow create, read: if request.auth != null;
}
match /ImageDetails/{document=**} {
allow create, read: if request.auth != null;
}
match /Users/{userId} {
allow create, read, update, write: if request.auth != null && request.auth.uid == userId;
}
match /UserDetails/{userId} {
allow create, read, update, write: if request.auth != null && request.auth.uid == userId;
}
}
}
Loading

0 comments on commit e473bce

Please sign in to comment.