diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index b735373..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 066b2d9..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3f07e4c..e432bba 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -26,21 +26,12 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: set up Docker buildx id: buildx uses: docker/setup-buildx-action@v3 with: version: latest - - name: builder instance name - run: echo ${{ steps.buildx.outputs.name }} - - - name: available platforms - run: echo ${{ steps.buildx.outputs.platforms }} - - name: decide on tag id: prep run: | @@ -67,7 +58,6 @@ jobs: echo "tags=${TAGS}" >> $GITHUB_OUTPUT - name: login to DockerHub - if: ${{ github.event_name != 'pull_request' }} uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -77,8 +67,10 @@ jobs: id: docker_build uses: docker/build-push-action@v5 with: - push: ${{ github.event_name != 'pull_request' }} - platforms: linux/amd64,linux/arm64 + push: true + platforms: | + linux/amd64 + linux/arm64 tags: ${{ steps.prep.outputs.tags }} - name: image digest diff --git a/Dockerfile b/Dockerfile index fd1a414..0baab36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,29 @@ -# syntax = docker/dockerfile:experimental - -# -# ----- Go Builder Image ------ -# -FROM golang:1.20-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS builder # curl git bash RUN apk add --no-cache curl git bash make -# + # ----- build and test ----- -# FROM builder as build + # set working directorydoc RUN mkdir -p /go/src/app WORKDIR /go/src/app + # load dependency +COPY Makefile . COPY go.mod . COPY go.sum . -RUN --mount=type=cache,target=$GOPATH/pkg/mod go mod download +RUN --mount=type=cache,target=/root/.cache/go-build go mod download + # copy sources COPY . . + +# build arguments (passed from buildx) +ARG TARGETOS +ARG TARGETARCH + # build -RUN make binary +RUN --mount=type=cache,target=/root/.cache/go-build make binary TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} # # ------ release Docker image ------ diff --git a/Makefile b/Makefile index aba8abf..d3bb2b9 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,11 @@ PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...)) TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \ '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \ $(PKGS)) -BIN = $(CURDIR)/.bin -BINARY = kubeip + +BIN := $(CURDIR)/.bin +BINARY = kubeip +TARGETOS := $(or $(TARGETOS), linux) +TARGETARCH := $(or $(TARGETARCH), amd64) GO = go TIMEOUT = 15 @@ -17,16 +20,16 @@ V = 0 Q = $(if $(filter 1,$V),,@) M = $(shell printf "\033[34;1m▶\033[0m") -export GO111MODULE=on export CGO_ENABLED=0 export GOPROXY=https://proxy.golang.org - +export GOOS=$(TARGETOS) +export GOARCH=$(TARGETARCH) .PHONY: all all: fmt lint binary .PHONY: binary -binary: $(BIN) ; $(info $(M) building executable...) @ ## Build program binary +binary: $(BIN) ; $(info $(M) building $(GOOS)/$(GOARCH) binary...) @ ## Build program binary $Q $(GO) build \ -tags release \ -ldflags '-X main.version=$(VERSION) -X main.buildDate=$(DATE)' \ diff --git a/main.go b/main.go index 0d9e8fb..5dbb7c1 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ var buildDate string func main() { config, _ = cfg.NewConfig() + logrus.Info("kubeIP version: ", version) logrus.Info(config) cluster, err := kipcompute.ClusterName() if err != nil {