diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml new file mode 100644 index 0000000..3a70035 --- /dev/null +++ b/.github/workflows/publish-docker-image.yml @@ -0,0 +1,76 @@ +name: Publish Docker image on GitHub Container Registry +# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions + +on: + workflow_dispatch: + push: + tags: + - "v*.*.*" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-publish-image: + runs-on: ubuntu-24.04 + + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false # do not keep the token around + + # Uses the `docker/login-action` action to log in to the Container registry using + # the account and password that will publish the packages. + - name: Log in to the Container registry + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for image + id: meta + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha,event=workflow_dispatch,enable=${{ !startsWith(github.ref, 'refs/tags/') }} + type=semver,pattern={{version}} + labels: | + org.opencontainers.image.title=HealthyCode + org.opencontainers.image.description=Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab + org.opencontainers.image.licenses=GPL-3.0-or-later + annotations: | + org.opencontainers.image.title=HealthyCode + org.opencontainers.image.description=Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab + org.opencontainers.image.licenses=GPL-3.0-or-later + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 + with: + context: . + push: true + tags: | + ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} + + - name: Generate artifact attestation for Docker image + uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6b2e9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.13-slim + +LABEL org.opencontainers.image.source="https://github.com/aboutcode-org/healthycode" +LABEL org.opencontainers.image.description="Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab" +LABEL org.opencontainers.image.licenses="GPL-3.0-or-later" + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /opt/healthycode + +RUN pip install --no-cache-dir poetry +RUN poetry config virtualenvs.in-project true + +COPY pyproject.toml poetry.lock* ./ +RUN poetry install --no-interaction --no-ansi --no-root + +COPY . . + +RUN poetry build -f wheel \ + && .venv/bin/pip install dist/*.whl \ No newline at end of file diff --git a/README.md b/README.md index ae14350..666b956 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ grimoirelab-metrics spdx.xml \ --pony-threshold 0.5 \ --elephant-threshold 0.5 \ --dev-categories-thresholds 0.8 0.95 \ + --grimoirelab-ecosystem "npm-training-set" \ + --grimoirelab-project "npm-popular-components" \ --output metrics.json ``` @@ -109,6 +111,39 @@ This is an example of a valid SPDX file: ``` +### Running with Docker +The tool can also be run using the published Docker image. This is useful when you +do not want to install Poetry and the tool's dependencies locally. + +Build the Docker image from the repository: +```bash +docker build -t healthycode . +``` + +Then run the tool with a Git repository as the input: + +```bash +docker run --rm \ + healthycode \ + /opt/healthycode/.venv/bin/grimoirelab-metrics https://github.com/aboutcode/example.git \ + --grimoirelab-url http://localhost:8000 \ + --grimoirelab-user user --grimoirelab-password password \ + --opensearch-url https://127.0.0.1:9200 \ + --opensearch-index events \ + --opensearch-user 'admin' --opensearch-password 'admin' \ + --verify-certs --opensearch-ca-certs /path/to/ca.pem \ + --from-date 2024-01-01 --to-date 2025-01-01 \ + --repository-timeout 3600 \ + --code-file-pattern "\.py$|\.js$" \ + --binary-file-pattern "\.exe$|\.tar$" \ + --pony-threshold 0.5 \ + --elephant-threshold 0.5 \ + --dev-categories-thresholds 0.8 0.95 \ + --grimoirelab-ecosystem "npm-training-set" \ + --grimoirelab-project "npm-popular-components" \ + --output metrics.json +``` + ## Project Health Metrics This is the list of the metrics generated by this tool: