diff --git a/.env.docker b/.env.docker new file mode 100644 index 0000000..f9c361b --- /dev/null +++ b/.env.docker @@ -0,0 +1,3 @@ +# Environment variables to use for local Docker setup +DATABASE_URL="postgresql://postgres:password@db:5432/prisma?schema=public" +NODE_ENV="development" diff --git a/Dockerfile b/Dockerfile index 4721a08..b963322 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,19 @@ -FROM node:8.12.0-alpine as Builder +FROM node:22.8.0-alpine3.20 AS builder WORKDIR /usr/app -# See .dockerignore for copied files COPY . . -RUN npm install --no-package-lock -RUN npm run build:production +RUN npm install +RUN npm run build -FROM node:8.12.0-alpine -WORKDIR /app -COPY --from=Builder /usr/app/dist /app/dist -COPY --from=Builder /usr/app/package.json /app/package.json -RUN npm install --no-package-lock --production -# EXPOSE 4000 - -CMD ["node", "./dist/main.js"] +FROM node:22.8.0-alpine3.20 +WORKDIR /app +COPY --from=builder /usr/app/dist /app/dist +COPY --from=builder /usr/app/package.json /app/package.json +COPY --from=builder /usr/app/src/prisma/schema.prisma /app/src/prisma/schema.prisma +RUN npm install +CMD ["node", "./dist/main.js"] diff --git a/docker-compose.yaml b/docker-compose.yaml index a4ed318..2190e4a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,44 +6,19 @@ services: POSTGRES_USER: postgres POSTGRES_PASSWORD: password POSTGRES_DB: prisma - networks: - - "prisma" - prisma: - container_name: "prisma" - image: prismagraphql/prisma:1.22 - restart: always + # The API is better launched using `npm run dev` for hot reloading + api: + container_name: graphql-api + build: . + env_file: + - ./.env.docker + command: > + sh -c ' + sleep 5 && + npx prisma migrate dev --name init && + npx prisma generate' ports: - - 7766:7766 - environment: - PRISMA_CONFIG: | - port: 7766 - databases: - default: - connector: postgres - active: true - host: db - port: 5432 - user: postgres - password: password - migrations: true + - 4000:4000 depends_on: - # - api - db - networks: - - "prisma" - - # The API is better launched using `npm run dev` for hot reloading - # api: - # container_name: graphql-api - # build: - # context: ./backend - # dockerfile: ./Dockerfile - # env_file: - # - ./backend/.env.dev - # ports: - # - 4000:4000 - -networks: - prisma: - driver: "bridge"