Skip to content

Commit 3a40156

Browse files
committed
add Makefile and enable local CI tests
1 parent 8e87fff commit 3a40156

File tree

10 files changed

+98
-109
lines changed

10 files changed

+98
-109
lines changed

.github/workflows/bandit.yml

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
name: security checks
22
on:
3-
push:
4-
paths-ignore:
5-
- 'README.md'
6-
- 'docs/**'
7-
- '**/README.md'
8-
pull_request:
9-
paths-ignore:
10-
- 'README.md'
11-
- 'docs/**'
12-
- '**/README.md'
3+
push:
4+
paths-ignore:
5+
- "README.md"
6+
- "docs/**"
7+
- "**/README.md"
8+
pull_request:
9+
paths-ignore:
10+
- "README.md"
11+
- "docs/**"
12+
- "**/README.md"
1313
permissions:
14-
contents: read
14+
contents: read
1515
jobs:
1616
build:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v4
20-
- uses: actions/setup-python@v5
21-
with:
22-
python-version: "3.12"
23-
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install bandit
27-
28-
- name: Simple bandit security checks
29-
run: bandit -ll -ii -r . -f json -o bandit-report.json
30-
31-
- name: Show Report in Action Output
32-
if: always()
33-
run: cat bandit-report.json
34-
35-
- name: Upload Bandit Scan Artifact
36-
uses: actions/upload-artifact@v4
37-
if: always()
38-
with:
39-
name: bandit-findings
40-
path: bandit-report.json
41-
19+
- uses: actions/checkout@v4
20+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
21+
- name: Simple bandit security checks
22+
run: make security
23+
- name: Show Report in Action Output
24+
if: always()
25+
run: cat bandit-report.json
26+
- name: Upload Bandit Scan Artifact
27+
uses: actions/upload-artifact@v4
28+
if: always()
29+
with:
30+
name: bandit-findings
31+
path: bandit-report.json

.github/workflows/black.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10-
- uses: psf/black@stable
10+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
11+
- run: make lint

.github/workflows/build.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@ name: Build
22
on:
33
push:
44
paths-ignore:
5-
- 'README.md'
6-
- 'docs/**'
7-
- '**/README.md'
5+
- "README.md"
6+
- "docs/**"
7+
- "**/README.md"
88
pull_request:
99
paths-ignore:
10-
- 'README.md'
11-
- 'docs/**'
12-
- '**/README.md'
10+
- "README.md"
11+
- "docs/**"
12+
- "**/README.md"
1313
permissions:
1414
contents: read
1515
jobs:
1616
build:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v4
20-
- uses: actions/setup-python@v5
21-
with:
22-
python-version: "3.12"
23-
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install poetry
27-
- name: Simple poetry build no package
28-
run: poetry build
29-
19+
- uses: actions/checkout@v4
20+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
21+
- name: Simple poetry build no package
22+
run: make build

.github/workflows/docs.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@ name: Update Sphinx documentation
33
on: [push, pull_request, workflow_dispatch]
44

55
permissions:
6-
contents: write
6+
contents: write
77

88
jobs:
99
docs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13-
- uses: actions/setup-python@v5
14-
- name: Install dependencies
15-
run: |
16-
pip install sphinx poetry
17-
- name: Sphinx build
18-
run: |
19-
python -m venv venv
20-
source venv/bin/activate
21-
poetry install
22-
sphinx-build docs _build
13+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
14+
- run: make docs
2315
- name: Deploy to GitHub Pages
2416
uses: peaceiris/actions-gh-pages@v4
2517
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}

