Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cicd/speedup #112

Merged
merged 3 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

17 changes: 0 additions & 17 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

16 changes: 4 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 }}
Expand All @@ -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
Expand Down
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 ------
Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@ 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
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)' \
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down