From e86e0d60278f751342be30ef5ba91811669b44b2 Mon Sep 17 00:00:00 2001 From: Dm1tr1y147 Date: Wed, 11 Nov 2020 19:11:02 +0300 Subject: [PATCH] Some deployment fixes --- .dockerignore | 1 + Dockerfile | 20 ++++++++++++++++---- package.json | 5 +++-- src/controllers/auth.ts | 2 -- src/controllers/mailer.ts | 2 -- src/index.ts | 2 -- 6 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ diff --git a/Dockerfile b/Dockerfile index d9f8c51..153dbda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,19 @@ -FROM node:14.4.0 -USER root +FROM node:alpine AS builder WORKDIR /backend -COPY . /backend +COPY package.json /backend/package.json RUN yarn +COPY . /backend +RUN yarn codegen +RUN yarn prisma generate RUN yarn build -CMD [ "node", "./dist/index.js" ] \ No newline at end of file + +FROM node:alpine +WORKDIR /backend +COPY --from=builder /backend/dist /backend +COPY package.json /backend/package.json +RUN yarn install --prod +COPY --from=builder /backend/node_modules/@prisma/client /backend/node_modules/@prisma/client +COPY --from=builder /backend/node_modules/.prisma/client/ /backend/node_modules/.prisma/client/ +COPY --from=builder /backend/prisma /backend/prisma +USER node +CMD [ "node", "./index.js" ] diff --git a/package.json b/package.json index cb5d666..88720ac 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "scripts": { "dev": "nodemon", "start": "ts-node src/index.ts", - "copy-assets": "cp src/typeDefs/typeDefs.gql dist/typeDefs/typeDefs.gql && cp .env.example dist/.env && vi dist/.env", + "copy-assets": "cp src/typeDefs/typeDefs.gql dist/typeDefs/typeDefs.gql", "build": "tsc && yarn copy-assets", "codegen": "graphql-codegen --config codegen.yml", "lint": "eslint", @@ -32,6 +32,7 @@ "@types/dotenv": "^8.2.0", "dotenv": "^8.2.0", "ts-node": "^9.0.0", - "typescript": "^4.0.3" + "typescript": "^4.0.3", + "@prisma/cli": "2.8.1" } } diff --git a/src/controllers/auth.ts b/src/controllers/auth.ts index c06548b..33e3e0a 100644 --- a/src/controllers/auth.ts +++ b/src/controllers/auth.ts @@ -6,8 +6,6 @@ import { } from 'apollo-server-express' import { PrismaClient } from '@prisma/client' -require('dotenv').config() - import { CheckRightsAndResolve } from './types' import { getDBFormAuthor } from '../db' import { sendToken } from './mailer' diff --git a/src/controllers/mailer.ts b/src/controllers/mailer.ts index e1a2b15..091ed12 100644 --- a/src/controllers/mailer.ts +++ b/src/controllers/mailer.ts @@ -1,7 +1,5 @@ import sgMail from '@sendgrid/mail' -require('dotenv').config() - sgMail.setApiKey('' + process.env.SENDGRID_API_KEY) const sendToken = (username: string, email: string, token: string) => { diff --git a/src/index.ts b/src/index.ts index e38bbf8..3b0da04 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,6 @@ import { ApolloContextType, JwtPayloadType } from './types' import { ApolloServer, makeExecutableSchema } from 'apollo-server-express' import { PrismaClient } from '@prisma/client' -require('dotenv').config() - const app = express() app.use(