How to integrate sonar qube to docker compose

36 Views Asked by At

Right now I have this workflow:

name: Deployment-CI/CD

on:
  push:
    branches:
      - v3.0.0_workflows_single_job
  pull_request:
    branches:
      - "master"
    types: [closed]


jobs:
  #  Run documentation pipeline
  documentation-CI:
    name: documentation-CI 
    uses: ./.github/workflows/documentation.yml

  # Run the article CI pipeline
  article-CI:
    name: article-CI 
    uses: ./.github/workflows/SJ.yml
    with:
      java_version: 18
      working_directory: ./article
      sonar_project_key: Article_Module
      sonar_project_name: "Article Module"
      sonar_host_url: http://localhost:9000
      sonar_token: 


  # Run the farmer CI pipeline
  farmer-CI:
    name: farmer-CI 
    uses: ./.github/workflows/SJ.yml
    with:
      java_version: 18
      working_directory: ./farmer
      sonar_project_key: Farmer_Module
      sonar_project_name: "Farmer Module"
      sonar_host_url: http://localhost:9000
      sonar_token: 


  #  Run the transport CI pipeline
  transport-CI:
    name: transport-CI 
    uses: ./.github/workflows/SJ.yml
    with:
      java_version: 18
      working_directory: ./transport
      sonar_project_key: Transport_Module
      sonar_project_name: "- Transport Module"
      sonar_host_url: http://localhost:9000
      sonar_token: 

  # Run the client CI pipeline
  client-CI:
    name: client-CI 
    uses: ./.github/workflows/clientDev.yml

    # Build the docker images for all modules
  image-build:
    name: Docker image build 
    runs-on: self-hosted
    needs: [client-CI, transport-CI, farmer-CI, article-CI, documentation-CI]
    steps:
      - name: Checkout branch ️
        uses: actions/checkout@v3

      - name: Set up JDK 18 ️
        uses: actions/setup-java@v3
        with:
          java-version: 18
          distribution: 'temurin'
          cache: maven

      - name: Create Docker images with JIB  ️
        run: mvn -T 2C compile package jib:dockerBuild -e

  # Create docker containers for all modules
  container-creation:
    name: Docker container creation 
    runs-on: self-hosted
    needs: image-build
    steps:
      - name: Checkout branch ️
        uses: actions/checkout@v3

      #todo change env variables to use production values
      - name: Build and start containers 
        run: docker-compose -f docker-compose-staging.yml up --build -d

and right now for me to use sonar qube I need to have already a sonar qube container set up outside the docker compose in the staging machine for me to connect it and analyze the code. I want to create the sonar qube container together with the other containers automatically. Any ideas how can I solve this dependency with the most efficient code and without repeating code and so on....

0

There are 0 best solutions below