Skip to content

Commit 9f6f60e

Browse files
Add grype scan, SBOM and improve labeling (#467)
* Add grype scan, SBOM and improve labeling Signed-off-by: Marikkannu, Suresh <suresh.marikkannu@intel.com> * Fix ui build issue Signed-off-by: Marikkannu, Suresh <suresh.marikkannu@intel.com> * Add e2e test Signed-off-by: Marikkannu, Suresh <suresh.marikkannu@intel.com> * Remove e2e test and address review comments Signed-off-by: Marikkannu, Suresh <suresh.marikkannu@intel.com> --------- Signed-off-by: Marikkannu, Suresh <suresh.marikkannu@intel.com>
1 parent b8d3cb9 commit 9f6f60e

5 files changed

Lines changed: 221 additions & 91 deletions

File tree

.github/dependabot.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2023 Canonical Ltd.
3-
# Copyright 2024 Intel Corporation
3+
# Copyright 2024-present Intel Corporation
44

5+
# Timeline for each ecosystem is intentionally staggered to spread
6+
# Dependabot PRs over the week.
57
version: 2
68
updates:
79

@@ -17,15 +19,15 @@ updates:
1719
directory: "/"
1820
schedule:
1921
interval: "weekly"
20-
day: "sunday"
22+
day: "thursday"
2123
time: "21:00"
2224
timezone: "America/Los_Angeles"
2325

2426
- package-ecosystem: github-actions
2527
directory: /
2628
schedule:
2729
interval: "weekly"
28-
day: "sunday"
30+
day: "tuesday"
2931
time: "21:00"
3032
timezone: "America/Los_Angeles"
3133
groups:

.github/workflows/push.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright 2024 Intel Corporation
2+
# Copyright 2024-present Intel Corporation
33
# Copyright 2025 Canonical Ltd.
44
name: Release Pipeline
55

@@ -60,3 +60,27 @@ jobs:
6060
release_branch: ${{ needs.tag-github.outputs.release_branch }}
6161
version_branch: ${{ needs.tag-github.outputs.version_branch }}
6262
secrets: inherit
63+
64+
sbom-source:
65+
needs: tag-github
66+
permissions:
67+
contents: read
68+
actions: read
69+
uses: omec-project/.github/.github/workflows/sbom-source.yml@4c4b1670edc14f7f8f95b6be5e1cb779b86b2716 # v0.0.16
70+
with:
71+
changed: ${{ needs.tag-github.outputs.changed }}
72+
branch_name: ${{ github.ref }}
73+
artifact_name: ${{ github.event.repository.name }}-${{ needs.tag-github.outputs.version }}.spdx.json
74+
sbom_format: spdx-json
75+
path: .
76+
77+
grype-scan:
78+
needs: [tag-github, sbom-source]
79+
permissions:
80+
contents: read
81+
actions: read
82+
security-events: write # Required for SARIF upload to Code Scanning
83+
uses: omec-project/.github/.github/workflows/grype-scan.yml@4c4b1670edc14f7f8f95b6be5e1cb779b86b2716 # v0.0.16
84+
with:
85+
changed: ${{ needs.tag-github.outputs.changed }}
86+
artifact_name: ${{ github.event.repository.name }}-${{ needs.tag-github.outputs.version }}.spdx.json

Dockerfile

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
# SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
2-
# SPDX-FileCopyrightText: 2024 Intel Corporation
2+
# SPDX-FileCopyrightText: 2024-present Intel Corporation
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

77
FROM golang:1.26.0-bookworm@sha256:eae3cdfa040d0786510a5959d36a836978724d03b34a166ba2e0e198baac9196 AS builder
88

9-
RUN apt-get update && \
10-
apt-get -y install --no-install-recommends \
11-
apt-transport-https \
12-
ca-certificates \
13-
gcc \
14-
cmake \
15-
autoconf \
16-
libtool \
17-
pkg-config \
18-
libmnl-dev \
19-
libyaml-dev \
20-
unzip && \
21-
apt-get clean
22-
239
WORKDIR $GOPATH/src/webconsole
2410
COPY . .
2511
RUN make all && \
2612
CGO_ENABLED=0 go build -a -installsuffix nocgo -o webconsole -x server.go
2713

2814
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS webui
2915

30-
LABEL maintainer="Aether SD-Core <dev@lists.aetherproject.org>" \
31-
description="ONF open source 5G Core Network" \
32-
version="Stage 3"
16+
17+
# Build arguments for dynamic labels
18+
ARG VERSION=dev
19+
ARG VCS_URL=unknown
20+
ARG VCS_REF=unknown
21+
ARG BUILD_DATE=unknown
22+
23+
LABEL org.opencontainers.image.source="${VCS_URL}" \
24+
org.opencontainers.image.version="${VERSION}" \
25+
org.opencontainers.image.created="${BUILD_DATE}" \
26+
org.opencontainers.image.revision="${VCS_REF}" \
27+
org.opencontainers.image.url="${VCS_URL}" \
28+
org.opencontainers.image.title="webconsole" \
29+
org.opencontainers.image.description="Aether 5G Core WEBCONSOLE Network Function" \
30+
org.opencontainers.image.authors="Aether SD-Core <dev@lists.aetherproject.org>" \
31+
org.opencontainers.image.vendor="Aether Project" \
32+
org.opencontainers.image.licenses="Apache-2.0" \
33+
org.opencontainers.image.documentation="https://docs.sd-core.aetherproject.org/"
3334

3435
ARG DEBUG_TOOLS
3536

Makefile

Lines changed: 171 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,201 @@
1+
# SPDX-FileCopyrightText: 2026 Intel Corporation
12
# SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
23
# Copyright 2019 free5GC.org
34
#
45
# SPDX-License-Identifier: Apache-2.0
56
#
7+
#
8+
9+
PROJECT_NAME := webui
10+
VERSION ?= $(shell cat ./VERSION 2>/dev/null || echo "dev")
611

12+
# Extract minimum Go version from go.mod file
13+
GOLANG_MINIMUM_VERSION ?= $(shell awk '/^go / {print $$2}' go.mod 2>/dev/null || echo "1.24")
714

8-
PROJECT_NAME := sdcore
9-
DOCKER_VERSION ?= $(shell cat ./VERSION)
15+
# Number of processors for parallel builds (Linux only)
16+
NPROCS := $(shell nproc)
1017

11-
## Docker related
18+
## Docker configuration
1219
DOCKER_REGISTRY ?=
1320
DOCKER_REPOSITORY ?=
14-
DOCKER_TAG ?= ${DOCKER_VERSION}
15-
DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${PROJECT_NAME}:${DOCKER_TAG}
21+
DOCKER_TAG ?= $(VERSION)
22+
DOCKER_IMAGE_PREFIX ?= 5gc-
23+
DOCKER_IMAGENAME := $(DOCKER_REGISTRY)$(DOCKER_REPOSITORY)$(DOCKER_IMAGE_PREFIX)$(PROJECT_NAME):$(DOCKER_TAG)
1624
DOCKER_BUILDKIT ?= 1
17-
DOCKER_BUILD_ARGS ?=
18-
19-
## Docker labels. Only set ref and commit date if committed
20-
DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
21-
DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
22-
DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
25+
DOCKER_BUILD_ARGS ?= --build-arg MAKEFLAGS=-j$(NPROCS)
26+
DOCKER_PULL ?= --pull
27+
28+
## Docker labels with better error handling
29+
DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url origin 2>/dev/null || echo "unknown")
30+
DOCKER_LABEL_VCS_REF ?= $(shell \
31+
echo "$${GIT_COMMIT:-$${GITHUB_SHA:-$${CI_COMMIT_SHA:-$(shell \
32+
if git rev-parse --git-dir > /dev/null 2>&1; then \
33+
git rev-parse HEAD 2>/dev/null; \
34+
else \
35+
echo "unknown"; \
36+
fi \
37+
)}}}")
2338
DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
2439

