From a2e2ba36f04cf5b869c650e581cdd35f5f36ddbc Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Sun, 24 Nov 2024 20:25:55 +0530 Subject: [PATCH 01/11] 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 2de27af..be16380 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,8 +15,8 @@ jobs: - name: Create .env file run: | - echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env + echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env echo PORT=${{ vars.PORT }} >> .env - name: List files in directory (debugging step) From 2e93036972992de399cd21c9f136bb89a1faf1ce Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Sun, 24 Nov 2024 20:28:11 +0530 Subject: [PATCH 02/11] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7c2460c..43c6103 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,10 +69,10 @@ USER node COPY . . #copy the .env file to workdir -COPY .env . +#COPY .env . # Expose the port that the application listens on. EXPOSE 9005 # Run the application. -CMD ["node", "index.js"] \ No newline at end of file +CMD ["node", "index.js"] From 7b3f0ba4a8f8ace53eb169aea859a716fc79093d Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Sun, 24 Nov 2024 20:39:05 +0530 Subject: [PATCH 03/11] Update main.yml --- .github/workflows/main.yml | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index be16380..3e804e5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,20 +13,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Create .env file - run: | - echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env - echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env - echo PORT=${{ vars.PORT }} >> .env - - - name: List files in directory (debugging step) - run: ls -la - - - name: Display .env file contents - run: cat .env - - name: Build Docker image - run: docker build -t kingitsolutionsteam/nawwa-test:${{ github.sha }} . + run: docker build \ + --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \ + --build-arg MONGO_URI=${{ secrets.MONGO_URI }} \ + --build-arg PORT=${{ vars.PORT }} \ + -t kingitsolutionsteam/nawwa-test:${{ github.sha }} . - name: Log in to Docker Hub uses: docker/login-action@v2 @@ -37,12 +29,10 @@ jobs: - name: Push Docker image to Docker Hub run: docker push kingitsolutionsteam/nawwa-test:${{ github.sha }} - deploy: runs-on: nawwa-runner - needs: build-and-push + needs: build-and-push steps: - - name: Log in to Docker Hub uses: docker/login-action@v2 with: @@ -51,9 +41,6 @@ jobs: - name: Pull Docker image run: sudo docker pull kingitsolutionsteam/nawwa-test:${{ github.sha }} - - - name: Deploy Docker image - run: | - sudo docker run -d -p ${{ vars.PORT }}:9005 kingitsolutionsteam/nawwa-test:${{ github.sha }} - + - name: Deploy Docker image + run: sudo docker run -d -p ${{ vars.PORT }}:9005 kingitsolutionsteam/nawwa-test:${{ github.sha }} From 3075f1423ba1628d04dc892de846b4745f0c9d1e Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Sun, 24 Nov 2024 23:50:44 +0530 Subject: [PATCH 04/11] Update Dockerfile --- Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Dockerfile b/Dockerfile index 43c6103..a7c505a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,16 @@ FROM node:${NODE_VERSION}-alpine # Use production node environment by default. ENV NODE_ENV=production +# Define build arguments +ARG JWT_SECRET +ARG MONGO_URI +ARG PORT + +# Set environment variables +ENV JWT_SECRET=$JWT_SECRET +ENV MONGO_URI=$MONGO_URI +ENV PORT=$PORT + WORKDIR /usr/src/app # Download dependencies as a separate step to take advantage of Docker's caching. From a230ccb7334756e257eb188c5fcb875454633068 Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Sun, 24 Nov 2024 23:55:36 +0530 Subject: [PATCH 05/11] Update Dockerfile --- Dockerfile | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7c505a..43a84de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,3 @@ -# # syntax=docker/dockerfile:1 - -# # Comments are provided throughout this file to help you get started. -# # If you need more help, visit the Dockerfile reference guide at -# # https://docs.docker.com/go/dockerfile-reference/ - -# # Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 - -# ARG NODE_VERSION=22.11.0 - -# FROM node:${NODE_VERSION}-alpine - -# # Use production node environment by default. -# ENV NODE_ENV production -# ENV key=value - -# WORKDIR /usr/src/app - -# # Download dependencies as a separate step to take advantage of Docker's caching. -# # Leverage a cache mount to /root/.npm to speed up subsequent builds. -# # Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into -# # into this layer. -# RUN --mount=type=bind,source=package.json,target=package.json \ -# --mount=type=bind,source=package-lock.json,target=package-lock.json \ -# --mount=type=cache,target=/root/.npm \ -# npm ci --omit=dev - -# # Run the application as a non-root user. -# USER node - -# # Copy the rest of the source files into the image. -# COPY . . - -# #copy the .env file to workdir -# COPY .env . - - -# # Expose the port that the application listens on. -# EXPOSE 9005 - -# # Run the application. -# CMD ["node", "index.js"] - - -# syntax=docker/dockerfile:1 - ARG NODE_VERSION=22.11.0 FROM node:${NODE_VERSION}-alpine @@ -83,6 +37,3 @@ COPY . . # Expose the port that the application listens on. EXPOSE 9005 - -# Run the application. -CMD ["node", "index.js"] From 27b46d8626162841a905497fd58cd64998572709 Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Sun, 24 Nov 2024 23:56:40 +0530 Subject: [PATCH 06/11] Update main.yml From 630bda5a2c37fb3d6d5a0784058f4bbbc2fffe8e Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Mon, 25 Nov 2024 00:00:38 +0530 Subject: [PATCH 07/11] 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 3e804e5..5b673b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v2 - name: Build Docker image - run: docker build \ + run: docker buildx build \ --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \ --build-arg MONGO_URI=${{ secrets.MONGO_URI }} \ --build-arg PORT=${{ vars.PORT }} \ From c219e1d4d8be683af3b486298159407b2d06ef1c Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Mon, 25 Nov 2024 09:42:56 +0530 Subject: [PATCH 08/11] Update Dockerfile --- Dockerfile | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 43a84de..e076961 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,16 +5,6 @@ FROM node:${NODE_VERSION}-alpine # Use production node environment by default. ENV NODE_ENV=production -# Define build arguments -ARG JWT_SECRET -ARG MONGO_URI -ARG PORT - -# Set environment variables -ENV JWT_SECRET=$JWT_SECRET -ENV MONGO_URI=$MONGO_URI -ENV PORT=$PORT - WORKDIR /usr/src/app # Download dependencies as a separate step to take advantage of Docker's caching. @@ -32,8 +22,9 @@ USER node # Copy the rest of the source files into the image. COPY . . -#copy the .env file to workdir -#COPY .env . - # Expose the port that the application listens on. EXPOSE 9005 + +# Run the application +CMD ["node", "index.js"] + From d12cb1f488a91bc26d8986c0404611b627697e61 Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Mon, 25 Nov 2024 09:44:39 +0530 Subject: [PATCH 09/11] Update main.yml --- .github/workflows/main.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5b673b4..1c810af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,11 +14,7 @@ jobs: uses: actions/checkout@v2 - name: Build Docker image - run: docker buildx build \ - --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \ - --build-arg MONGO_URI=${{ secrets.MONGO_URI }} \ - --build-arg PORT=${{ vars.PORT }} \ - -t kingitsolutionsteam/nawwa-test:${{ github.sha }} . + run: docker build -t kingitsolutionsteam/nawwa-test:${{ github.sha }} . - name: Log in to Docker Hub uses: docker/login-action@v2 From c107d91328bba0756845f79e261dc64f356712de Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Mon, 25 Nov 2024 09:48:54 +0530 Subject: [PATCH 10/11] Update main.yml --- .github/workflows/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c810af..4db2dfe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,6 +13,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Show project directory + run: ls -al + + - name: Show .env file contents + run: cat .env + - name: Build Docker image run: docker build -t kingitsolutionsteam/nawwa-test:${{ github.sha }} . From d0952fe50e95ac329dd2abcb91f6b18310ea7889 Mon Sep 17 00:00:00 2001 From: tharaka911 Date: Mon, 25 Nov 2024 09:50:51 +0530 Subject: [PATCH 11/11] Update main.yml --- .github/workflows/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4db2dfe..d5a830b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,6 +13,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Create .env file + run: | + echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env + echo MONGO_URI=${{ secrets.MONGO_URI }} >> .env + echo PORT=${{ vars.PORT }} >> .env + - name: Show project directory run: ls -al