diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..df76028e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,56 @@ +name: CI Pipeline + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + +jobs: + ci_pipeline: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + # Install Java (Required for Sonar Scanner) + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + # SonarQube Scan (Self-Hosted) + - name: SonarQube Scan + run: | + curl -o sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip + unzip sonar-scanner.zip + export PATH=$PATH:$(pwd)/sonar-scanner-5.0.1.3006-linux/bin + sonar-scanner \ + -Dsonar.projectKey=your-project-key \ + -Dsonar.sources=. \ + -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ + -Dsonar.login=${{ secrets.SONAR_TOKEN }} + + # Log in to Docker Hub + - name: Log in to Docker Hub + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + + # Build and Push Docker Image + - name: Build and Push Docker Image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/your-app:latest . + docker push ${{ secrets.DOCKER_USERNAME }}/your-app:latest + + # Trivy Security Scan + - name: Scan Docker Image with Trivy + uses: aquasecurity/trivy-action@master + with: + image-ref: "${{ secrets.DOCKER_USERNAME }}/your-app:latest" + format: "table" + exit-code: 1 + severity: "CRITICAL,HIGH"