25-
DOCKER_TARGETS ?= webui
26-
27-
# https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target
28-
GO_BIN_PATH = bin
29-
GO_SRC_PATH = ./
30-
C_BUILD_PATH = build
31-
ROOT_PATH = $(shell pwd)
32-
33-
WEBCONSOLE = webconsole
40+
## Build configuration
41+
BINARY_NAME := $(PROJECT_NAME)
42+
UI_BINARY_NAME := webconsole-ui
43+
GO_PACKAGES ?= ./...
3444

35-
WEBCONSOLE_GO_FILES = $(shell find ./ -name "*.go" ! -name "*_test.go")
45+
## Directory configuration
46+
BIN_DIR := bin
47+
COVERAGE_DIR := .coverage
3648

37-
VERSION = $(shell git describe --tags)
38-
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
39-
WEBCONSOLE_COMMIT_HASH = $(shell git submodule status | grep $(WEBCONSOLE) | awk '{print $$(1)}' | cut -c1-8)
40-
WEBCONSOLE_COMMIT_TIME = $(shell git log --pretty="%ai" -1 | awk '{time=$$(1)"T"$$(2)"Z"; print time}')
49+
## Go build configuration
50+
GO_FILES := $(shell find . -name "*.go" ! -name "*_test.go" 2>/dev/null)
4151

