Skip to content

Commit

Permalink
Optimise Docker Image, remove crypto package
Browse files Browse the repository at this point in the history
  • Loading branch information
yash22arora committed May 24, 2024
1 parent 21bf2d2 commit fd516b5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
36 changes: 31 additions & 5 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
FROM node:18
FROM node:18 as base
# Create app directory
WORKDIR /server
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

# RUN npm install
# If you are building your code for production
RUN npm install

# Install TypeScript globally
RUN npm install -g typescript

# RUN npm install
# If you are building your code for production
RUN npm ci --omit=dev
FROM base as build

WORKDIR /server

# Bundle app source
COPY . .

# Because we have the postinstall script in the package.json file, we dont need to run the tsc command separately. npm install will take care of it.
# Build the app
RUN npm run tsc


FROM node:18-alpine

WORKDIR /server

COPY package*.json ./

RUN npm i -g npm@latest

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

RUN npm ci --omit=dev

COPY --from=build /server/dist ./dist
RUN ls dist
RUN chown -R node:node /server

USER node

# Expose the port the app runs on
EXPOSE 5000
Expand Down
12 changes: 0 additions & 12 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./dist/server.js",
"dev": "ts-node-dev --respawn --pretty --transpile-only ./src/server.ts",
"tsc": "tsc",
"postinstall": "npm run tsc"
"tsc": "tsc"
},
"author": "Yashvardhan Arora",
"license": "ISC",
"dependencies": {
"axios": "^1.3.4",
"body-parser": "^1.20.2",
"crypto": "^1.0.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion server/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();

import * as crypto from "crypto";
import crypto from "crypto";

// Encryption and decryption key
const ENCRYPTION_KEY = process.env.CIPHER_KEY!; // Must be 256 bits (32 characters)
Expand Down

0 comments on commit fd516b5

Please sign in to comment.