From 6820dc9155ab0990cb0f95b2ac73add7c0e1a431 Mon Sep 17 00:00:00 2001 From: Kundan Date: Fri, 14 Jun 2024 17:01:44 +0530 Subject: [PATCH 1/2] Commit message describing submodule changes --- .github/workflows/docker-image.yml | 29 +++++++++++++++++++++++++++++ README.md | 8 ++++++++ backend/Dockerfile | 20 ++++++++++++++++++++ docker-compose.yml | 12 ++++++++++++ frontend/Dockerfile | 24 ++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/Dockerfile diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..444c2b4 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,29 @@ +name: Build and Push Docker Images + +on: + push: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Login to GitHub Packages + run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + + - name: Build and push backend image + working-directory: sample-fullstack-application\backend # Relative path to the backend directory + run: | + docker build -t docker.pkg.github.com/glitcher007/sample-fullstack-application/backend:latest . + docker push docker.pkg.github.com/glitcher007/sample-fullstack-application/backend:latest + + - name: Build and push frontend image + working-directory: sample-fullstack-application\frontend # Relative path to the frontend directory + run: | + docker build -t docker.pkg.github.com/glitcher007/sample-fullstack-application/frontend:latest . + docker push docker.pkg.github.com/glitcher007/sample-fullstack-application/frontend:latest diff --git a/README.md b/README.md index dc4d5b6..383551e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # Sample Fullstack Application +# Full Stack Application + +## Running the Project with Docker + +1. **Clone the Repository**: + ```sh + git clone https://github.com/your-username/your-repo.git + cd your-repo diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..af7f71e --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,20 @@ +# Dockerfile for React frontend +FROM node:14-alpine as build + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN npm run build + +FROM nginx:alpine + +COPY --from=build /app/build /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..443c385 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3' + +services: + backend: + image: docker.pkg.github.com/glitcher007/sample-fullstack-application/backend:latest + ports: + - "3000:3000" + + frontend: + image: docker.pkg.github.com/glitcher007/sample-fullstack-application/frontend:latest + ports: + - "80:80" diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..b54f561 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,24 @@ +# Use an official Node.js image as the base image +FROM node:14-alpine + +# Set the working directory inside the container +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package.json ./ +COPY package-lock.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the application code to the working directory +COPY . . + +# Build the application +RUN npm run build + +# Expose port 3000 for the application +EXPOSE 3000 + +# Start the application +CMD ["npm", "start"] From f6b64c1d91a2d94a473578488fb9ef396c8f630e Mon Sep 17 00:00:00 2001 From: Kundan Date: Fri, 14 Jun 2024 19:08:07 +0530 Subject: [PATCH 2/2] Main --- .github/workflows/docker-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 444c2b4..97365c7 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,6 +9,7 @@ jobs: build-and-push: runs-on: ubuntu-latest + steps: - name: Checkout repository uses: actions/checkout@v2