Skip to content

Commit 10d735b

Browse files
author
Yoan Moscatelli
committed
✨ add pre-commit, reviews and venv
1 parent e1254a0 commit 10d735b

File tree

10 files changed

+85
-28
lines changed

10 files changed

+85
-28
lines changed

.devcontainer/Dockerfile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/devcontainers/base:jammy
1+
FROM mcr.microsoft.com/devcontainers/base:noble
22

33
RUN export DEBIAN_FRONTEND=noninteractive && \
44
apt-get update && \
@@ -8,14 +8,29 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
88
bash-completion \
99
curl \
1010
git \
11+
libsqlite3-dev \
12+
python3 \
1113
python3-pip \
14+
python3-venv \
1215
p7zip-full \
1316
skopeo \
1417
tmux \
1518
vim \
1619
&& \
1720
apt-get clean
21+
22+
USER vscode
23+
24+
ENV LANG=C.UTF-8
25+
ENV LC_ALL=C.UTF-8
26+
27+
# Create virtual environment
28+
ENV VIRTUAL_ENV=/home/vscode/venv
29+
RUN python3 -m venv $VIRTUAL_ENV
30+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
31+
1832
COPY requirements.txt /tmp/requirements.txt
19-
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
20-
python3 -m pip install --no-cache-dir -r /tmp/requirements.txt
21-
USER vscode
33+
34+
# Install python libs in the virtual environment
35+
RUN pip install --upgrade pip && \
36+
pip install -r /tmp/requirements.txt

.devcontainer/requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
requests==2.32.0
2-
GitPython==3.1.43
1+
requests==2.32.3
2+
GitPython==3.1.44
33
pyunpack==0.3
4-
patool==2.2.0
4+
patool==4.0.0
5+
pre-commit==4.1.0

.devcontainer/setup.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -xe
44

5-
if [ "$CODESPACES" = "true" ]; then
5+
if [[ "${CODESPACES}" = "true" ]]; then
66
# NOTE: This is the only way I managed to have the right
77
# permissions files for git sources files
88
# (Some salt pylint test check file permissions and expected 644
@@ -19,10 +19,11 @@ fi
1919
echo "Updating localtime"
2020
sudo ln -fs /usr/share/zoneinfo/UTC /etc/localtime
2121

22-
# Install act
23-
gh extension install https://github.com/nektos/gh-act
22+
echo "Install pre-commit hooks"
23+
pre-commit install --install-hooks
2424

25-
# Install dependencies
2625
echo "Installing dependencies"
27-
python3 src/main.py install
26+
# Run with sudo and preserved environment
27+
sudo PATH="${PATH}" python3 src/main.py install
28+
2829
echo "End of setup"

.github/dependabot.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
version: 2
23
updates:
34
- package-ecosystem: "github-actions"
@@ -12,9 +13,6 @@ updates:
1213
schedule:
1314
interval: "daily"
1415
rebase-strategy: "auto"
15-
ignore:
16-
- dependency-name: "requests"
17-
versions: ["<2.25.1"]
1816
reviewers:
1917
- "scality/metalk8s"
2018

.github/scripts/update_scanners.py

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
import re
24
import requests
35

.github/workflows/nightly.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: "nightly"
23
run-name: "Nightly tests for ${{ github.ref_name }}"
34

@@ -38,15 +39,17 @@ jobs:
3839
- name: Update scanner versions
3940
run: python .github/scripts/update_scanners.py
4041

