From d648311d6bc9d07b4228f1ff6369e9221937932b Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 15:41:42 +0530 Subject: [PATCH 01/10] Create Dockerfile --- Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b7d722e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# Use an official Node.js runtime as a parent image +FROM node:16 + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy the package.json and package-lock.json files +# This is done to install dependencies first, before copying the rest of the application files +COPY package*.json ./ + +# Install the app dependencies +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Expose the port the app will run on (typically 3000 for Node.js apps) +EXPOSE 3000 + +# Define the command to run your app +CMD ["npm", "start"] +# Use an official Node.js runtime as a parent image +FROM node:16 + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy the package.json and package-lock.json files +# This is done to install dependencies first, before copying the rest of the application files +COPY package*.json ./ + +# Install the app dependencies +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Expose the port the app will run on (typically 3000 for Node.js apps) +EXPOSE 3000 + +# Define the command to run your app +CMD ["npm", "start"] From 00ab389782cf09471eacf0a483e037cda05e1b86 Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 15:44:44 +0530 Subject: [PATCH 02/10] Create node.js.yml --- .github/workflows/node.js.yml | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..aafa2b8 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,51 @@ +name: Node.js CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + - run: npm ci + + - run: npm run build --if-present + + - run: npm test + + # Docker steps to build and push to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build Docker image + run: | + docker build -t your-dockerhub-username/my-node-app:${{ github.sha }} . + + - name: Push Docker image to Docker Hub + run: | + docker push your-dockerhub-username/my-node-app:${{ github.sha }} + + # Optional: Tag the image with the "latest" tag + - name: Tag and Push Latest Docker Image + run: | + docker tag your-dockerhub-username/my-node-app:${{ github.sha }} your-dockerhub-username/my-node-app:latest + docker push your-dockerhub-username/my-node-app:latest From 250fd2ebe08a6f4de11273ba4602346d7d38fec6 Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 15:51:16 +0530 Subject: [PATCH 03/10] Update node.js.yml --- .github/workflows/node.js.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index aafa2b8..8a8753e 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -49,3 +49,4 @@ jobs: run: | docker tag your-dockerhub-username/my-node-app:${{ github.sha }} your-dockerhub-username/my-node-app:latest docker push your-dockerhub-username/my-node-app:latest + From 42106580c11595b7bbbcc6d88aa8fbd48584064a Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 16:00:47 +0530 Subject: [PATCH 04/10] Update node.js.yml --- .github/workflows/node.js.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8a8753e..b1bd207 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - node-version: [16] + node-version: [16, 18] # Add more Node.js versions to test steps: - uses: actions/checkout@v4 @@ -23,11 +23,23 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' + - name: Cache node_modules + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci - run: npm run build --if-present - run: npm test + - run: npm run lint # Assuming you have a lint script + - run: npm audit --production --audit-level=high + + # Docker steps to build and push to Docker Hub - name: Log in to Docker Hub @@ -38,7 +50,7 @@ jobs: - name: Build Docker image run: | - docker build -t your-dockerhub-username/my-node-app:${{ github.sha }} . + docker build --cache-from=your-dockerhub-username/my-node-app:latest -t your-dockerhub-username/my-node-app:${{ github.sha }} . - name: Push Docker image to Docker Hub run: | @@ -49,4 +61,3 @@ jobs: run: | docker tag your-dockerhub-username/my-node-app:${{ github.sha }} your-dockerhub-username/my-node-app:latest docker push your-dockerhub-username/my-node-app:latest - From 8ebcef7389176082e32a7e8e10a612c302943088 Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 16:12:58 +0530 Subject: [PATCH 05/10] Update node.js.yml --- .github/workflows/node.js.yml | 90 +++++++++++++++++------------------ 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b1bd207..9a2584e 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,3 +1,5 @@ +# This workflow installs node dependencies, caches them, builds the source code, runs tests, and pushes a Docker image to Docker Hub. + name: Node.js CI on: @@ -12,52 +14,46 @@ jobs: strategy: matrix: - node-version: [16, 18] # Add more Node.js versions to test + node-version: [16] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@v4 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - - name: Cache node_modules - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - run: npm ci - - - run: npm run build --if-present - - - run: npm test - - run: npm run lint # Assuming you have a lint script - - run: npm audit --production --audit-level=high - - - - # Docker steps to build and push to Docker Hub - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build Docker image - run: | - docker build --cache-from=your-dockerhub-username/my-node-app:latest -t your-dockerhub-username/my-node-app:${{ github.sha }} . - - - name: Push Docker image to Docker Hub - run: | - docker push your-dockerhub-username/my-node-app:${{ github.sha }} - - # Optional: Tag the image with the "latest" tag - - name: Tag and Push Latest Docker Image - run: | - docker tag your-dockerhub-username/my-node-app:${{ github.sha }} your-dockerhub-username/my-node-app:latest - docker push your-dockerhub-username/my-node-app:latest + # Step 1: Checkout repository + - name: Checkout repository + uses: actions/checkout@v4 + + # Step 2: Setup Node.js + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + # Step 3: Install dependencies + - name: Install dependencies + run: npm ci + + # Step 4: Build the application + - name: Build application + run: npm run build --if-present + + # Step 5: Run tests + - name: Run tests + run: npm test -- --passWithNoTests + + # Step 6: Log in to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} # Replace with your Docker Hub username secret + password: ${{ secrets.DOCKER_PASSWORD }} # Replace with your Docker Hub password secret + + # Step 7: Build Docker image + - name: Build Docker image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/react-app:latest . + + # Step 8: Push Docker image to Docker Hub + - name: Push Docker image to Docker Hub + run: | + docker push ${{ secrets.DOCKER_USERNAME }}/react-app:latest From 6764345ceae5040be3ec762f4b77ffa5148c359e Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 16:22:13 +0530 Subject: [PATCH 06/10] Update node.js.yml --- .github/workflows/node.js.yml | 89 ++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9a2584e..c438671 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,5 +1,3 @@ -# This workflow installs node dependencies, caches them, builds the source code, runs tests, and pushes a Docker image to Docker Hub. - name: Node.js CI on: @@ -14,46 +12,51 @@ jobs: strategy: matrix: - node-version: [16] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + node-version: ["16.8.6"] # Testing on multiple Node.js versions steps: - # Step 1: Checkout repository - - name: Checkout repository - uses: actions/checkout@v4 - - # Step 2: Setup Node.js - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - # Step 3: Install dependencies - - name: Install dependencies - run: npm ci - - # Step 4: Build the application - - name: Build application - run: npm run build --if-present - - # Step 5: Run tests - - name: Run tests - run: npm test -- --passWithNoTests - - # Step 6: Log in to Docker Hub - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} # Replace with your Docker Hub username secret - password: ${{ secrets.DOCKER_PASSWORD }} # Replace with your Docker Hub password secret - - # Step 7: Build Docker image - - name: Build Docker image - run: | - docker build -t ${{ secrets.DOCKER_USERNAME }}/react-app:latest . - - # Step 8: Push Docker image to Docker Hub - - name: Push Docker image to Docker Hub - run: | - docker push ${{ secrets.DOCKER_USERNAME }}/react-app:latest + - uses: actions/checkout@v4 # Checkout the repository + + - name: Set NODE_OPTIONS to allow OpenSSL legacy provider + run: echo "NODE_OPTIONS=--openssl-legacy-provider" >> $GITHUB_ENV # Fix for OpenSSL error + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' # Enable npm caching + + - name: Cache node_modules + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - run: npm ci # Install dependencies + + - run: npm run build --if-present # Build the project if there's a build script + + - run: npm test # Run tests + + # Docker steps to build and push to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build Docker image + run: | + docker build --cache-from=your-dockerhub-username/my-node-app:latest -t your-dockerhub-username/my-node-app:${{ github.sha }} . + + - name: Push Docker image to Docker Hub + run: | + docker push your-dockerhub-username/my-node-app:${{ github.sha }} + + # Optional: Tag the image with the "latest" tag + - name: Tag and Push Latest Docker Image + run: | + docker tag your-dockerhub-username/my-node-app:${{ github.sha }} your-dockerhub-username/my-node-app:latest + docker push your-dockerhub-username/my-node-app:latest From 409bd6b4e1ed05bc266f5cc1f5eb87122a33ebfe Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 16:23:25 +0530 Subject: [PATCH 07/10] Update node.js.yml --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c438671..1516dcc 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - node-version: ["16.8.6"] # Testing on multiple Node.js versions + node-version: ["16"] # Testing on multiple Node.js versions steps: - uses: actions/checkout@v4 # Checkout the repository From 166a11ee38bdd40cfe8ba7be37c79bd1c17d2b2b Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Sun, 15 Dec 2024 16:30:18 +0530 Subject: [PATCH 08/10] Update node.js.yml --- .github/workflows/node.js.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 1516dcc..0d62e56 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - node-version: ["16"] # Testing on multiple Node.js versions + node-version: [16, 18] # Testing on multiple Node.js versions steps: - uses: actions/checkout@v4 # Checkout the repository @@ -39,6 +39,19 @@ jobs: - run: npm run build --if-present # Build the project if there's a build script - run: npm test # Run tests + import ErrorBoundary from './ErrorBoundary'; +import App from './App'; + +function Root() { + return ( + + + + ); +} + +export default Root; + # Docker steps to build and push to Docker Hub - name: Log in to Docker Hub From 63e09700fe9bf4801f7c3540e2488cdf917513a4 Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Tue, 17 Dec 2024 12:57:43 +0530 Subject: [PATCH 09/10] Update Dockerfile From df1ec440936cf2c99ac013fefa2c75eae8d40700 Mon Sep 17 00:00:00 2001 From: saravanan-ux Date: Tue, 17 Dec 2024 13:04:25 +0530 Subject: [PATCH 10/10] Update node.js.yml --- .github/workflows/node.js.yml | 112 ++++++++++++++-------------------- 1 file changed, 47 insertions(+), 65 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0d62e56..9509762 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,75 +1,57 @@ -name: Node.js CI +name: React CI/CD Workflow on: push: - branches: [ "master" ] + branches: + - master pull_request: - branches: [ "master" ] + branches: + - master jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16, 18] # Testing on multiple Node.js versions - steps: - - uses: actions/checkout@v4 # Checkout the repository - - - name: Set NODE_OPTIONS to allow OpenSSL legacy provider - run: echo "NODE_OPTIONS=--openssl-legacy-provider" >> $GITHUB_ENV # Fix for OpenSSL error - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' # Enable npm caching - - - name: Cache node_modules - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - run: npm ci # Install dependencies - - - run: npm run build --if-present # Build the project if there's a build script - - - run: npm test # Run tests - import ErrorBoundary from './ErrorBoundary'; -import App from './App'; - -function Root() { - return ( - - - - ); -} - -export default Root; - - - # Docker steps to build and push to Docker Hub - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build Docker image - run: | - docker build --cache-from=your-dockerhub-username/my-node-app:latest -t your-dockerhub-username/my-node-app:${{ github.sha }} . - - - name: Push Docker image to Docker Hub - run: | - docker push your-dockerhub-username/my-node-app:${{ github.sha }} - - # Optional: Tag the image with the "latest" tag - - name: Tag and Push Latest Docker Image - run: | - docker tag your-dockerhub-username/my-node-app:${{ github.sha }} your-dockerhub-username/my-node-app:latest - docker push your-dockerhub-username/my-node-app:latest + # Step 1: Checkout the code + - name: Checkout repository + uses: actions/checkout@v4 + + # Step 2: Set up Node.js + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 # Use Node.js 18 or the version your project requires + + # Step 3: Install dependencies + - name: Install dependencies + run: npm install + + # Step 4: Run tests + - name: Run tests + run: npm test + + # Step 5: Build the React application + - name: Build React app + run: npm run build + + # Step 6: Log in to Docker Hub + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + # Step 7: Build Docker image + - name: Build Docker image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/react-app:latest . + + # Step 8: Push Docker image to Docker Hub + - name: Push Docker image + run: | + docker push ${{ secrets.DOCKER_USERNAME }}/react-app:latest + + # Step 9: List Docker images + - name: List Docker images + run: docker images