Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No seed part in dockerfile #12

Open
kasir-barati opened this issue Mar 20, 2022 · 2 comments
Open

No seed part in dockerfile #12

kasir-barati opened this issue Mar 20, 2022 · 2 comments

Comments

@kasir-barati
Copy link

Please add more details about when we have seeds. Personally I did this:
Dockerfile

# As you understood I have another base.Dockerfile to do npm ci and commit it as my base image. I did this because in my area Net bother me a lot and my image build time was around 20 min and mostly failed due to Socket timeout error while npm ci
# FROM node:16.14.0-alpine3.15 as build_stage
FROM take-report:dep as build_stage

# README: Because WORKDIR is set in the take-report:dep I ignore to use it here again
# WORKDIR /app
# When using COPY with more than one source file, the destination must be a directory and end with a /
COPY prisma ./prisma/
COPY . .
RUN npx prisma generate
RUN npm run build
# RUN npm prune --production

FROM node:16.14.0-alpine3.15

WORKDIR /app

COPY --from=build_stage /app/node_modules ./node_modules
COPY --from=build_stage /app/package*.json ./
COPY --from=build_stage /app/tsconfig*.json ./
COPY --from=build_stage /app/dist ./dist
COPY --from=build_stage /app/prisma ./prisma

EXPOSE $APP_PORT

And this is my docker-compose.yml file:

version: '3.7'

services:
  take-report:
    image: take-report:v1
    restart: unless-stopped
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        - DATABASE_URL
    ports: 
      - ${APP_EXPOSED_PORT}:$APP_PORT
    env_file:
      - .env
    networks:
      - take-report
      - traefik_default
    labels:
      - "traefik.enable=true"
    command: npm run start:prisma:prod

And in my package.json I have these scripts:

"start:prisma:prod": "npm run prisma:dev && node dist/src/main",
"prisma:dev": "npx prisma generate && npx prisma deploy && npx prisma db seed",

But my problem with this solution is that I have to run npm prune --production after my seed completed. Do you have any idea to improve this?

@Furkan-Gulsen
Copy link

image
I get this error when I apply your management. How can I solve it? @kasir-barati

@kasir-barati
Copy link
Author

@Furkan-Gulsen It is elementary, Did you have the prisma installed as a dev Dependency? if not do this npm i -D prisma.
Then it should work.
The other options is to install prisma globally before the RUN npx prisma generate. But please note that I used to use a custom images. My base.Dockerfile for the take-report:dep is this:

# Just because of too many socket timeout and bottleneck while installing 3rd party packages I did this.

FROM node:16.14.0-alpine3.15

WORKDIR /app
# When using COPY with more than one source file, the destination must be a directory and end with a /
COPY package*.json ./
RUN NODE_ENV=development npm ci

And eventually I docker build . -f base.Dockerfile -t take-report:dep. I hope this helps you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants