Skip to content

Commit

Permalink
Updated workflow for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjal-barnwal committed May 26, 2024
1 parent 272c6c0 commit 426953f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
26 changes: 26 additions & 0 deletions .github/workflows/docker-react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Docker Build and Run React App

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-run:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
run: docker build -t developerstar:latest .

- name: Run Docker container
run: docker run -d -p 3000:5173 developerstar:latest
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# base docker image for our deployment
FROM node:20-alpine

# we define the working directory
WORKDIR /app

# copy selected files to WorkDir
COPY package*.json .

# suppose if we're working with Typescript, then we can also: COPY tsconfig.json

# installing all the required node packages
RUN npm install

# copying from source to destination
# since we didn't wanted node_modules to be copies, so we added it in .dockerignore file
COPY . .

# exposing the port on which we were running
EXPOSE 5173

# running our command
CMD [ "npm", "run", "dev" ]

# in the 'dev' script in package.json add '--host 0.0.0.0', so that it can run from any IP-Address
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host 0.0.0.0",
"build": "vite build",
"preview": "vite preview"
},
Expand Down

0 comments on commit 426953f

Please sign in to comment.