Skip to content

Commit dfabf2b

Browse files
authored
Merge pull request #4 from ziadhany/docker-file
Add Dockerfile and publish docker image
2 parents deaa8f5 + 7849725 commit dfabf2b

3 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish Docker image on GitHub Container Registry
2+
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
tags:
8+
- "v*.*.*"
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-publish-image:
16+
runs-on: ubuntu-24.04
17+
18+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
19+
permissions:
20+
contents: read
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28+
with:
29+
persist-credentials: false # do not keep the token around
30+
31+
# Uses the `docker/login-action` action to log in to the Container registry using
32+
# the account and password that will publish the packages.
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels) for image
41+
id: meta
42+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=sha,event=workflow_dispatch,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
47+
type=semver,pattern={{version}}
48+
labels: |
49+
org.opencontainers.image.title=HealthyCode
50+
org.opencontainers.image.description=Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab
51+
org.opencontainers.image.licenses=GPL-3.0-or-later
52+
annotations: |
53+
org.opencontainers.image.title=HealthyCode
54+
org.opencontainers.image.description=Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab
55+
org.opencontainers.image.licenses=GPL-3.0-or-later
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
59+
60+
- name: Build and push Docker image
61+
id: push
62+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
63+
with:
64+
context: .
65+
push: true
66+
tags: |
67+
${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
annotations: ${{ steps.meta.outputs.annotations }}
70+
71+
- name: Generate artifact attestation for Docker image
72+
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
73+
with:
74+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
75+
subject-digest: ${{ steps.push.outputs.digest }}
76+
push-to-registry: true

‎Dockerfile‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.13-slim
2+
3+
LABEL org.opencontainers.image.source="https://github.com/aboutcode-org/healthycode"
4+
LABEL org.opencontainers.image.description="Client to generate GrimoireLab metrics for Project Health using the software analytics platform GrimoireLab"
5+
LABEL org.opencontainers.image.licenses="GPL-3.0-or-later"
6+
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
git build-essential \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /opt/healthycode
12+
13+
RUN pip install --no-cache-dir poetry
14+
RUN poetry config virtualenvs.in-project true
15+
16+
COPY pyproject.toml poetry.lock* ./
17+
RUN poetry install --no-interaction --no-ansi --no-root
18+
19+
COPY . .
20+
21+
RUN poetry build -f wheel \
22+
&& .venv/bin/pip install dist/*.whl

‎README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ grimoirelab-metrics spdx.xml \
6565
--pony-threshold 0.5 \
6666
--elephant-threshold 0.5 \
6767
--dev-categories-thresholds 0.8 0.95 \
68+
--grimoirelab-ecosystem "npm-training-set" \
69+
--grimoirelab-project "npm-popular-components" \
6870
--output metrics.json
6971
```
7072

@@ -109,6 +111,39 @@ This is an example of a valid SPDX file:
109111
</Document>
110112
```
111113

114+
### Running with Docker
115+
The tool can also be run using the published Docker image. This is useful when you
116+
do not want to install Poetry and the tool's dependencies locally.
117+
118+
Build the Docker image from the repository:
119+
```bash
120+
docker build -t healthycode .
121+
```
122+
123+
Then run the tool with a Git repository as the input:
124+
125+
```bash
126+
docker run --rm \
127+
healthycode \
128+
/opt/healthycode/.venv/bin/grimoirelab-metrics https://github.com/aboutcode/example.git \
129+
--grimoirelab-url http://localhost:8000 \
130+
--grimoirelab-user user --grimoirelab-password password \
131+
--opensearch-url https://127.0.0.1:9200 \
132+
--opensearch-index events \
133+
--opensearch-user 'admin' --opensearch-password 'admin' \
134+
--verify-certs --opensearch-ca-certs /path/to/ca.pem \
135+
--from-date 2024-01-01 --to-date 2025-01-01 \
136+
--repository-timeout 3600 \
137+
--code-file-pattern "\.py$|\.js$" \
138+
--binary-file-pattern "\.exe$|\.tar$" \
139+
--pony-threshold 0.5 \
140+
--elephant-threshold 0.5 \
141+
--dev-categories-thresholds 0.8 0.95 \
142+
--grimoirelab-ecosystem "npm-training-set" \
143+
--grimoirelab-project "npm-popular-components" \
144+
--output metrics.json
145+
```
146+
112147
## Project Health Metrics
113148
114149
This is the list of the metrics generated by this tool:

0 commit comments

Comments
 (0)