diff --git a/.env.example b/.env.example index 03f7815..5355076 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/dev.Dockerfile b/dev.Dockerfile index 7dbb1c2..490c454 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -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 @@ -16,7 +28,7 @@ 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 @@ -24,6 +36,8 @@ 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; \ diff --git a/docker-compose.yml b/docker-compose.yml index 7ea5224..bc9f987 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/docs/docker.md b/docs/docker.md index 20aff49..e9413dc 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -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.