From 0bf328fa286a6506fdc1ad0601f74e36ad3cad78 Mon Sep 17 00:00:00 2001 From: hkv24 Date: Sun, 15 Sep 2024 21:50:10 +0530 Subject: [PATCH] feat: made the Docker file Multistaged --- .../scripts/mailchimp/package-lock.json | 2 +- Dockerfile => Dockerfile.dev | 4 ++- Dockerfile.prod | 31 +++++++++++++++++++ README.md | 19 +++++++++--- 4 files changed, 50 insertions(+), 6 deletions(-) rename Dockerfile => Dockerfile.dev (69%) create mode 100644 Dockerfile.prod diff --git a/.github/workflows/scripts/mailchimp/package-lock.json b/.github/workflows/scripts/mailchimp/package-lock.json index 7ee7d84f86f..cc41a360da7 100644 --- a/.github/workflows/scripts/mailchimp/package-lock.json +++ b/.github/workflows/scripts/mailchimp/package-lock.json @@ -594,4 +594,4 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" } } -} \ No newline at end of file +} diff --git a/Dockerfile b/Dockerfile.dev similarity index 69% rename from Dockerfile rename to Dockerfile.dev index f0d69e54df0..d1a2c583203 100644 --- a/Dockerfile +++ b/Dockerfile.dev @@ -13,7 +13,9 @@ COPY . . # Expose the port for development (if needed) EXPOSE 3000 -# Set environment variables for development (optional) +# Set environment variables for development ENV NODE_ENV=development CMD ["npm", "run", "dev"] + +# Build command -> docker build -f Dockerfile.dev --build-arg NODE_ENV=development -t app-dev . diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 00000000000..6e8d9a57477 --- /dev/null +++ b/Dockerfile.prod @@ -0,0 +1,31 @@ +FROM node:18-alpine AS build + +WORKDIR /async + +# Install all dependencies +COPY package.json package-lock.json ./ +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Production Stage +FROM node:18-alpine + +WORKDIR /async + +# Install production dependencies only +COPY package.json package-lock.json ./ +RUN npm install --only=production + +# Copy built files from the build stage +COPY --from=build /async . + +EXPOSE 3000 + +# Set environment variables for production +ENV NODE_ENV=production + +CMD ["npm", "run", "start"] + +# Build command -> docker build -f Dockerfile.prod --build-arg NODE_ENV=production -t app-prod . diff --git a/README.md b/README.md index 5eab72063aa..af41e2d3be0 100644 --- a/README.md +++ b/README.md @@ -123,14 +123,25 @@ Generated files of the storybook go to the `storybook-static` folder. After cloning repository to your local, perform the following steps from the root of the repository. #### Steps: -1. Build the Docker image: +1. Development Setup with Docker: + 1. Build the Docker image: ```bash - docker build -t asyncapi-website .` + docker build -f Dockerfile.dev --build-arg NODE_ENV=development -t app-dev . ``` -2. Start the container: + 2. Start the container: ```bash - docker run --rm -it -v "$PWD":/async -p 3000:3000 asyncapi-website + docker run --rm -it -v "$PWD":/async -p 3000:3000 app-dev ``` +2. Production Setup with Docker + 1. Build the Docker image: + ```bash + docker build -f Dockerfile.prod --build-arg NODE_ENV=production -t app-prod . + ``` + 2. Start the container: + ```bash + docker run --rm -p 3000:3000 app-prod + ``` + Now you're running AsyncAPI website in a development mode. Container is mapped with your local copy of the website. Whenever you make changes to the code, the website will refresh and changes visible in localhost:3000.