42-
.PHONY: $(NF) clean docker-build docker-push
52+
## Tool versions (for reproducible builds)
53+
GOLANGCI_LINT_VERSION ?= latest
4354

44-
.DEFAULT_GOAL: nfs
55+
# Default target
56+
.DEFAULT_GOAL := help
4557

46-
all: $(WEBCONSOLE)
58+
## Help target
59+
help: ## Show this help message
60+
@echo "Available targets:"
61+
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*##/ { printf " %-20s %s\n", $$1, $$2 }' $(MAKEFILE_LIST) | sort
4762

48-
$(WEBCONSOLE): $(GO_BIN_PATH)/$(WEBCONSOLE)
63+
## Build targets
64+
build: $(BIN_DIR)/$(BINARY_NAME) ## Build binary
4965

50-
$(GO_BIN_PATH)/$(WEBCONSOLE): server.go $(WEBCONSOLE_GO_FILES)
51-
@echo "Start building $(@F)...."
52-
go build -o $(ROOT_PATH)/$@ ./server.go
66+
all: build ## Build binary (alias for compatibility)
5367

54-
vpath %.go $(addprefix $(GO_SRC_PATH)/, $(GO_NF))
68+
$(BIN_DIR)/$(BINARY_NAME): $(GO_FILES) | bin-dir
69+
@echo "Building $(BINARY_NAME)..."
70+
@CGO_ENABLED=0 go build -o $@ .
5571

56-
webconsole-ui: $(GO_BIN_PATH)/$(WEBCONSOLE)-ui
72+
webconsole-ui: $(BIN_DIR)/$(UI_BINARY_NAME)
5773

58-
$(GO_BIN_PATH)/$(WEBCONSOLE)-ui: server.go $(WEBCONSOLE_GO_FILES)
59-
@echo "Start building $(@F)...."
60-
go build --tags ui -o $(ROOT_PATH)/$@ ./server.go
74+
$(BIN_DIR)/$(UI_BINARY_NAME): $(GO_FILES) | bin-dir
75+
@echo "Building $(UI_BINARY_NAME)..."
76+
@CGO_ENABLED=0 go build --tags ui -o $@ .
6177

62-
clean:
63-
rm -rf $(ROOT_PATH)/$(GO_BIN_PATH)/$(WEBCONSOLE)
64-
rm -rf $(ROOT_PATH)/$(GO_BIN_PATH)/$(WEBCONSOLE)-ui
78+
bin-dir: ## Create binary directory
79+
@mkdir -p $(BIN_DIR)
6580

