Skip to content

Commit

Permalink
Dockerize app
Browse files Browse the repository at this point in the history
  • Loading branch information
shekharnwagh committed May 15, 2021
1 parent f821ce7 commit b85cd7b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
.vscode
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

.build
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Use the official lightweight Node.js 14 image.
# https://hub.docker.com/_/node
FROM node:14-alpine

# Create and change to the app directory.
WORKDIR /usr/src/app

# APP Environment
ENV APP_ENV="staging"

# HUSKY Disable Hooks
ENV HUSKY=0

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY package*.json ./

# RUN apk --no-cache --virtual build-dependencies add \
# python \
# make \
# g++ \
# && npm ci \
# && apk del build-dependencies
# Install production dependencies.
# If you add a package-lock.json, speed your build by switching to 'npm ci'.
# RUN npm ci
RUN npm ci --only=production --ignore-scripts

# Copy local code to the container image.
COPY . ./

# Typescript
RUN npm run build

EXPOSE 8080

# Run the web service on container startup.
CMD [ "node", ".build/server.js" ]
23 changes: 6 additions & 17 deletions package-lock.json

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

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "tsc",
"prestart": "npm run lint & npm run build",
"dev": "nodemon --watch './**/*.ts' --exec 'ts-node' server.ts",
"start": "node .build/server.js"
"start": "node .build/server.js",
"build:image": "docker build -t cowin-notify-server ."
},
"repository": {
"type": "git",
Expand All @@ -22,9 +23,6 @@
},
"homepage": "https://github.com/shekharnwagh/cowin-notify-server#readme",
"devDependencies": {
"@types/express": "^4.17.11",
"@types/node": "^15.3.0",
"@types/verror": "^1.10.4",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"eslint": "^7.26.0",
Expand All @@ -36,11 +34,14 @@
"lint-staged": "^11.0.0",
"nodemon": "^2.0.7",
"prettier": "^2.3.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
"ts-node": "^9.1.1"
},
"dependencies": {
"@types/express": "^4.17.11",
"@types/node": "^15.3.0",
"@types/verror": "^1.10.4",
"express": "^4.17.1",
"winston": "^3.3.3"
"winston": "^3.3.3",
"typescript": "^4.2.4"
}
}
16 changes: 8 additions & 8 deletions server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express, { Request, Response } from 'express';
// import Constants from './src/constants';
import Constants from './src/constants';
import { logger } from './src/utils';

const app = express();
Expand All @@ -10,14 +10,14 @@ app.get('/status', (request: Request, response: Response) => {
response.status(200).send({ success: true });
});

// if (process.env.APP_ENV === Constants.APP_ENV.DEVELOPMENT) {
// const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;
// const HOST = process.env.HOST ? process.env.HOST : 'localhost';
if (process.env.APP_ENV === Constants.APP_ENV.DEVELOPMENT) {
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;
const HOST = process.env.HOST ? process.env.HOST : 'localhost';

// app.listen(PORT, HOST, () => {
// logger.info(`Started server on HOST: ${HOST}, at PORT: ${PORT}`);
// });
// }
app.listen(PORT, HOST, () => {
logger.info(`Started server on HOST: ${HOST}, at PORT: ${PORT}`);
});
}

const port = process.env.PORT || 8080;
app.listen(port, () => {
Expand Down

0 comments on commit b85cd7b

Please sign in to comment.