Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 032f52a

Browse files
committed
sanitize repo
Change-Id: I0b20007d89302b52155198bb266b6d7f7b2c36dd
1 parent b4294e3 commit 032f52a

File tree

6 files changed

+102
-2
lines changed

6 files changed

+102
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ dkms.conf
7272

7373
# Go workspace file
7474
go.work
75+
76+
bin/

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ COPY ./main.go ./go.mod ./go.sum ./
1717
RUN go mod download
1818
RUN CGO_ENABLED=0 go build -o /go/bin/nat64 .
1919

20-
FROM registry.k8s.io/build-image/distroless-iptables:v0.5.1
20+
FROM registry.k8s.io/build-image/distroless-iptables:v0.6.2
2121
COPY --from=ebpf-builder --chown=root:root /go/src/app/bpf/nat64.o /bpf/nat64.o
2222
COPY --from=builder --chown=root:root /go/bin/nat64 /nat64
2323
CMD ["/nat64"]

Makefile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
REPO_ROOT:=${CURDIR}
2+
OUT_DIR=$(REPO_ROOT)/bin
3+
BINARY_NAME?=na64
4+
5+
# go1.9+ can autodetect GOROOT, but if some other tool sets it ...
6+
GOROOT:=
7+
# enable modules
8+
GO111MODULE=on
9+
# disable CGO by default for static binaries
10+
CGO_ENABLED=0
11+
export GOROOT GO111MODULE CGO_ENABLED
12+
13+
14+
test:
15+
CGO_ENABLED=1 go test -v -race -count 1 ./...
16+
17+
# code linters
18+
lint:
19+
hack/lint.sh
20+
21+
update:
22+
go mod tidy
23+
24+
# get image name from directory we're building
25+
IMAGE_NAME=nat64
26+
# docker image registry, default to upstream
27+
REGISTRY?=docker.io/aojea
28+
# tag based on date-sha
29+
TAG?=$(shell echo "$$(date +v%Y%m%d)-$$(git describe --always --dirty)")
30+
# the full image tag
31+
KNP_IMAGE?=$(REGISTRY)/$(IMAGE_NAME):$(TAG)
32+
PLATFORMS?=linux/amd64
33+
# PLATFORMS?=linux/amd64,linux/arm64
34+
.PHONY: ensure-buildx
35+
ensure-buildx:
36+
./hack/init-buildx.sh
37+
38+
image-build:
39+
docker buildx build . \
40+
--tag="${KNP_IMAGE}" \
41+
--load
42+
43+
image-push:
44+
docker buildx build . \
45+
--platform="${PLATFORMS}" \
46+
--tag="${KNP_IMAGE}" \
47+
--push
48+
49+
.PHONY: release # Build a multi-arch docker image
50+
release: ensure-buildx image-push

hack/init-buildx.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2020 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit -o nounset -o pipefail
17+
18+
# We can skip setup if the current builder already has multi-arch
19+
# AND if it isn't the docker driver, which doesn't work
20+
current_builder="$(docker buildx inspect)"
21+
# linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
22+
if ! grep -q "^Driver: docker$" <<<"${current_builder}" && \
23+
grep -q "linux/amd64" <<<"${current_builder}" && \
24+
grep -q "linux/arm64" <<<"${current_builder}"; then
25+
exit 0
26+
fi
27+
28+
# Ensure qemu is in binfmt_misc
29+
# Docker desktop already has these in versions recent enough to have buildx
30+
# We only need to do this setup on linux hosts
31+
if [ "$(uname)" == 'Linux' ]; then
32+
# NOTE: this is pinned to a digest for a reason!
33+
docker run --rm --privileged tonistiigi/binfmt:qemu-v7.0.0-28@sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55 --install all
34+
fi
35+
36+
# Ensure we use a builder that can leverage it (the default on linux will not)
37+
docker buildx rm knp-builder || true
38+
docker buildx create --use --name=knp-builder

hack/lint.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
8+
9+
cd $REPO_ROOT
10+
docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.56.2 golangci-lint run -v

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func main() {
117117
http.Handle("/metrics", promhttp.Handler())
118118
go func() {
119119
log.Printf("starting metrics server listening in %s", metricsBindAddress)
120-
http.ListenAndServe(metricsBindAddress, nil)
120+
http.ListenAndServe(metricsBindAddress, nil) // nolint:errcheck
121121
}()
122122

123123
// Remove resource limits for kernels <5.11.

0 commit comments

Comments
 (0)