Skip to content

Commit

Permalink
docker: Add a docker-based dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Feb 20, 2024
1 parent dbdde49 commit 2f966d3
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ jobs:
- uses: actions/checkout@v4

- name: Build image
working-directory: ./docker
run: |
docker build . --target workers --tag hoarder-workers
docker build . --target web --tag hoarder-web
docker build .. --target workers --tag hoarder-workers -f Dockerfile
docker build .. --target web --tag hoarder-web -f Dockerfile
- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
pull_request:
jobs:
build-lint:
name: Build and Lint
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ I'm a systems engineer in my day job (and have been for the past 7 years). I did

## Development

### Docker

You can turnup the whole development environment with:
`docker compose -f docker/docker-compose.dev.yml up`

### Manual

Or if you have nodejs installed locally, you can do:

- `yarn install` in the root of the repo.
- `yarn prisma:migrate:dev` then `yarn prisma:generate` to generate prisma's data and run the database migrations.
- `yarn web` to start the web app.
Expand All @@ -75,3 +84,7 @@ I'm a systems engineer in my day job (and have been for the past 7 years). I did
- `packages/shared`: Shared utilities and code between the workers and the web app.
- `packages/web`: Where the nextjs based web app lives.
- `packages/workers`: Where the background job workers (crawler and openai as of now) run.

### Submitting PRs

- Before submitting PRs, you'll want to run `yarn format` and include its changes in the commit. Also make sure `yarn lint` is successful.
8 changes: 2 additions & 6 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ ENV CHROME_PATH "/usr/bin/chromium-browser"
ENV BROWSER_EXECUTABLE_PATH "/app/start-chrome.sh"
ENV BROWSER_USER_DATA_DIR="/tmp/chrome"

RUN echo '#!/bin/sh' >> /app/start-chrome.sh && \
echo 'set -x;' >> /app/start-chrome.sh && \
echo 'id -u chrome &>/dev/null || adduser -S chrome' >> /app/start-chrome.sh && \
echo 'mkdir -p /tmp/chrome && chown chrome /tmp/chrome' >> /app/start-chrome.sh && \
echo 'runuser -u chrome -- $CHROME_PATH $@' >> /app/start-chrome.sh && \
chmod +x /app/start-chrome.sh
ADD start-chrome.sh .
RUN chmod +x /app/start-chrome.sh

COPY packages/db packages/db
COPY packages/shared packages/shared
Expand Down
11 changes: 11 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:21-alpine

RUN apk add --no-cache libc6-compat chromium runuser make g++ py3-pip linux-headers
ENV PUPPETEER_SKIP_DOWNLOAD true
ENV CHROME_PATH "/usr/bin/chromium-browser"
ENV BROWSER_EXECUTABLE_PATH "/bin/start-chrome.sh"
ENV BROWSER_USER_DATA_DIR="/tmp/chrome"

WORKDIR /app
ADD start-chrome.sh /bin
RUN chmod +x /bin/start-chrome.sh
58 changes: 58 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "3.8"
services:
web:
build:
dockerfile: Dockerfile.dev
volumes:
- data:/data
- ..:/app
ports:
- 3000:3000
environment:
REDIS_HOST: redis
DATABASE_URL: "file:/data/db.db"
command:
- yarn
- web
working_dir: /app
depends_on:
prep:
condition: service_completed_successfully
redis:
image: redis:7.2-alpine
volumes:
- redis:/data
workers:
build:
dockerfile: Dockerfile.dev
volumes:
- data:/data
- ..:/app
working_dir: /app
environment:
REDIS_HOST: redis
DATABASE_URL: "file:/data/db.db"
# OPENAI_API_KEY: ...
command:
- yarn
- workers
depends_on:
prep:
condition: service_completed_successfully
prep:
build:
dockerfile: Dockerfile.dev
working_dir: /app
environment:
DATABASE_URL: "file:/data/db.db"
volumes:
- data:/data
- ..:/app
command:
- /bin/sh
- -c
- "corepack enable && yarn install --immutable && yarn prisma:generate && yarn prisma:migrate:dev"

volumes:
redis:
data:
1 change: 1 addition & 0 deletions docker-compose.yml → docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
environment:
REDIS_HOST: redis
DATABASE_URL: "file:/data/db.db"
# OPENAI_API_KEY: ...
depends_on:
migration:
condition: service_completed_successfully
Expand Down
7 changes: 7 additions & 0 deletions docker/start-chrome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -x;
id -u chrome &>/dev/null || adduser -S chrome;
mkdir -p $BROWSER_USER_DATA_DIR;
chown chrome $BROWSER_USER_DATA_DIR;
runuser -u chrome -- $CHROME_PATH --no-sandbox $@;
4 changes: 4 additions & 0 deletions docker/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit 2f966d3

Please sign in to comment.