Skip to content

Commit

Permalink
Merge pull request #1 from anup39/docker-dev
Browse files Browse the repository at this point in the history
Docker setup for development
  • Loading branch information
anup39 committed Feb 4, 2024
2 parents 6fbe905 + 0623a8e commit fdd542c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ WFC_QUOTA_ENTERPRISE=100
TEAM_EMAIL=example@example.com
GITHUB_CLIENT_ID="example"
GITHUB_CLIENT_SECRET="example"
# Need to add the Mapbox token else the map is not loading
# The key which has been used as a public didnot work in local host may be restricted to specific domain
NEXT_PUBLIC_MAPBOX_TOKEN=xxx
24 changes: 19 additions & 5 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
FROM node:20-slim
ENV NODE_ENV=development

RUN apt-get update && apt-get install -y openssl
WORKDIR /home/node/app

WORKDIR /app
ENV PATH /home/node/app/node_modules/.bin:$PATH

RUN apt-get update && apt-get install -y openssl --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& chown -R node:node /home/node/app

# Blitz.js recommends using tini, see why: https://github.com/krallin/tini/issues/8
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

USER node

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
COPY --chown=node:node package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
if [ -f yarn.lock ]; then yarn config list && yarn install --frozen-lockfile && yarn cache clean --force; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \
# Allow install without lockfile, so example works even without Node.js installed locally
Expand All @@ -16,14 +28,16 @@ RUN \

# TODO: this would be nice to change. Like,
# moving source to src
COPY . .
COPY --chown=node:node . .

# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry
# Uncomment the following line to disable telemetry at run time
ENV NEXT_TELEMETRY_DISABLED 1

# Note: Don't expose ports here, Compose will handle that for us

ENTRYPOINT ["/tini", "--"]

# Start Next.js in development mode based on the preferred package manager
CMD \
if [ -f yarn.lock ]; then yarn dev; \
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ services:
- 5432:5432
web: &web
build:
context: .
dockerfile: dev.Dockerfile
env_file:
- .env.local
volumes:
- .:/app
user: node
command: yarn dev
command: /bin/sh -c 'blitz prisma migrate deploy && blitz prisma generate && yarn dev'
ports:
- 3000:3000
depends_on:
Expand Down
17 changes: 15 additions & 2 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,36 @@ configuration is a little new. Note that this docker configuration
is optimized for _development_ - we don't yet have a configuration
for production.



#### Prepare

```bash
cp .env.example .env.local
```

### Add your Mapbox access token in
``` .env.local ```

`NEXT_PUBLIC_MAPBOX_TOKEN=YOUR_MAPBOX_ACCESS_TOKEN`

#### Build

```bash
docker compose build
docker-compose build
```

#### Run

```bash
docker compose up
docker-compose up
```
#### Run in detached(background) mode

```bash
docker-compose up -d
```


- Open [localhost:3000](http://localhost:3000/) for the server.
- Open [localhost:5555](http://localhost:5555/) for the Prisma database browser.

0 comments on commit fdd542c

Please sign in to comment.