Skip to content

Commit

Permalink
feat: made the Docker file Multistaged
Browse files Browse the repository at this point in the history
  • Loading branch information
hkv24 committed Sep 15, 2024
1 parent 1422b75 commit 0bf328f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/mailchimp/package-lock.json

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

4 changes: 3 additions & 1 deletion Dockerfile → Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
31 changes: 31 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -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 .
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0bf328f

Please sign in to comment.