Skip to content

Commit

Permalink
feat: add working docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Gum-Joe committed Oct 18, 2024
1 parent 7a20193 commit 8a5df0c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions collection/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Dockerfile for docker compose
FROM node:18

RUN npm i -g nx
31 changes: 31 additions & 0 deletions collection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DoCSoc Collection System

This is a Next.js Application that allows us to manage merchandise collections securely. Designed to be ran as a docker container with a Postgres DB.

Once deployed, it allows us to control committee member access, import items from eActivities CSV exports, and mark item as collected.

# Why no `package.json`?

This folder has no package.json as it means we can share the same `package.json` as the rest of the monorepo. This means we can share dependencies like React and scripts across all app, rather than having to maintain multiple `package.json` files and React versions, etc.

Other tools have their own package.jsons as that was how they were originally set up.

# Quick Start

## Local

1. From the root of the repo run `npm install`
2. Copy `.env.local.template` to `.env.local` and fill in the details
3. Run from this dir `npx nx prisma-push` to create the database
4. Run from this dir `npx nx dev` to start the dev server

## Docker

1. Copy `.env.local.template` to `.env.local` and fill in the details
2. From the current dir (`collection`) run `docker compose -f dev.docker-compose.yml up`. This start a dev docker compose instance that has the source code _mounted_ into it: meaning you need not rebuild the docker image every time you make a change!
3. Visit `http://localhost:3000` in your browser and login with the root user you setu in the `.env.local` file
4. To run future DB migrations in docker compose run `docker exec -i $(docker ps -qf "name=docsoc-collection" | head -n1) npx nx prisma-migrate collection --name migration-name`

# Docker

To build the docker image, run `npx nx container collection` from the _root_ of the repo.
36 changes: 36 additions & 0 deletions collection/dev.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
docsoc-collection:
image: docsoc/collection-dev
pull_policy: never
build:
context: .
dockerfile: Dockerfile.dev
depends_on:
- docsoc-database
environment:
- NODE_ENV=development
- COLLECTION_DATABASE_URL=postgres://user:pass@docsoc-database:5432/docsoc
env_file: .env.local
ports:
- "3000:3000"
volumes:
- ..:/app
working_dir: /app
command:
- bash
- -c
- ./collection/scripts/compose-entry.sh

docsoc-database:
image: postgres:16
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=docsoc
ports:
- "5432:5432"
volumes:
- database-data:/var/lib/postgresql/data

volumes:
database-data:
2 changes: 2 additions & 0 deletions collection/scripts/compose-entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npx nx prisma-deploy collection --dev
npx nx run collection:dev

0 comments on commit 8a5df0c

Please sign in to comment.