From 4a992478a9df9919a1ca6860aac2df52ca79cb96 Mon Sep 17 00:00:00 2001 From: Harsh Jain <harsh.jain@niveussolutions.com> Date: Wed, 6 Nov 2024 19:01:08 +0530 Subject: [PATCH] env added --- .dockerignore | 3 +++ .env | 1 + .gitignore | 3 +-- docker.compose.yaml | 11 +++++++++++ dockerfile | 25 +++++++++++++++++++++++++ index.js | 2 +- 6 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 .env diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..942162e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +Dockerfile +.dockerignore \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 0000000..0e41d3e --- /dev/null +++ b/.env @@ -0,0 +1 @@ +PORT = 3000 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1dcef2d..b512c09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -node_modules -.env \ No newline at end of file +node_modules \ No newline at end of file diff --git a/docker.compose.yaml b/docker.compose.yaml index e69de29..bb647bd 100644 --- a/docker.compose.yaml +++ b/docker.compose.yaml @@ -0,0 +1,11 @@ +version: "3.8" +services: + app_server: + container_name: app_server + image: app_server:1.0.0 + build: + context: . + dockerfile: ./Dockerfile + command: npm run start + env_file: .env + ports: '3000:3000' \ No newline at end of file diff --git a/dockerfile b/dockerfile index e69de29..0ed8a67 100644 --- a/dockerfile +++ b/dockerfile @@ -0,0 +1,25 @@ +FROM node:18-alpine + +WORKDIR /app + +# Copy package.json and package-lock.json first (this leverages Docker cache for better efficiency) +COPY package.json . +COPY package-lock.json . + +# Install dependencies +RUN npm install + +# Copy the rest of the application code +COPY . . + +# Copy .env file if necessary for environment variables +COPY .env .env + +# Expose the application port +EXPOSE 3000 + +# Command to run the application +CMD ["npm", "start"] + +# Optionally, add a health check +# HEALTHCHECK CMD curl --fail http://localhost:3000/ || exit 1 diff --git a/index.js b/index.js index 59e23a2..caee80d 100644 --- a/index.js +++ b/index.js @@ -9,5 +9,5 @@ app.get('/', (req,res)=>{ }); app.listen(PORT, ()=>{ - console.log(`Listening to http://localhost:3001`); + console.log(`Listening to http://localhost:${PORT}`); }) \ No newline at end of file -- GitLab