From 65040d324380057dd7706504b61b1d06d1099ed4 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 21:57:45 +0700 Subject: [PATCH 01/24] create pull request --- .github/workflows/create-pull-request.yml | 23 +++++++++++++++++++++++ .github/workflows/main.yaml | 10 +++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/create-pull-request.yml diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml new file mode 100644 index 0000000..e1d6b00 --- /dev/null +++ b/.github/workflows/create-pull-request.yml @@ -0,0 +1,23 @@ +name: Create Pull Request from dev to test + +on: + push: + branches: + - dev + +jobs: + create-pull-request: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.MY_GITHUB_TOKEN }} + base: test + head: dev + title: "Sync dev to test" + body: "This is an automated pull request to sync changes from dev to test." + draft: false diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index cff8d58..616f19e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -26,8 +26,8 @@ jobs: - name: Unit Tests run: mvn -B test --file pom.xml - build-image: - needs: testing - uses: ./.github/workflows/build-image.yaml - secrets: - DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + # build-image: + # needs: testing + # uses: ./.github/workflows/build-image.yaml + # secrets: + # DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} From fc95cb39d4addee23d63bd9b0d610a6f30391d56 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 21:59:44 +0700 Subject: [PATCH 02/24] create pull request 2 --- .github/workflows/create-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index e1d6b00..47e8929 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create Pull Request uses: peter-evans/create-pull-request@v6 From 0c9864178c04acab6e39e2937d2c1b3dbb57a143 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:03:14 +0700 Subject: [PATCH 03/24] create pull request 3 --- .github/workflows/main.yaml | 52 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 616f19e..938f2ac 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,33 +1,33 @@ -name: Continuous Integration for Comment Service +# name: Continuous Integration for Comment Service -on: - push: - branches: - - dev +# on: +# push: +# branches: +# - dev -jobs: - testing: - name: Testing Comment Service - runs-on: ubuntu-latest - steps: +# jobs: +# testing: +# name: Testing Comment Service +# runs-on: ubuntu-latest +# steps: - - name: Checkout code - uses: actions/checkout@v3 +# - name: Checkout code +# uses: actions/checkout@v3 - - name: Setup JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: 17 +# - name: Setup JDK 17 +# uses: actions/setup-java@v3 +# with: +# distribution: 'corretto' +# java-version: 17 - - name: Set up MongoDB URI - run: echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/user-service" >> $GITHUB_ENV +# - name: Set up MongoDB URI +# run: echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/user-service" >> $GITHUB_ENV - - name: Unit Tests - run: mvn -B test --file pom.xml +# - name: Unit Tests +# run: mvn -B test --file pom.xml - # build-image: - # needs: testing - # uses: ./.github/workflows/build-image.yaml - # secrets: - # DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} +# # build-image: +# # needs: testing +# # uses: ./.github/workflows/build-image.yaml +# # secrets: +# # DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} From 1dfc7363d71443ee9fa72b6784ee0b538b87a929 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:06:48 +0700 Subject: [PATCH 04/24] create pull request --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 938f2ac..e922ec3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,4 +1,4 @@ -# name: Continuous Integration for Comment Service +# name: Dev Stage for Comment Service # on: # push: From 1c4f08d02ec4bdf71ddb24335f1365579317fe29 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:27:48 +0700 Subject: [PATCH 05/24] create example pull request --- .github/workflows/create-pull-request.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index 47e8929..92e5030 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -12,6 +12,9 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: extract git commit data + uses: rlespinasse/git-commit-data-action@v1.x + - name: Create Pull Request uses: peter-evans/create-pull-request@v6 with: @@ -20,4 +23,3 @@ jobs: head: dev title: "Sync dev to test" body: "This is an automated pull request to sync changes from dev to test." - draft: false From 666ba2ce7b301ff206490f2b5d26e0abb3baee54 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:28:40 +0700 Subject: [PATCH 06/24] create example pull request --- .../com/programming/userService/controller/UserController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/programming/userService/controller/UserController.java b/src/main/java/com/programming/userService/controller/UserController.java index 3ccf6d0..7abc97f 100644 --- a/src/main/java/com/programming/userService/controller/UserController.java +++ b/src/main/java/com/programming/userService/controller/UserController.java @@ -43,7 +43,8 @@ public class UserController { public String getServiceName(){ return "User Service"; } - private final AuthUserRepository userRepository; + + private final AuthUserRepository userRepository; private final PasswordEncoder passwordEncoder; @Autowired private JavaMailSender javaMailSender; From e5401aaedf076205cc07ce272436689bfcec896d Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:31:00 +0700 Subject: [PATCH 07/24] create example pull request --- .github/workflows/create-pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index 92e5030..cc6316b 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -23,3 +23,4 @@ jobs: head: dev title: "Sync dev to test" body: "This is an automated pull request to sync changes from dev to test." + delete-branch: true From 4c2236b4c9f4a51952506543a7d3a66bca785555 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:46:21 +0700 Subject: [PATCH 08/24] create example pull request --- .github/workflows/create-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index cc6316b..34e301f 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -23,4 +23,4 @@ jobs: head: dev title: "Sync dev to test" body: "This is an automated pull request to sync changes from dev to test." - delete-branch: true + delete-branch: true \ No newline at end of file From 32d577c8b1ab134420a803102b947351d847b528 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 22:58:22 +0700 Subject: [PATCH 09/24] chnage dev --- .github/workflows/create-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index 34e301f..a43d950 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -23,4 +23,4 @@ jobs: head: dev title: "Sync dev to test" body: "This is an automated pull request to sync changes from dev to test." - delete-branch: true \ No newline at end of file + delete-branch: false \ No newline at end of file From 2219d6e0439ec21257804409c13268f67d057b10 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 23:00:44 +0700 Subject: [PATCH 10/24] create pull request --- .github/workflows/create-pull-request.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml index a43d950..68a7170 100644 --- a/.github/workflows/create-pull-request.yml +++ b/.github/workflows/create-pull-request.yml @@ -10,9 +10,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v3 - - name: extract git commit data + - name: Extract git commit data uses: rlespinasse/git-commit-data-action@v1.x - name: Create Pull Request @@ -20,7 +20,7 @@ jobs: with: token: ${{ secrets.MY_GITHUB_TOKEN }} base: test - head: dev + branch: dev title: "Sync dev to test" body: "This is an automated pull request to sync changes from dev to test." - delete-branch: false \ No newline at end of file + delete-branch: false From 826a6ab4b4dff190fcceb12e267566a501f9b4d6 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 23:07:07 +0700 Subject: [PATCH 11/24] dev --- .../programming/userService/controller/UserController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/programming/userService/controller/UserController.java b/src/main/java/com/programming/userService/controller/UserController.java index 7abc97f..745206b 100644 --- a/src/main/java/com/programming/userService/controller/UserController.java +++ b/src/main/java/com/programming/userService/controller/UserController.java @@ -43,6 +43,10 @@ public class UserController { public String getServiceName(){ return "User Service"; } + @GetMapping("/test") + public String getTest(){ + return "Test User Service"; + } private final AuthUserRepository userRepository; private final PasswordEncoder passwordEncoder; From 2b86039232185e5350cf8af7e0a8bd8010519a17 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 23:12:42 +0700 Subject: [PATCH 12/24] create pull request --- .github/workflows/main.yaml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f773916..ed80c6c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,18 +1,9 @@ -<<<<<<< HEAD # name: Dev Stage for Comment Service # on: # push: # branches: # - dev -======= -name: Test Stage for Comment Service - -on: - push: - branches: - - test ->>>>>>> 617e5c168880e2901d6a17c5029940509920a8f8 # jobs: # testing: @@ -35,16 +26,8 @@ on: # - name: Unit Tests # run: mvn -B test --file pom.xml -<<<<<<< HEAD -# # build-image: -# # needs: testing -# # uses: ./.github/workflows/build-image.yaml -# # secrets: -# # DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} -======= # build-image: # needs: testing # uses: ./.github/workflows/build-image.yaml # secrets: # DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} ->>>>>>> 617e5c168880e2901d6a17c5029940509920a8f8 From 62596a386e8432ac73d07a1ac20af17837464bd2 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 23:14:53 +0700 Subject: [PATCH 13/24] create pull request --- .../programming/userService/controller/UserController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/programming/userService/controller/UserController.java b/src/main/java/com/programming/userService/controller/UserController.java index 745206b..cee9eae 100644 --- a/src/main/java/com/programming/userService/controller/UserController.java +++ b/src/main/java/com/programming/userService/controller/UserController.java @@ -43,10 +43,7 @@ public class UserController { public String getServiceName(){ return "User Service"; } - @GetMapping("/test") - public String getTest(){ - return "Test User Service"; - } + private final AuthUserRepository userRepository; private final PasswordEncoder passwordEncoder; From b2e6275d285ce0070694e8048b486b992e02be8a Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Wed, 19 Jun 2024 23:18:16 +0700 Subject: [PATCH 14/24] dev --- .github/workflows/create-pull-request.yml | 26 ------------ .github/workflows/main.yaml | 52 +++++++++++------------ 2 files changed, 26 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/create-pull-request.yml diff --git a/.github/workflows/create-pull-request.yml b/.github/workflows/create-pull-request.yml deleted file mode 100644 index 68a7170..0000000 --- a/.github/workflows/create-pull-request.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Create Pull Request from dev to test - -on: - push: - branches: - - dev - -jobs: - create-pull-request: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Extract git commit data - uses: rlespinasse/git-commit-data-action@v1.x - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.MY_GITHUB_TOKEN }} - base: test - branch: dev - title: "Sync dev to test" - body: "This is an automated pull request to sync changes from dev to test." - delete-branch: false diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index ed80c6c..acb295f 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,33 +1,33 @@ -# name: Dev Stage for Comment Service +name: Dev Stage for Comment Service -# on: -# push: -# branches: -# - dev +on: + push: + branches: + - dev -# jobs: -# testing: -# name: Testing Comment Service -# runs-on: ubuntu-latest -# steps: +jobs: + testing: + name: Testing Comment Service + runs-on: ubuntu-latest + steps: -# - name: Checkout code -# uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 -# - name: Setup JDK 17 -# uses: actions/setup-java@v3 -# with: -# distribution: 'corretto' -# java-version: 17 + - name: Setup JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: 17 -# - name: Set up MongoDB URI -# run: echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/user-service" >> $GITHUB_ENV + - name: Set up MongoDB URI + run: echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/user-service" >> $GITHUB_ENV -# - name: Unit Tests -# run: mvn -B test --file pom.xml + - name: Unit Tests + run: mvn -B test --file pom.xml - # build-image: - # needs: testing - # uses: ./.github/workflows/build-image.yaml - # secrets: - # DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + build-image: + needs: testing + uses: ./.github/workflows/build-image.yaml + secrets: + DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} From 1722595972bd8fe66fbbb0715086bd08dc3bc575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:11:26 +0700 Subject: [PATCH 15/24] Demo dev stage commit --- .github/workflows/main.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index acb295f..57360d8 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -31,3 +31,4 @@ jobs: uses: ./.github/workflows/build-image.yaml secrets: DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} +### \ No newline at end of file From 804b0fe715c4c68e8f2d05b1f408e6e83ec70bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:04:36 +0700 Subject: [PATCH 16/24] Demo ArgoCD auto synchronized --- src/test/java/TestUserService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/TestUserService.java b/src/test/java/TestUserService.java index edff7ed..042a686 100644 --- a/src/test/java/TestUserService.java +++ b/src/test/java/TestUserService.java @@ -17,3 +17,4 @@ public void testGetServiceName() throws Exception { .andExpect(status().isOk()); } } +///// From f1c523f32c5af511a1a12c6ad20dc65c555179b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:25:53 +0700 Subject: [PATCH 17/24] Dev stage --- .github/workflows/SonarQube.yaml | 2 +- .github/workflows/main.yaml | 4 ++-- .github/workflows/notifyCI.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/SonarQube.yaml b/.github/workflows/SonarQube.yaml index 16dd20d..2bc5e27 100644 --- a/.github/workflows/SonarQube.yaml +++ b/.github/workflows/SonarQube.yaml @@ -1,4 +1,4 @@ -name: SonarCloud scan for User Services (Test Stage) +name: SonarCloud scan for User Services on: workflow_call: secrets: diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 3bb8e2d..c1619cf 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,4 +1,4 @@ -name: Dev Stage for Comment Service +name: Dev Stage for User Service on: push: @@ -7,7 +7,7 @@ on: jobs: testing: - name: Testing Comment Service + name: Testing User Service runs-on: ubuntu-latest steps: diff --git a/.github/workflows/notifyCI.yaml b/.github/workflows/notifyCI.yaml index 2dc3428..2b7db47 100644 --- a/.github/workflows/notifyCI.yaml +++ b/.github/workflows/notifyCI.yaml @@ -1,4 +1,4 @@ -name: Send Slack Notification for User Service (Test Stage) +name: Send Slack Notification for User Service on: workflow_call: From 81dc025b57df13c417218969c29a6f6860041f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:33:46 +0700 Subject: [PATCH 18/24] Dev Stage --- .github/workflows/SonarQube.yaml | 35 ---------------------- .github/workflows/build-image.yaml | 37 +++++++++++++++++++++++ .github/workflows/main.yaml | 13 +++------ .github/workflows/scan-image.yaml | 47 ------------------------------ 4 files changed, 41 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/SonarQube.yaml create mode 100644 .github/workflows/build-image.yaml delete mode 100644 .github/workflows/scan-image.yaml diff --git a/.github/workflows/SonarQube.yaml b/.github/workflows/SonarQube.yaml deleted file mode 100644 index 2bc5e27..0000000 --- a/.github/workflows/SonarQube.yaml +++ /dev/null @@ -1,35 +0,0 @@ -name: SonarCloud scan for User Services -on: - workflow_call: - secrets: - SONAR_TOKEN: - required: true -jobs: - sonar-cloud-scan: - name: Build and analyze - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'zulu' # Alternative distribution options are available. - - name: Cache SonarCloud packages - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - name: Build and analyze - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=DevOps-Video-Sharing_UserService \ No newline at end of file diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 0000000..9fd2079 --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -0,0 +1,37 @@ +name: Build Image User Service + +on: + workflow_call: + secrets: + DOCKER_HUB_ACCESS_TOKEN: + required: true + +jobs: + build-image: + name: Build and Push Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: 17 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: datuits + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build the application + run: | + mvn clean + mvn -B package --file pom.xml + + - name: Build and Push the docker image + run: | + docker build -t datuits/devops-user-service:latest . + docker push datuits/devops-user-service:latest \ No newline at end of file diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c1619cf..fc05942 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -26,19 +26,14 @@ jobs: - name: Unit Tests run: mvn -B test --file pom.xml - - sonar-cloud-scan: + build-image: needs: testing - uses: ./.github/workflows/SonarQube.yaml + uses: ./.github/workflow/build-image.yaml secrets: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - scan-image: - needs: sonar-cloud-scan - uses: ./.github/workflows/scan-image.yaml + DOCKER_HUB_ACCESS_TOKEN: true notify: - needs: scan-image + needs: build-image uses: ./.github/workflows/notifyCI.yaml secrets: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/scan-image.yaml b/.github/workflows/scan-image.yaml deleted file mode 100644 index d366468..0000000 --- a/.github/workflows/scan-image.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Scan Image User Service (Test Stage) -on: - workflow_call: - -jobs: - scan-image: - name: Security Scan - runs-on: ubuntu-latest - steps: - - name: Install Trivy - run: | - sudo apt-get update - sudo apt-get install -y wget - wget https://github.com/aquasecurity/trivy/releases/download/v0.40.0/trivy_0.40.0_Linux-64bit.deb - sudo dpkg -i trivy_0.40.0_Linux-64bit.deb - - - name: Scan Docker image with Trivy - id: scan-image - run: | - trivy image --format json --output scan-results.json datuits/devops-user-service:latest - - - name: Extract high and critical vulnerabilities - id: extract_vulnerabilities - run: | - jq -r ' - def hr(severity): - if severity == "HIGH" or severity == "CRITICAL" then true else false end; - def to_md: - "| " + (.VulnerabilityID // "") + " | " + (.PkgName // "") + " | " + (.InstalledVersion // "") + " | " + (.Severity // "") + " | " + (.Title // "") + " |"; - [ - "# Docker Image Scan Results", - "", - "## High and Critical Vulnerabilities", - "", - "| Vulnerability ID | Package | Version | Severity | Description |", - "|------------------|---------|---------|----------|-------------|", - (.Results[] | .Vulnerabilities[] | select(hr(.Severity)) | to_md), - "" - ] | join("\n") - ' scan-results.json > vulnerability-report.md - - - name: Upload vulnerability report - uses: actions/upload-artifact@v2 - with: - name: vulnerability-report - path: vulnerability-report.md - \ No newline at end of file From 9d7c461eb3d59544469eeb72e2872fa45673159d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:34:46 +0700 Subject: [PATCH 19/24] Dev Stage --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index fc05942..8ac704c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -28,7 +28,7 @@ jobs: build-image: needs: testing - uses: ./.github/workflow/build-image.yaml + uses: ./.github/workflows/build-image.yaml secrets: DOCKER_HUB_ACCESS_TOKEN: true From 5d0f80f326c7128026b5ad7bf71293c1b48946b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:40:17 +0700 Subject: [PATCH 20/24] Dev stage --- .github/workflows/main.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8ac704c..b8ccc72 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -37,3 +37,4 @@ jobs: uses: ./.github/workflows/notifyCI.yaml secrets: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} +###Testing Build### From 3529a334497c05367cfa451f09512bd87c118975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:42:17 +0700 Subject: [PATCH 21/24] Dev stage --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index b8ccc72..15a2c75 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -30,7 +30,7 @@ jobs: needs: testing uses: ./.github/workflows/build-image.yaml secrets: - DOCKER_HUB_ACCESS_TOKEN: true + DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} notify: needs: build-image From e6c09f2ad74a4512a8dd47bf17e8129ff112c608 Mon Sep 17 00:00:00 2001 From: Trinh-Tan-Dat <21520714@gm.uit.edu.vn> Date: Thu, 29 Aug 2024 04:58:48 +0000 Subject: [PATCH 22/24] test --- .github/workflows/deploymentCD.yaml | 58 +++++++++++++++++++++++++++++ .github/workflows/notifyCD.yaml | 36 ++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .github/workflows/deploymentCD.yaml create mode 100644 .github/workflows/notifyCD.yaml diff --git a/.github/workflows/deploymentCD.yaml b/.github/workflows/deploymentCD.yaml new file mode 100644 index 0000000..8f2fa89 --- /dev/null +++ b/.github/workflows/deploymentCD.yaml @@ -0,0 +1,58 @@ +# name: Continuous Deployment for User Service + +# on: +# workflow_run: +# workflows: ["Continuous Integration for Comment Service"] +# types: +# - completed + +# env: +# PROJECT_ID: gke-project-423206 +# CLUSTER_NAME: autopilot-cluster-1 +# ZONE: us-central1 + +# jobs: +# deploy: +# name: Deploy to GKE Autopilot +# runs-on: ubuntu-latest +# steps: +# - name: Checkout code +# uses: actions/checkout@v3 + +# - name: Setup JDK 17 +# uses: actions/setup-java@v3 +# with: +# distribution: 'corretto' +# java-version: 17 + +# - name: Build the application +# run: | +# mvn clean +# mvn -B package --file pom.xml + +# - name: Authenticate +# uses: google-github-actions/auth@v2 +# with: +# credentials_json: ${{ secrets.GCP_SA_KEY }} + +# - name: Configure gcloud +# uses: google-github-actions/setup-gcloud@v2 +# with: +# project_id: ${{ env.PROJECT_ID }} +# install_components: 'gke-gcloud-auth-plugin' + +# - name: Set cluster context +# run: | +# gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.ZONE }} --project ${{ env.PROJECT_ID }} + +# - name: Apply Kubernetes manifests +# run: | +# kubectl apply -f resources.yaml + +# notifications: +# needs: deploy +# uses: ./.github/workflows/notifyCD.yaml +# secrets: +# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL}} + +# ###Demo### \ No newline at end of file diff --git a/.github/workflows/notifyCD.yaml b/.github/workflows/notifyCD.yaml new file mode 100644 index 0000000..06777cc --- /dev/null +++ b/.github/workflows/notifyCD.yaml @@ -0,0 +1,36 @@ +# name: Send Slack Notification for User Service + +# on: +# workflow_call: +# secrets: +# SLACK_WEBHOOK_URL: +# required: true + +# jobs: +# success_notifier: +# if: success() +# runs-on: ubuntu-latest +# steps: +# - name: Send success notification on Slack +# uses: slackapi/slack-github-action@v1.24.0 +# with: +# payload: | +# { +# "text": "The Continuous Deployment for User Service workflow has completed successfully." +# } +# env: +# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + +# failure_notifier: +# if: failure() +# runs-on: ubuntu-latest +# steps: +# - name: Send failure notification on Slack +# uses: slackapi/slack-github-action@v1.24.0 +# with: +# payload: | +# { +# "text": "The Continuous Deployment for User Service workflow has failed." +# } +# env: +# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file From 85562c73ff75c661ab69ccc416b89e2beff7aacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:35:47 +0700 Subject: [PATCH 23/24] ELK first test --- pom.xml | 6 +++++- .../userService/controller/UserController.java | 8 ++++++++ src/main/resources/application.properties | 3 +++ src/main/resources/logback-spring.xml | 11 +++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/logback-spring.xml diff --git a/pom.xml b/pom.xml index c90ca06..c450841 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,11 @@ 2.10.1 - + + net.logstash.logback + logstash-logback-encoder + 7.0.1 + diff --git a/src/main/java/com/programming/userService/controller/UserController.java b/src/main/java/com/programming/userService/controller/UserController.java index cee9eae..00abca5 100644 --- a/src/main/java/com/programming/userService/controller/UserController.java +++ b/src/main/java/com/programming/userService/controller/UserController.java @@ -33,14 +33,22 @@ import java.util.Map; import java.util.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; @RestController @AllArgsConstructor @RequestMapping("/user") public class UserController { + private static final Logger logger = LoggerFactory.getLogger(UserController.class); + @GetMapping("/") public String getServiceName(){ + //ELK + MDC.put("type", "userservice"); + logger.info("User Service Start"); return "User Service"; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 091832f..d9a056f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,3 +18,6 @@ spring.mail.username=21520714@gm.uit.edu.vn spring.mail.password=vkux umrv rtkd svsy spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true + +# logstash +logging.config=classpath:logback-spring.xml \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..6b0ebf7 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,11 @@ + + + 192.168.120.213:5050 + + + + + + + + \ No newline at end of file From 8f7619db10823caad31200b2a3b75ea704550b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?= <146197243+DucBaoUIT@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:26:23 +0700 Subject: [PATCH 24/24] Update CI and ELK image --- .github/workflows/deploymentCD.yaml | 116 +++++++++--------- .github/workflows/main.yaml | 10 +- .github/workflows/notifyCD.yaml | 66 +++++----- .../controller/UserController.java | 15 ++- 4 files changed, 110 insertions(+), 97 deletions(-) diff --git a/.github/workflows/deploymentCD.yaml b/.github/workflows/deploymentCD.yaml index 8f2fa89..3dac504 100644 --- a/.github/workflows/deploymentCD.yaml +++ b/.github/workflows/deploymentCD.yaml @@ -1,58 +1,58 @@ -# name: Continuous Deployment for User Service - -# on: -# workflow_run: -# workflows: ["Continuous Integration for Comment Service"] -# types: -# - completed - -# env: -# PROJECT_ID: gke-project-423206 -# CLUSTER_NAME: autopilot-cluster-1 -# ZONE: us-central1 - -# jobs: -# deploy: -# name: Deploy to GKE Autopilot -# runs-on: ubuntu-latest -# steps: -# - name: Checkout code -# uses: actions/checkout@v3 - -# - name: Setup JDK 17 -# uses: actions/setup-java@v3 -# with: -# distribution: 'corretto' -# java-version: 17 - -# - name: Build the application -# run: | -# mvn clean -# mvn -B package --file pom.xml - -# - name: Authenticate -# uses: google-github-actions/auth@v2 -# with: -# credentials_json: ${{ secrets.GCP_SA_KEY }} - -# - name: Configure gcloud -# uses: google-github-actions/setup-gcloud@v2 -# with: -# project_id: ${{ env.PROJECT_ID }} -# install_components: 'gke-gcloud-auth-plugin' - -# - name: Set cluster context -# run: | -# gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.ZONE }} --project ${{ env.PROJECT_ID }} - -# - name: Apply Kubernetes manifests -# run: | -# kubectl apply -f resources.yaml - -# notifications: -# needs: deploy -# uses: ./.github/workflows/notifyCD.yaml -# secrets: -# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL}} - -# ###Demo### \ No newline at end of file +name: Continuous Deployment for User Service + +on: + workflow_run: + workflows: ["Continuous Integration for Comment Service"] + types: + - completed + +env: + PROJECT_ID: gke-project-423206 + CLUSTER_NAME: autopilot-cluster-1 + ZONE: us-central1 + +jobs: + deploy: + name: Deploy to GKE Autopilot + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: 17 + + - name: Build the application + run: | + mvn clean + mvn -B package --file pom.xml + + - name: Authenticate + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Configure gcloud + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: ${{ env.PROJECT_ID }} + install_components: 'gke-gcloud-auth-plugin' + + - name: Set cluster context + run: | + gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.ZONE }} --project ${{ env.PROJECT_ID }} + + - name: Apply Kubernetes manifests + run: | + kubectl apply -f resources.yaml + + notifications: + needs: deploy + uses: ./.github/workflows/notifyCD.yaml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL}} + +###Demo### \ No newline at end of file diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 15a2c75..e824872 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -32,9 +32,9 @@ jobs: secrets: DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - notify: - needs: build-image - uses: ./.github/workflows/notifyCI.yaml - secrets: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + # notify: + # needs: build-image + # uses: ./.github/workflows/notifyCI.yaml + # secrets: + # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} ###Testing Build### diff --git a/.github/workflows/notifyCD.yaml b/.github/workflows/notifyCD.yaml index 06777cc..20f2b28 100644 --- a/.github/workflows/notifyCD.yaml +++ b/.github/workflows/notifyCD.yaml @@ -1,36 +1,36 @@ -# name: Send Slack Notification for User Service +name: Send Slack Notification for User Service -# on: -# workflow_call: -# secrets: -# SLACK_WEBHOOK_URL: -# required: true +on: + workflow_call: + secrets: + SLACK_WEBHOOK_URL: + required: true -# jobs: -# success_notifier: -# if: success() -# runs-on: ubuntu-latest -# steps: -# - name: Send success notification on Slack -# uses: slackapi/slack-github-action@v1.24.0 -# with: -# payload: | -# { -# "text": "The Continuous Deployment for User Service workflow has completed successfully." -# } -# env: -# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} +jobs: + success_notifier: + if: success() + runs-on: ubuntu-latest + steps: + - name: Send success notification on Slack + uses: slackapi/slack-github-action@v1.24.0 + with: + payload: | + { + "text": "The Continuous Deployment for User Service workflow has completed successfully." + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} -# failure_notifier: -# if: failure() -# runs-on: ubuntu-latest -# steps: -# - name: Send failure notification on Slack -# uses: slackapi/slack-github-action@v1.24.0 -# with: -# payload: | -# { -# "text": "The Continuous Deployment for User Service workflow has failed." -# } -# env: -# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file + failure_notifier: + if: failure() + runs-on: ubuntu-latest + steps: + - name: Send failure notification on Slack + uses: slackapi/slack-github-action@v1.24.0 + with: + payload: | + { + "text": "The Continuous Deployment for User Service workflow has failed." + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/src/main/java/com/programming/userService/controller/UserController.java b/src/main/java/com/programming/userService/controller/UserController.java index 00abca5..054993f 100644 --- a/src/main/java/com/programming/userService/controller/UserController.java +++ b/src/main/java/com/programming/userService/controller/UserController.java @@ -97,6 +97,11 @@ public ResponseEntity registerUser(@RequestBody AuthUser user) { user.setTimestamp(new Date()); user.setAvatar(getDefaultAvatar()); AuthUser save = userRepository.save(user); + AuthUser userFromDb = userRepository.findByUsername(user.getUsername()) + .orElseThrow(() -> new Exception("User not found")); + MDC.put("type", "userservice"); + MDC.put("action", "register"); + logger.info("UserID: " + userFromDb.getId()); return ResponseEntity.ok(save); } catch (Exception e) { return ResponseEntity.internalServerError().body(e.getMessage()); @@ -116,6 +121,9 @@ public ResponseEntity loginUser(@RequestBody AuthUser user) { AuthUser userFromDb = userRepository.findByUsername(user.getUsername()) .orElseThrow(() -> new Exception("User not found")); if (passwordEncoder.matches(user.getPassword(), userFromDb.getPassword())) { + MDC.put("type", "userservice"); + MDC.put("action", "login"); + logger.info("UserID: " + userFromDb.getId()); return ResponseEntity.ok(userFromDb); } else { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Invalid credentials"); @@ -173,6 +181,9 @@ public ResponseEntity updateProfile(@PathVariable("id") String id, @RequestBody userFromDb.setFirstName(user.getFirstName()); userFromDb.setLastName(user.getLastName()); AuthUser save = userRepository.save(userFromDb); + MDC.put("type", "userservice"); + MDC.put("action", "update-profile"); + logger.info("UserID: " + userFromDb.getId()); return ResponseEntity.ok(HttpStatus.OK); } catch (Exception e) { @@ -194,7 +205,9 @@ public ResponseEntity changePassword(@PathVariable("id") String id, userFromDb.setPassword(passwordEncoder.encode(changePasswordRequest.getNewPassword())); AuthUser save = userRepository.save(userFromDb); - + MDC.put("type", "userservice"); + MDC.put("action", "change-password"); + logger.info("UserID: " + userFromDb.getId()); return ResponseEntity.ok("Password changed successfully"); } catch (Exception e) { return ResponseEntity.internalServerError().body(e.getMessage());