Skip to content

Commit 8c94189

Browse files
authored
Merge pull request #142 from ANDDEV-OSS/&DEV/OCI_Container_Support
Support for clair v4 and OCI
2 parents 31e2387 + 00fbef3 commit 8c94189

28 files changed

+1670
-366
lines changed

.devcontainer/Dockerfile.devcontainer

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use a Go development container as the base image
2+
FROM mcr.microsoft.com/devcontainers/go:1-1.23-bookworm
3+
4+
# Install Docker dependencies and tools
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
ca-certificates \
8+
curl \
9+
gnupg && \
10+
# Create keyrings directory and download Docker GPG key
11+
install -m 0755 -d /etc/apt/keyrings && \
12+
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc && \
13+
chmod a+r /etc/apt/keyrings/docker.asc && \
14+
# Add Docker repository
15+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
16+
$(. /etc/os-release && echo "${VERSION_CODENAME}") stable" | \
17+
tee /etc/apt/sources.list.d/docker.list > /dev/null && \
18+
# Update and install Docker
19+
apt-get update && \
20+
apt-get install -y --no-install-recommends \
21+
docker-ce \
22+
docker-ce-cli \
23+
containerd.io \
24+
docker-buildx-plugin \
25+
docker-compose-plugin

.devcontainer/devcontainer.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go
3+
{
4+
"name": "Go",
5+
"dockerComposeFile": "../docker-compose.devcontainers.yml",
6+
"service": "clair-scanner",
7+
"workspaceFolder": "/workspaces/clair-scanner",
8+
"shutdownAction": "stopCompose",
9+
"customizations": {
10+
"extensions": [
11+
"ms-azuretools.vscode-docker"
12+
],
13+
"vscode": {
14+
"extensions": [
15+
"ms-azuretools.vscode-docker",
16+
"ms-vscode.makefile-tools",
17+
"golang.Go"
18+
]
19+
}
20+
},
21+
"postCreateCommand": {
22+
"configure-docker": "sudo chown $(whoami) /var/run/docker.sock",
23+
"docker-pull": "docker pull python:bullseye"
24+
}
25+
// Features to add to the dev container. More info: https://containers.dev/features.
26+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
27+
// "forwardPorts": [],
28+
// Use 'postCreateCommand' to run commands after the container is created.
29+
// "postCreateCommand": "go version",
30+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
31+
// "remoteUser": "root"
32+
}
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build, Test, and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+-prerelease-[0-9]+'
7+
- '[0-9]+.[0-9]+.[0-9]+' # Trigger on semantic version tags (e.g., v1.0.0)
8+
9+
workflow_dispatch: # Allow manual trigger
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
goos: [linux, windows, darwin]
17+
goarch: [amd64, arm64]
18+
steps:
19+
# Step 1: Checkout code
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
# Step 2: Set up Go
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: 1.22
28+
29+
# Step 3: Run Go tests
30+
- name: Run Go tests
31+
run: |
32+
go test ./... -v
33+
34+
# Step 4: Build the Go app for each platform
35+
- name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
36+
env:
37+
GOOS: ${{ matrix.goos }}
38+
GOARCH: ${{ matrix.goarch }}
39+
run: |
40+
mkdir -p dist
41+
output_name=clair-scanner_${GOOS}-${GOARCH}
42+
[ "$GOOS" = "windows" ] && output_name+=".exe"
43+
go build -o dist/$output_name
44+
45+
# Step 5: Upload binaries as artifacts for inspection
46+
- name: Upload binaries
47+
uses: actions/upload-artifact@v3
48+
with:
49+
name: clair-scanner_${{ matrix.goos }}_${{ matrix.goarch }}
50+
path: dist/
51+
52+
release:
53+
needs: build
54+
runs-on: ubuntu-latest
55+
steps:
56+
# Step 1: Checkout code
57+
- name: Checkout code
58+
uses: actions/checkout@v3
59+
60+
# Step 2: Download build artifacts
61+
- name: Download binaries
62+
uses: actions/download-artifact@v3
63+
with:
64+
path: dist/
65+
66+
- name: Determine if Prerelease
67+
id: prerelease-check
68+
run: |
69+
if [[ "${GITHUB_REF_NAME}" =~ -prerelease-[0-9]+$ ]]; then
70+
echo "is_prerelease=true" >> $GITHUB_ENV
71+
else
72+
echo "is_prerelease=false" >> $GITHUB_ENV
73+
fi
74+
75+
# Step 3: Create GitHub Release
76+
- name: Create Release
77+
uses: softprops/action-gh-release@v2
78+
env:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
with:
81+
tag_name: ${{ github.ref_name }}
82+
name: Release ${{ github.ref_name }}
83+
body: |
84+
Automated release for ${{ github.ref_name }}.
85+
draft: false
86+
prerelease: ${{ env.is_prerelease }}
87+
88+
# Step 4: Upload binaries to the release
89+
- name: Upload Release Assets
90+
run: |
91+
pwd
92+
ls -alh dist/
93+
find dist/ -type f -print0 | while IFS= read -r -d '' file; do
94+
echo "Uploading: $file"
95+
gh release upload "${{ github.ref_name }}" "$file"
96+
done
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
vendor
22
clair-scanner
33
*.out
4-
dist
4+
dist
5+
clair_report.json
6+
clair-scanner_*
7+
report.txt

