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/deploymentCD.yaml b/.github/workflows/deploymentCD.yaml deleted file mode 100644 index 4d59425..0000000 --- a/.github/workflows/deploymentCD.yaml +++ /dev/null @@ -1,56 +0,0 @@ -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}} \ No newline at end of file diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 551f244..97c0be1 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -3,14 +3,13 @@ name: Continuous Integration for Comment Service on: push: branches: - - main + - dev jobs: testing: name: Testing Comment Service runs-on: ubuntu-latest steps: - - name: Checkout code uses: actions/checkout@v3 @@ -26,11 +25,6 @@ jobs: - name: Unit Tests run: mvn -B test --file pom.xml - sonar-cloud-scan: - needs: testing - uses: ./.github/workflows/SonarQube.yaml - secrets: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} build-image: needs: testing @@ -38,13 +32,25 @@ jobs: secrets: DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - scan-image: + + deploy: needs: build-image - uses: ./.github/workflows/scan-image.yaml + runs-on: ubuntu-latest - notify: - needs: scan-image - uses: ./.github/workflows/notifyCI.yaml - secrets: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - \ No newline at end of file + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Kubectl + uses: azure/setup-kubectl@v2 + with: + version: 'latest' + + - name: Set up Kubeconfig + run: | + mkdir -p $HOME/.kube + echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config + + - name: Deploy to Kubernetes + run: | + kubectl apply -f resources.yml diff --git a/.github/workflows/notifyCD.yaml b/.github/workflows/notifyCD.yaml deleted file mode 100644 index 20f2b28..0000000 --- a/.github/workflows/notifyCD.yaml +++ /dev/null @@ -1,36 +0,0 @@ -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 diff --git a/.github/workflows/notifyCI.yaml b/.github/workflows/notifyCI.yaml deleted file mode 100644 index 2b7db47..0000000 --- a/.github/workflows/notifyCI.yaml +++ /dev/null @@ -1,36 +0,0 @@ -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 Integration 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 Integration for User Service workflow has failed." - } - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/scan-image.yaml b/.github/workflows/scan-image.yaml deleted file mode 100644 index e4477df..0000000 --- a/.github/workflows/scan-image.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Scan Image User Service -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 diff --git a/resources.yaml b/resources.yaml index c4edba2..34e3367 100644 --- a/resources.yaml +++ b/resources.yaml @@ -25,10 +25,10 @@ spec: resources: requests: memory: "32Mi" - cpu: "0.2" + cpu: "200m" limits: memory: "64Mi" - cpu: "0.4" + cpu: "400m" --- apiVersion: v1 kind: Service @@ -41,4 +41,5 @@ spec: - protocol: TCP port: 8081 targetPort: 8081 - type: NodePort \ No newline at end of file + type: NodePort + nodePort: 30001 # Gán cụ thể nodePort để dễ dàng truy cập