diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..97365c7 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,30 @@ +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"]