.travis.yml

-30
This file was deleted.

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch main.go",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}",
13+
"args": ["--clair", "http://localhost:8080", "--threshold=High", "--report", "clair_report.json", "python:bullseye"]
14+
}
15+
]
16+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"makefile.configureOnOpen": false
3+
}

Makefile

+17-12
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ build:
1010
installLocal:
1111
CGO_ENABLED=0 go install
1212

13-
docker:
14-
@cd docker && \
15-
docker build -t golang-cross-compile .
16-
17-
cross: docker
18-
docker run -ti --rm -e CGO_ENABLED=0 -v $(CURDIR):/gopath/src/clair-scanner -w /gopath/src/clair-scanner golang-cross-compile gox -osarch="darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"
13+
cross:
14+
@archs="linux/386 linux/amd64 linux/arm linux/arm64 darwin/amd64 darwin/arm64"; \
15+
for arch in $$archs; do \
16+
GOOS=$$(echo $$arch | cut -d'/' -f1); \
17+
GOARCH=$$(echo $$arch | cut -d'/' -f2); \
18+
echo "Building for $$GOOS/$$GOARCH"; \
19+
CMD="GOOS=$$GOOS GOARCH=$$GOARCH go build -o clair-scanner_$${GOOS}_$${GOARCH}"; \
20+
eval $$CMD; \
21+
done
1922

2023
clean:
2124
rm -rf dist
@@ -30,8 +33,8 @@ test:
3033
go test
3134

3235
pull:
33-
docker pull alpine:3.5
34-
docker pull debian:jessie
36+
docker pull alpine:3.20
37+
docker pull debian:bookworm
3538

3639
db:
3740
docker run -p 5432:5432 -d --name db arminc/clair-db:latest
@@ -41,10 +44,12 @@ clair:
4144
docker run -p 6060:6060 --link db:postgres -d --name clair arminc/clair-local-scan:latest
4245
@sleep 5
4346

44-
integration: pull db clair
45-
go test -v -covermode=count -coverprofile=coverage.out -ip $(shell ipconfig getifaddr en0) -tags integration
47+
#integration: pull db clair
48+
integration:
49+
go test -v -covermode=count -coverprofile=coverage.out -ip 127.0.0.1 -tags integration
4650

47-
integrationlinux: pull db clair
48-
go test -v -covermode=count -coverprofile=coverage.out -ip $(shell ifconfig docker0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1) -tags integration
51+
#integrationlinux: pull db clair
52+
integration:
53+
go test -v -covermode=count -coverprofile=coverage.out -ip 127.0.0.1 -tags integration
4954

5055
release: integrationlinux build cross

0 commit comments

Comments
 (0)