41-
- name: Create Pull Request
42-
uses: peter-evans/create-pull-request@v7
43-
id: pr
44-
with:
45-
title: Dependency update
46-
branch: feature/deps-update
47-
delete-branch: true
48-
commit-message: ":arrow_up: Update scanner versions"
49-
token: ${{ steps.app-token.outputs.token }}
42+
- name: Create pull request
43+
uses: actions/github-script@v7
44+
with:
45+
script: |
46+
const pr = await github.rest.pulls.create({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
head: "feature/deps-update",
50+
base: "main",
51+
title: ":arrow_up: Update scanner versions"
52+
})
5053
5154
vuln-scan:
5255
permissions:
@@ -58,7 +61,6 @@ jobs:
5861
- name: Checkout
5962
uses: actions/checkout@v4
6063
with:
61-
path: ./
6264
fetch-depth: 0
6365
fetch-tags: true
6466

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
repos:
3+
- repo: https://github.com/psf/black
4+
rev: 25.1.0
5+
hooks:
6+
- id: black
7+
files: src/.*\.py
8+
name: Formatting Python
9+
- id: black
10+
files: src/.*\.py
11+
# We want this hook to be part of "lint" so that if we run
12+
# `pre-commit run lint` we include this hook
13+
alias: lint
14+
name: Checking Python formatting
15+
args:
16+
- --check
17+
- --diff
18+
19+
- repo: https://github.com/pycqa/pylint
20+
rev: v3.3.5
21+
hooks:
22+
- id: pylint
23+
alias: lint
24+
name: Lint Python (CLI)
25+
files: src/.*\.py
26+
additional_dependencies:
27+
- 'requests~=2.32.3'
28+
- 'GitPython~=3.1.44'
29+
- 'pyunpack~=0.3'
30+
- 'patool~=4.0.0'

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ It has been installed through the `gh` extension.
1515
To run the workflow locally, execute the following command:
1616

1717
```bash
18-
gh act push --rm --workflows=.github/workflows/tests.yaml -P ubuntu-22.04=ghcr.io/catthehacker/ubuntu:act-22.04
18+
docker login ghcr.io
19+
gh extension install https://github.com/nektos/gh-act
20+
gh act push --rm --workflows=.github/workflows/tests.yaml -P ubuntu-24.04=ghcr.io/catthehacker/ubuntu:act-22.04
1921
```
2022

2123
For more information on how to use `act`, please refer to the [official documentation] or run `gh act --help`.

action.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: "Scality SBOM Action"
23
description: "Creates an SBOM (Software Bill Of Materials) from your code, and artifacts."
34
author: "Scality"

src/lib/install.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pyunpack import Archive
88

99
# Define the scanners and their versions
10-
scanners = {"syft": "1.20.0", "grype": "0.89.1", "trivy": "0.60.0"}
10+
scanners = {"syft": "1.21.0", "grype": "0.90.0", "trivy": "0.60.0"}
1111

1212
# Define the base URLs for the scanners
1313
ANCHORE_BASE_URL = (
@@ -20,6 +20,7 @@
2020
"v{version}/{package_name}_{version}_Linux-64bit.tar.gz"
2121
)
2222

23+
2324
def set_versions(package_name):
2425
"""
2526
## This function sets the versions of the scanners.
@@ -30,6 +31,7 @@ def set_versions(package_name):
3031
version = scanners[package_name]
3132
return version
3233

34+
3335
def install_package(package_name, version):
3436
"""
3537
## This function installs the specified package and version.
@@ -47,6 +49,8 @@ def install_package(package_name, version):
4749
except FileNotFoundError:
4850
print(f"{package_name} is not installed.")
4951
print(f"Installing {package_name} version {version}...")
52+
# Set base URL based on package name
53+
base_url = ""
5054
if package_name in ["syft", "grype"]:
5155
base_url = ANCHORE_BASE_URL
5256
elif package_name == "trivy":
@@ -77,11 +81,12 @@ def install_package(package_name, version):
7781
os.remove(f"{package_name}_v{version}.tar.gz")
7882
print(f"{package_name} version {version} installed.")
7983

84+
8085
def install():
8186
"""
8287
## This function installs the base packages.
8388
"""
8489
for scanner, version in scanners.items():
8590
version = set_versions(scanner)
8691
print(f"Installing {scanner} version {version}...")
87-
install_package(scanner,version)
92+
install_package(scanner, version)

0 commit comments

Comments
 (0)