From 5cbeca2f1e901101e291799a37ec00f02f651fed Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:42:52 +0530 Subject: [PATCH 1/8] Create Dockerfile --- Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7bc65fd9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:16.20.1 +WORKDIR /app +COPY package.json ./ +RUN npm install +COPY . . +EXPOSE 5000 +CMD ["npm","run","start"] From a010d6458e8ab38ceb43f3afca4658270dc7305c Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Thu, 9 Jan 2025 19:05:40 +0530 Subject: [PATCH 2/8] Update main.yml --- .github/workflows/main.yml | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f0545784..774a406d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,19 +2,28 @@ name: CICD on: push: - branches: [main,master] - + branches: [cicd-docker-ec2] + jobs: build: runs-on: [ubuntu-latest] steps: - - name: Checkout Source + - name: Checkout source uses: actions/checkout@v3 - - name: Set Node.js 16.x - uses: actions/setup-node@v3 - with: - node-version: 16.x - - name: Install Dependencies - run : npm install - - name: Test Project - run: npm test + - name: Login to docker hub + run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + - name: Build docker image + run: docker build -t integrationninjas/nodejs-app . + - name: Publish image to docker hub + run: docker push integrationninjas/nodejs-app:latest + + deploy: + needs: build + runs-on: [aws-ec2] + steps: + - name: Pull image from docker hub + run: docker pull integrationninjas/nodejs-app:latest + - name: Delete old container + run: docker rm -f nodejs-app-container + - name: Run docker container + run: docker run -d -p 5000:5000 --name nodejs-app-container integrationninjas/nodejs-app From d70893569b60a87e4cf090eac4edbfaaeec9c03c Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Thu, 9 Jan 2025 19:07:06 +0530 Subject: [PATCH 3/8] Update main.yml From 7afc8e346e22f61e63766d89fdbf3b4d5672d990 Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:06:41 +0530 Subject: [PATCH 4/8] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 774a406d..fa9528ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: deploy: needs: build - runs-on: [aws-ec2] + runs-on: [runner-ec2] steps: - name: Pull image from docker hub run: docker pull integrationninjas/nodejs-app:latest From 4c3b7ab487dcc46a6b89c54171fb88d52fd5c159 Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:43:30 +0530 Subject: [PATCH 5/8] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa9528ac..cbdcc7db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: CICD +name: CICD-PIPELINE on: push: From df0a66c03fb0ec1cb1f5ffe99de864f5c580dd1c Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:45:34 +0530 Subject: [PATCH 6/8] Delete .github/workflows/main.yml --- .github/workflows/main.yml | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index cbdcc7db..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: CICD-PIPELINE - -on: - push: - branches: [cicd-docker-ec2] - -jobs: - build: - runs-on: [ubuntu-latest] - steps: - - name: Checkout source - uses: actions/checkout@v3 - - name: Login to docker hub - run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - - name: Build docker image - run: docker build -t integrationninjas/nodejs-app . - - name: Publish image to docker hub - run: docker push integrationninjas/nodejs-app:latest - - deploy: - needs: build - runs-on: [runner-ec2] - steps: - - name: Pull image from docker hub - run: docker pull integrationninjas/nodejs-app:latest - - name: Delete old container - run: docker rm -f nodejs-app-container - - name: Run docker container - run: docker run -d -p 5000:5000 --name nodejs-app-container integrationninjas/nodejs-app From 0cc293785cf43ac3ad7f5cb3327338bcdae1448e Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:46:41 +0530 Subject: [PATCH 7/8] Create main.yml --- .github/workflows/main.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..cbdcc7db --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: CICD-PIPELINE + +on: + push: + branches: [cicd-docker-ec2] + +jobs: + build: + runs-on: [ubuntu-latest] + steps: + - name: Checkout source + uses: actions/checkout@v3 + - name: Login to docker hub + run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + - name: Build docker image + run: docker build -t integrationninjas/nodejs-app . + - name: Publish image to docker hub + run: docker push integrationninjas/nodejs-app:latest + + deploy: + needs: build + runs-on: [runner-ec2] + steps: + - name: Pull image from docker hub + run: docker pull integrationninjas/nodejs-app:latest + - name: Delete old container + run: docker rm -f nodejs-app-container + - name: Run docker container + run: docker run -d -p 5000:5000 --name nodejs-app-container integrationninjas/nodejs-app From 951e202e450daee0b7f624cd302d97d4437c522f Mon Sep 17 00:00:00 2001 From: maheshlawnekar <53034901+maheshlawnekar@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:18:19 +0530 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00aeaf62..125ba7ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Nodejs app with rest and graphql example -An example of GraphQL queries/mutations with Node and Express js. +An example of GraphQL queries/mutations with Node and Expressjs With GraphQL, clients can specify exactly what data they need, and the server responds with only that data, reducing the amount of data transferred over the network.