66-
docker-build:
81+
## Docker targets
82+
docker-build: ## Build Docker image
83+
@echo "Building Docker image: $(DOCKER_IMAGENAME)"
6784
@go mod vendor
68-
for target in $(DOCKER_TARGETS); do \
69-
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build $(DOCKER_BUILD_ARGS) \
70-
--target $$target \
71-
--tag ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}5gc-$$target:${DOCKER_TAG} \
72-
--build-arg org_label_schema_version="${DOCKER_VERSION}" \
73-
--build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
74-
--build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
75-
--build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
76-
--build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
77-
. \
78-
|| exit 1; \
79-
done
80-
rm -rf vendor
81-
82-
docker-push:
83-
for target in $(DOCKER_TARGETS); do \
84-
docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}5gc-$$target:${DOCKER_TAG}; \
85-
done
86-
87-
.coverage:
88-
rm -rf $(CURDIR)/.coverage
89-
mkdir -p $(CURDIR)/.coverage
90-
91-
test: .coverage
92-
docker run --rm -v $(CURDIR):/webconsole -w /webconsole golang:latest \
85+
@DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build $(DOCKER_PULL) $(DOCKER_BUILD_ARGS) \
86+
--build-arg VERSION="$(VERSION)" \
87+
--build-arg VCS_URL="$(DOCKER_LABEL_VCS_URL)" \
88+
--build-arg VCS_REF="$(DOCKER_LABEL_VCS_REF)" \
89+
--build-arg BUILD_DATE="$(DOCKER_LABEL_BUILD_DATE)" \
90+
--tag $(DOCKER_IMAGENAME) \
91+
. \
92+
|| exit 1
93+
@rm -rf vendor
94+
95+
docker-push: ## Push Docker image to registry
96+
@echo "Pushing Docker image: $(DOCKER_IMAGENAME)"
97+
@docker push $(DOCKER_IMAGENAME)
98+
99+
docker-clean: ## Remove local Docker image
100+
@echo "Cleaning local Docker image..."
101+
@docker rmi $(DOCKER_IMAGENAME) 2>/dev/null || true
102+
103+
## Testing targets
104+
$(COVERAGE_DIR): ## Create coverage directory
105+
@mkdir -p $(COVERAGE_DIR)
106+
107+
test: $(COVERAGE_DIR) ## Run unit tests with coverage
108+
@echo "Running unit tests..."
109+
@docker run --rm \
110+
-v $(CURDIR):/$(PROJECT_NAME) \
111+
-w /$(PROJECT_NAME) \
112+
golang:$(GOLANG_MINIMUM_VERSION) \
93113
go test \
114+
-race \
94115
-failfast \
95-
-coverprofile=.coverage/coverage-unit.txt \
116+
-coverprofile=$(COVERAGE_DIR)/coverage-unit.txt \
96117
-covermode=atomic \
97118
-v \
98-
./ ./...
119+
$(GO_PACKAGES)
120+
121+
test-local: $(COVERAGE_DIR) ## Run unit tests locally (without Docker)
122+
@echo "Running unit tests locally..."
123+
@go test \
124+
-race \
125+
-failfast \
126+
-coverprofile=$(COVERAGE_DIR)/coverage-unit.txt \
127+
-covermode=atomic \
128+
-v \
129+
$(GO_PACKAGES)
130+
131+
## Code quality targets
132+
fmt: ## Format Go code
133+
@echo "Formatting Go code..."
134+
@go fmt ./...
135+
136+
lint: ## Run linter
137+
@echo "Running linter..."
138+
@docker run --rm \
139+
-v $(CURDIR):/app \
140+
-w /app \
141+
golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) \
142+
golangci-lint run -v --config /app/.golangci.yml
143+
144+
lint-local: ## Run linter locally (without Docker)
145+
@echo "Running linter locally..."
146+
@golangci-lint run -v --config .golangci.yml
147+
148+
check-reuse: ## Check REUSE compliance
149+
@echo "Checking REUSE compliance..."
150+
@docker run --rm \
151+
-v $(CURDIR):/$(PROJECT_NAME) \
152+
-w /$(PROJECT_NAME) \
153+
omecproject/reuse-verify:latest \
154+
reuse lint
155+
156+
check: fmt lint check-reuse ## Run all code quality checks
157+
158+
## Utility targets
159+
clean: ## Clean build artifacts
160+
@echo "Cleaning build artifacts..."
161+
@rm -rf $(BIN_DIR)
162+
@rm -rf $(COVERAGE_DIR)
163+
@rm -rf vendor
164+
@docker system prune -f --filter label=org.opencontainers.image.source="$(DOCKER_LABEL_VCS_URL)" 2>/dev/null || true
165+
166+
print-version: ## Print current version
167+
@echo $(VERSION)
168+
169+
env: ## Print environment variables
170+
@echo "PROJECT_NAME=$(PROJECT_NAME)"
171+
@echo "VERSION=$(VERSION)"
172+
@echo "GOLANG_MINIMUM_VERSION=$(GOLANG_MINIMUM_VERSION)"
173+
@echo "BINARY_NAME=$(BINARY_NAME)"
174+
@echo "DOCKER_REGISTRY=$(DOCKER_REGISTRY)"
175+
@echo "DOCKER_REPOSITORY=$(DOCKER_REPOSITORY)"
176+
@echo "DOCKER_IMAGE_PREFIX=$(DOCKER_IMAGE_PREFIX)"
177+
@echo "DOCKER_TAG=$(DOCKER_TAG)"
178+
@echo "DOCKER_IMAGENAME=$(DOCKER_IMAGENAME)"
179+
@echo "DOCKER_LABEL_VCS_URL=$(DOCKER_LABEL_VCS_URL)"
180+
@echo "DOCKER_LABEL_VCS_REF=$(DOCKER_LABEL_VCS_REF)"
181+
@echo "NPROCS=$(NPROCS)"
182+
183+
## Phony targets
184+
.PHONY: all \
185+
bin-dir \
186+
build \
187+
check \
188+
check-reuse \
189+
clean \
190+
docker-build \
191+
docker-clean \
192+
docker-push \
193+
env \
194+
fmt \
195+
help \
196+
lint \
197+
lint-local \
198+
print-version \
199+
test \
200+
test-local \
201+
webconsole-ui

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1-dev
1+
2.1.0

0 commit comments

Comments
 (0)