version: '3'
services:
  sonar:
    image: sonarqube:8.9-community
    container_name: sonarqube
    restart: always
    ports:
      - 9000:9000
      - 9001:9001
    depends_on:
      - db
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://${PSQL_HOST}:${PSQL_PORT}/sonar
      SONAR_JDBC_USERNAME: ${PSQL_USERNAME}
      SONAR_JDBC_PASSWORD: ${PSQL_PASSWORD}
    volumes:
      - ./sonarqube/data:/opt/sonarqube/data
      - ./sonarqube/logs:/opt/sonarqube/logs
      - ./sonarqube/extensions:/opt/sonarqube/extensions
      - ./sonarqube/conf:/opt/sonarqube/conf
  db:
    image: postgres:12
    hostname: postgresql
    container_name: postgresql
    environment:
      POSTGRES_USER: ${PSQL_USERNAME}
      POSTGRES_PASSWORD: ${PSQL_PASSWORD}
      POSTGRES_DB: sonar
    ports:
      - 5432:5432
    volumes:
      - ./psql/postgresql:/var/lib/postgresql
      - ./psql/postgresql_data:/var/lib/postgresql/data