Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .default.docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MAVEN_BUILDER_VERSION=3-openjdk-17-slim
SONARQUBE_VERSION=10.6.0-community
POSTGRES_VERSION=12
SONAR_LOG_LEVEL_WEB=INFO
DOCKER_BUILDKIT=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put a comment for these 2 options, please

COMPOSE_DOCKER_CLI_BUILD=1
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

# Ensure BAT files will always be checked out with CRLFs (regardless of the
# OS they were checked out on).
*.bat text eol=crlf
*.bat text eol=crlf
49 changes: 49 additions & 0 deletions .github/workflows/bash_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Bash Tests

on:
pull_request:
push:
branches:
- main
tags:
- '*'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Setup Python
- uses: actions/setup-python@v2
with:
python-version: '3.12'

# Cache the installation of Poetry itself
- name: cache poetry install
uses: actions/cache@v2
with:
path: ~/.local
key: poetry-1.7.1-0

# Install Poetry
- uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true

# Cache dependencies
- name: cache deps
id: cache-deps
uses: actions/cache@v2
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}

# Install dependencies
- run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'

# Run tests
- run: poetry run pytest tests/test_*.py
1 change: 1 addition & 0 deletions .github/workflows/build_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
- name: Publish image
id: push
uses: docker/build-push-action@v4
if: github.event_name == 'pull_request' && github.event.action == 'closed'
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Ignore IDE files
*.iml
.idea

# Ignore all files and folders starting with ".", except a few exceptions
.*
!.gitignore
!.gitattributes
!.github/
!.default.docker.env

# Ignore generated files
target
bin
dependency-reduced-pom.xml

# Ignore IDE files
*.iml
release.properties
pom.xml.*
tests/__pycache__
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
ARG MAVEN_BUILDER=3-openjdk-17-slim
ARG SONARQUBE_VERSION=10.6.0-community
# syntax=docker/dockerfile:1

FROM maven:${MAVEN_BUILDER} AS builder
ARG MAVEN_BUILDER_VERSION
ARG SONARQUBE_VERSION

COPY . /usr/src/ecocode
FROM maven:${MAVEN_BUILDER_VERSION} AS builder

WORKDIR /usr/src/ecocode
COPY src src/
COPY pom.xml tool_build.sh ./
ARG ECOCODE_SRC_PATH=/usr/src/ecocode

RUN ./tool_build.sh
COPY . ${ECOCODE_SRC_PATH}

WORKDIR ${ECOCODE_SRC_PATH}
RUN ${ECOCODE_SRC_PATH}/toolbox.sh build

FROM sonarqube:${SONARQUBE_VERSION}
COPY --from=builder /usr/src/ecocode/target/ecocode-*.jar /opt/sonarqube/extensions/plugins/

ARG ECOCODE_SRC_PATH=/usr/src/ecocode
ARG SONARQUBE_PLUGINS_PATH=/opt/sonarqube/extensions/plugins/

COPY --from=builder ${ECOCODE_SRC_PATH}/target/ecocode-*.jar ${SONARQUBE_PLUGINS_PATH}
USER sonarqube
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
name: sonarqube_ecocode_java

services:
sonar:
build: .
build:
context: .
dockerfile: Dockerfile
args:
- MAVEN_BUILDER_VERSION=${MAVEN_BUILDER_VERSION}
- SONARQUBE_VERSION=${SONARQUBE_VERSION}
container_name: sonar_ecocode_java
ports:
- ":9000"
Expand All @@ -16,18 +21,13 @@ services:
SONAR_JDBC_PASSWORD: sonar
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonarqube
SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true'
env_file:
- path: ./.default.docker.env
required: true
- path: ./.override.docker.env
required: false
volumes:
- "extensions:/opt/sonarqube/extensions"
- "logs:/opt/sonarqube/logs"
- "data:/opt/sonarqube/data"

db:
image: postgres:12
image: postgres:${POSTGRES_VERSION}
container_name: postgresql_ecocode_java
networks:
- sonarnet
Expand Down
137 changes: 137 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# toolbox.sh

## Overview

This toolbox enables you to install the SonarQube dev environment.

## Index

* [build](#build)
* [compile](#compile)
* [docker_env_source](#dockerenvsource)
* [docker_build](#dockerbuild)
* [init](#init)
* [start](#start)
* [stop](#stop)
* [clean](#clean)
* [display_logs](#displaylogs)
* [release](#release)
* [release_push](#releasepush)
* [display_help](#displayhelp)

### build

Compile and package source code with maven.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered when building source code.
* **2**: If the ecoCode plugin in target directory cannot be found.

### compile

Compile source code with maven.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered when compiling the source code.

### docker_env_source

Export environment variables from .default.docker.env file.

#### Exit codes

* **0**: If successful.
* **1**: If the environment file cannot be found.

### docker_build

Build Docker services.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered retrieving environment variables.
* **2**: If an error has been encountered when building services.

### init

Building the ecoCode plugin and creating containers.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered when building project code in the target folder.
* **2**: If an error was encountered retrieving environment variables.
* **3**: If an error was encountered during container creating.

### start

Starting Docker containers.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered retrieving environment variables.
* **2**: If the ecoCode plugin is not present in the target folder.
* **3**: If an error was encountered during container startup.

### stop

Stopping Docker containers.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered retrieving environment variables.
* **2**: If an error was encountered during container shutdown.

### clean

Stop and remove containers, networks and volumes.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered retrieving environment variables.
* **2**: If an error was encountered during deletion.

### display_logs

Display Docker container logs.

#### Exit codes

* **0**: If successful.
* **1**: If an error was encountered retrieving environment variables.

### release

Use maven plugin release to prepare locally next release and next SNAPSHOT.

#### Exit codes

* **0**: If successful.
* **1**: If an error is encountered when prepare the release.
* **2**: If an error is encountered when cleaning files.

### release_push

Create a push and a new branch with commits previously prepared.

#### Exit codes

* **0**: If successful.
* **1**: If the last commit tag does not match the last git tag.

### display_help

Display help.

#### Exit codes

* **0**: If successful.

Loading