Skip to content

Commit dc3a76f

Browse files
authored
fix: update docker and package build (#26)
1 parent e041786 commit dc3a76f

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

.github/workflows/docker-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
run: |
3535
docker build \
3636
-f docker/Dockerfile \
37+
--build-arg APP_VERSION=${GITHUB_REF_NAME} \
38+
--build-arg APP_COMMIT_SHA=${GITHUB_SHA} \
3739
-t ghcr.io/${{ steps.repo.outputs.repo }}:${GITHUB_REF_NAME} \
3840
-t ghcr.io/${{ steps.repo.outputs.repo }}:latest \
3941
.
@@ -43,12 +45,16 @@ jobs:
4345
- name: Build & Push Scanner specific Docker image
4446
run: |
4547
docker build \
48+
--build-arg APP_VERSION=${GITHUB_REF_NAME} \
49+
--build-arg APP_COMMIT_SHA=${GITHUB_SHA} \
4650
-f docker/cnspec.Dockerfile \
4751
-t ghcr.io/${{ steps.repo.outputs.repo }}:${GITHUB_REF_NAME}-cnspec \
4852
-t ghcr.io/${{ steps.repo.outputs.repo }}:latest-cnspec \
4953
.
5054
5155
docker build \
56+
--build-arg APP_VERSION=${GITHUB_REF_NAME} \
57+
--build-arg APP_COMMIT_SHA=${GITHUB_SHA} \
5258
-f docker/snyk.Dockerfile \
5359
-t ghcr.io/${{ steps.repo.outputs.repo }}:${GITHUB_REF_NAME}-snyk \
5460
-t ghcr.io/${{ steps.repo.outputs.repo }}:latest-snyk \

docker/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ ARG BASE_IMAGE_REPOSITORY="python"
33
ARG BASE_IMAGE_TAG="3.12-alpine3.22"
44
FROM ${BASE_IMAGE_REGISTRY}/${BASE_IMAGE_REPOSITORY}:${BASE_IMAGE_TAG}
55

6-
ARG APP_COMMIT_SHA=""
7-
ARG APP_VERSION=""
6+
ARG APP_COMMIT_SHA="changeme"
7+
ARG APP_VERSION="v0.0.1"
88
ENV APP_COMMIT_SHA=$APP_COMMIT_SHA
99
ENV APP_VERSION=$APP_VERSION
10+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=$APP_VERSION
1011

1112
# install uv
1213
COPY --from=docker.io/astral/uv@sha256:e4644cb5bd56fdc2c5ea3ee0525d9d21eed1603bccd6a21f887a938be7e85be1 /uv /uvx /bin/
@@ -25,13 +26,13 @@ USER airgapper
2526
WORKDIR /home/airgapper
2627

2728
# Copy requirements first to leverage Docker cache
28-
COPY pyproject.toml uv.lock ./
29-
30-
# Install dependencies
31-
RUN uv sync --frozen # --no-dev
29+
COPY pyproject.toml uv.lock LICENSE README.md ./
3230

3331
# Copy all local packages and files
34-
COPY src/ .
32+
COPY src/ src/
33+
34+
# Install dependencies
35+
RUN uv venv && uv sync --frozen
3536

3637
# Specify the command to run the app
37-
ENTRYPOINT ["uv", "run", "python", "main.py"]
38+
ENTRYPOINT ["uv", "run", "cnairgapper"]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ build-backend = "hatchling.build"
4444
[tool.hatch.version]
4545
source = "vcs"
4646

47-
[tool.hatch.build.hooks.vcs]
48-
version-file = "src/cnairgapper/_version.py"
47+
# [tool.hatch.build.hooks.vcs]
48+
# version-file = "src/cnairgapper/_version.py"
4949

5050
[tool.hatch.build.targets.sdist]
5151
include = ["src", "README.md", "LICENSE", "pyproject.toml"]

src/cnairgapper/cli/parser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import argparse
2+
from importlib.metadata import PackageNotFoundError
3+
from importlib.metadata import version as pkg_version
24

35
import configargparse
46

@@ -31,10 +33,24 @@ def create_parser():
3133
"--config-folder", help="Path to a folder containing YAML sync config files"
3234
)
3335

36+
parser.add_argument(
37+
"--version",
38+
action="version",
39+
version=_get_version(),
40+
)
41+
3442
parser.add_argument("--debug", action="store_true", default=False, help="Enable debug logging")
3543
return parser
3644

3745

46+
def _get_version() -> str:
47+
try:
48+
# must match [project].name in pyproject.toml
49+
return pkg_version("cnairgapper")
50+
except PackageNotFoundError:
51+
return "0.0.0-dev"
52+
53+
3854
def validate_arguments(args: argparse.Namespace, parser: argparse.ArgumentParser) -> bool:
3955
"""Validates the provided command-line arguments to ensure exactly one option is specified
4056
between mutually exclusive pairs (--credentials-file, --credentials-folder) and

0 commit comments

Comments
 (0)