Skip to content

Commit

Permalink
Sonarqube-ecoCode container image (#72)
Browse files Browse the repository at this point in the history
* Dockerfile for a directly embeded sonarqube ecoCode
* Add a workflow to build container
* Update documentation
* Better workflow version
* Wrong repo in workflow
* Typo in workflow
* Add latest tag on container build if push on main
  • Loading branch information
obeone authored Mar 17, 2023
1 parent 7c5f872 commit 717d153
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
75 changes: 75 additions & 0 deletions .github/workflows/build_container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
# template source: https://github.com/bretfisher/docker-build-workflow/blob/main/templates/call-docker-build.yaml
name: Docker Build

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

env:
# github.repository as <account>/<repo>
IMAGE_NAME: sonarqube-ecocode
IMAGES: |
ghcr.io/${{ github.repository_owner }}/sonarqube-ecocode
jobs:
Build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ env.IMAGES }}
flavor: |
latest=auto
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=semver,event=tag,pattern={{version}}
type=semver,event=tag,pattern={{major}}.{{minor}}
type=semver,event=tag,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Publish image
id: push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
pull: true
cache-to: type=gha,mode=max
cache-from: type=gha,mode=max
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM maven:3-openjdk-11-slim AS builder

COPY . /usr/src/ecocode

WORKDIR /usr/src/ecocode
RUN ./tool_build.sh

FROM sonarqube:9.9-community
COPY --from=builder /usr/src/ecocode/lib/* /opt/sonarqube/extensions/plugins/
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ JavaScript plugin works differently because it does not use AST. [More informati
🚀 Getting Started
------------------

You can download each plugin separatly and copy the plugin (jar file) to `$SONAR_INSTALL_DIR/extensions/plugins` and
You can give a try with a one command docker :
```
docker run -ti --rm \
-v sq_ecocode_logs:/opt/sonarqube/logs \
-v sq_ecocode_data:/opt/sonarqube/data \
-p 9000:9000 \
--name sonarqube-ecocode ghcr.io/green-code-initiative/sonarqube-ecocode:latest
```
And add the `eco-conception` tagged rules to Quality Profiles.

You can also download each plugin separatly and copy the plugin (jar file) to `$SONAR_INSTALL_DIR/extensions/plugins` and
restart SonarQube.

Or you can directly use a [all-in-one docker-compose](INSTALL.md)

🛒 Distribution
Expand Down

0 comments on commit 717d153

Please sign in to comment.