.github/workflows/pytests.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,10 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12-
1312
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v4
16-
with:
17-
submodules: 'true'
18-
- name: Set up Python
19-
uses: actions/setup-python@v5
20-
with:
21-
python-version: '3.12'
22-
- name: Install dependencies
23-
run: |
24-
python -m pip install --upgrade pip
25-
pip install poetry
26-
- name: Install dependencies
27-
run: poetry install
28-
- name: Install Zot (OCI Registry)
13+
- uses: actions/checkout@v4
14+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
15+
- name: Run tests
2916
run: |
30-
sudo wget -O /usr/bin/zot https://github.com/project-zot/zot/releases/download/v2.1.0/zot-linux-amd64
31-
sudo chmod +x /usr/bin/zot
32-
sudo chown root:root /usr/bin/zot
33-
- name: Run tests with pytest
34-
run: |
35-
export GLOCI_REGISTRY_USERNAME="gardenlinux"
3617
export GLOCI_REGISTRY_TOKEN="invalid"
37-
poetry run pytest -k "not kms"
38-
18+
make test

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,9 @@ cython_debug/
162162
# and can be added to the global gitignore or merged into this file. For a more nuclear
163163
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164164
.idea/
165+
166+
# bandit
167+
bandit-report.json
168+
169+
# zot
170+
test-data/zot

cert/gencert.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

hack/print_feature_extensions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33

44
search_and_print_directories() {

test-data/build-test-data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33
echo "This will take a while. Building for the following targets:"
44

tests/conftest.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
1-
from .helper import call_command
1+
import json
22
import os
3-
import tempfile
4-
from .helper import spawn_background_process
5-
import sys
63
import shutil
7-
import json
4+
import subprocess
5+
import sys
6+
import tempfile
7+
88
import pytest
99
from dotenv import load_dotenv
1010

11-
GL_ROOT_DIR = "test-data/gardenlinux"
11+
from .helper import call_command, spawn_background_process
12+
13+
TEST_DATA_DIR = "test-data"
14+
GL_ROOT_DIR = f"{TEST_DATA_DIR}/gardenlinux"
15+
CERT_DIR = f"{TEST_DATA_DIR}/cert"
16+
17+
18+
def generate_test_certificates():
19+
"""Generate self-signed certificates for testing"""
20+
os.makedirs(CERT_DIR, exist_ok=True)
21+
key_path = os.path.join(CERT_DIR, "oci-sign.key")
22+
cert_path = os.path.join(CERT_DIR, "oci-sign.crt")
23+
cmd = [
24+
"openssl",
25+
"req",
26+
"-x509",
27+
"-newkey",
28+
"rsa:4096",
29+
"-keyout",
30+
key_path,
31+
"-out",
32+
cert_path,
33+
"-days",
34+
"365",
35+
"-nodes",
36+
"-subj",
37+
"/CN=Garden Linux test signing key for oci",
38+
]
39+
try:
40+
subprocess.run(cmd, check=True)
41+
# Set proper permissions
42+
os.chmod(key_path, 0o600)
43+
print(f"Generated test certificates in {CERT_DIR}")
44+
except subprocess.CalledProcessError as e:
45+
print(f"Error generating certificates: {e}")
46+
raise
1247

1348

1449
def write_zot_config(config_dict, file_path):
@@ -33,7 +68,7 @@ def zot_session():
3368

3469
print(f"Spawning zot registry with config {zot_config_file_path}")
3570
zot_process = spawn_background_process(
36-
f"zot serve {zot_config_file_path}",
71+
f"{TEST_DATA_DIR}/zot serve {zot_config_file_path}",
3772
stdout=sys.stdout,
3873
stderr=sys.stderr,
3974
)
@@ -50,12 +85,12 @@ def zot_session():
5085

5186

5287
def pytest_sessionstart(session):
53-
call_command("./cert/gencert.sh")
88+
generate_test_certificates()
5489
call_command("./test-data/build-test-data.sh --dummy")
5590

5691

5792
def pytest_sessionfinish(session):
58-
if os.path.isfile("./cert/oci-sign.crt"):
59-
os.remove("./cert/oci-sign.crt")
60-
if os.path.isfile("./cert/oci-sign.key"):
61-
os.remove("./cert/oci-sign.key")
93+
if os.path.isfile(CERT_DIR + "/oci-sign.crt"):
94+
os.remove(CERT_DIR + "/oci-sign.crt")
95+
if os.path.isfile(CERT_DIR + "/oci-sign.key"):
96+
os.remove(CERT_DIR + "/oci-sign.key")

0 commit comments

Comments
 (0)