From e49035663347144dd45e9bb4cb506973f7aab4c3 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Tue, 24 Sep 2024 15:36:52 +0200 Subject: [PATCH] change name from pluralctl to plrlctl (#547) * change name from pluralctl to plrlctl * update GoReleaser * add plrctl Dockerfile * fix --- .goreleaser.yaml | 53 ++++++++++++++++++++++++------ Dockerfile | 10 +++--- Makefile | 26 +++++++++++---- cmd/{pluralctl => plrlctl}/main.go | 2 +- dockerfiles/plrlctl/Dockerfile | 47 ++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 23 deletions(-) rename cmd/{pluralctl => plrlctl}/main.go (98%) create mode 100644 dockerfiles/plrlctl/Dockerfile diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 61a99516..d7ec0787 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -28,9 +28,42 @@ builds: ldflags: - -s - -w - - -X "github.com/pluralsh/plural-cli/cmd/plural.Version={{.Version}}" - - -X "github.com/pluralsh/plural-cli/cmd/plural.Commit={{.Commit}}" - - -X "github.com/pluralsh/plural-cli/cmd/plural.Date={{.Date}}" + - -X "github.com/pluralsh/plural-cli/pkg/common.Version={{.Version}}" + - -X "github.com/pluralsh/plural-cli/pkg/common.Commit={{.Commit}}" + - -X "github.com/pluralsh/plural-cli/pkg/common.Date={{.Date}}" + - -X "github.com/pluralsh/plural-cli/pkg/scm.GitlabClientSecret={{.Env.GITLAB_CLIENT_SECRET}}" + binary: plural + # Do not embed UI into linux/arm64 and windows/arm64 binaries + overrides: + - goos: linux + goarch: arm64 + tags: [linux] + env: + - CGO_ENABLED=0 + - goos: windows + goarch: arm64 + tags: [windows] + env: + - CGO_ENABLED=0 + - id: plrlctl + main: ./cmd/plrlctl + targets: + - linux_amd64 + - linux_arm64 + - windows_amd64 + # TODO: Re-enable once fixed + # Ref: https://github.com/golang/go/issues/51019 + # - windows_arm64 + - darwin_amd64 + - darwin_arm64 + env: + - CGO_ENABLED=0 + ldflags: + - -s + - -w + - -X "github.com/pluralsh/plural-cli/pkg/common.Version={{.Version}}" + - -X "github.com/pluralsh/plural-cli/pkg/common.Commit={{.Commit}}" + - -X "github.com/pluralsh/plural-cli/pkg/common.Date={{.Date}}" - -X "github.com/pluralsh/plural-cli/pkg/scm.GitlabClientSecret={{.Env.GITLAB_CLIENT_SECRET}}" binary: plural # Do not embed UI into linux/arm64 and windows/arm64 binaries @@ -70,13 +103,13 @@ archives: {{- title .Os }}_ {{- if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} -# - id: plural-cli-console -# builds: [ plural-cli-console ] -# name_template: >- -# {{ .ProjectName }}_console_{{ .Version }}_ -# {{- title .Os }}_ -# {{- if eq .Arch "386" }}i386 -# {{- else }}{{ .Arch }}{{ end }} + - id: plrlctl + builds: [plrlctl] + name_template: >- + {{ .ProjectName }}_{{ .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} checksum: name_template: 'checksums.txt' diff --git a/Dockerfile b/Dockerfile index 97dd53ea..c741e711 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.10 as user +FROM ubuntu:22.10 AS user # Create a nonroot user for final image RUN useradd -u 10001 nonroot @@ -26,12 +26,12 @@ ARG TARGETARCH RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \ go build -ldflags '-s -w \ - -X "github.com/pluralsh/plural-cli/cmd/plural.Version=${APP_VSN}" \ - -X "github.com/pluralsh/plural-cli/cmd/plural.Commit=${APP_COMMIT}" \ - -X "github.com/pluralsh/plural-cli/cmd/plural.Date=${APP_DATE}"' \ + -X "github.com/pluralsh/plural-cli/pkg/common.Version=${APP_VSN}" \ + -X "github.com/pluralsh/plural-cli/pkg/common.Commit=${APP_COMMIT}" \ + -X "github.com/pluralsh/plural-cli/pkg/common.Date=${APP_DATE}"' \ -o plural ./cmd/plural -FROM golang:1.20-alpine3.17 +FROM golang:1.22-alpine3.19 AS final WORKDIR / diff --git a/Makefile b/Makefile index 0fe2bfcc..8cae73aa 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ include $(ROOT_DIRECTORY)/hack/include/build.mk GCP_PROJECT ?= pluralsh APP_NAME ?= plural-cli +APP_CTL_NAME ?= plrlctl APP_VSN ?= $(shell git describe --tags --always --dirty) APP_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%S%z") BUILD ?= $(shell git rev-parse --short HEAD) @@ -16,9 +17,9 @@ GOLANG_CROSS_VERSION ?= v1.22.0 PACKAGE ?= github.com/pluralsh/plural BASE_LDFLAGS ?= -s -w LDFLAGS ?= $(BASE_LDFLAGS) $\ - -X "$(PACKAGE)/cmd/plural.Version=$(APP_VSN)" $\ - -X "$(PACKAGE)/cmd/plural.Commit=$(BUILD)" $\ - -X "$(PACKAGE)/cmd/plural.Date=$(APP_DATE)" $\ + -X "$(PACKAGE)/pkg/common.Version=$(APP_VSN)" $\ + -X "$(PACKAGE)/pkg/common.Commit=$(BUILD)" $\ + -X "$(PACKAGE)/pkg/common.Date=$(APP_DATE)" $\ -X "$(PACKAGE)/pkg/scm.GitlabClientSecret=${GITLAB_CLIENT_SECRET}" $\ -X "$(PACKAGE)/pkg/scm.BitbucketClientSecret=${BITBUCKET_CLIENT_SECRET}" WAILS_TAGS ?= desktop,production,ui,debug @@ -26,7 +27,7 @@ WAILS_BINDINGS_TAGS ?= bindings,generate WAILS_BINDINGS_BINARY_NAME ?= wailsbindings TAGS ?= $(WAILS_TAGS) OUTFILE ?= plural.o -OUTCTLFILE ?= pluralctl.o +OUTCTLFILE ?= plrlctl.o GOBIN ?= go env GOBIN # Targets to run before other targets @@ -41,7 +42,7 @@ git-push: .PHONY: install install: go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/plural ./cmd/plural - go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/pluralctl ./cmd/pluralctl + go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/plrlctl ./cmd/plrlctl .PHONY: build-cli build-cli: ## Build a CLI binary for the host architecture without embedded UI @@ -49,7 +50,7 @@ build-cli: ## Build a CLI binary for the host architecture without embedded UI .PHONY: build-ctl build-ctl: ## Build a CLI binary for the fleet management - go build -ldflags='$(LDFLAGS)' -o $(OUTCTLFILE) ./cmd/plural + go build -ldflags='$(LDFLAGS)' -o $(OUTCTLFILE) ./cmd/plrlctl .PHONY: build-cli-ui build-cli-ui: $(PRE) generate-bindings ## Build a CLI binary for the host architecture with embedded UI @@ -77,7 +78,7 @@ generate-bindings: build-web ## Generate backend bindings for the embedded UI .PHONY: release release: GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) ./cmd/plural - GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTCTLFILE) ./cmd/pluralctl + GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTCTLFILE) ./cmd/plrlctl .PHONY: goreleaser goreleaser: @@ -102,6 +103,17 @@ build: ## Build the Docker image -t gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN) \ -t $(DKR_HOST)/plural/$(APP_NAME):$(APP_VSN) . +.PHONY: build-ctl +build-ctl: ## Build the plrctl Docker image + docker build --build-arg APP_NAME=$(APP_CTL_NAME) \ + --build-arg APP_VSN=$(APP_VSN) \ + --build-arg APP_DATE=$(APP_DATE) \ + --build-arg APP_COMMIT=$(BUILD) \ + -t $(APP_CTL_NAME):$(APP_VSN) \ + -t $(APP_CTL_NAME):latest \ + -t gcr.io/$(GCP_PROJECT)/$(APP_CTL_NAME):$(APP_VSN) \ + -t $(DKR_HOST)/plural/$(APP_CTL_NAME):$(APP_VSN) -f dockerfiles/plrlctl/Dockerfile . + .PHONY: build-cloud build-cloud: ## build the cloud docker image docker build --build-arg APP_NAME=$(APP_NAME) \ diff --git a/cmd/pluralctl/main.go b/cmd/plrlctl/main.go similarity index 98% rename from cmd/pluralctl/main.go rename to cmd/plrlctl/main.go index 9bee1fea..f2ef0936 100644 --- a/cmd/pluralctl/main.go +++ b/cmd/plrlctl/main.go @@ -25,7 +25,7 @@ import ( "github.com/pluralsh/plural-cli/pkg/utils" ) -const ApplicationName = "pluralctl" +const ApplicationName = "plrlctl" type Plural struct { client.Plural diff --git a/dockerfiles/plrlctl/Dockerfile b/dockerfiles/plrlctl/Dockerfile new file mode 100644 index 00000000..7fe58ad8 --- /dev/null +++ b/dockerfiles/plrlctl/Dockerfile @@ -0,0 +1,47 @@ +FROM ubuntu:22.10 AS user + +# Create a nonroot user for final image +RUN useradd -u 10001 nonroot + +FROM golang:1.22-alpine3.19 AS builder + +WORKDIR /workspace + +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download + +# Copy the go source +COPY cmd/ cmd/ +COPY pkg/ pkg/ + +# Build +ARG APP_VSN +ARG APP_COMMIT +ARG APP_DATE +ARG TARGETARCH + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \ + go build -ldflags '-s -w \ + -X "github.com/pluralsh/plural-cli/pkg/common.Version=${APP_VSN}" \ + -X "github.com/pluralsh/plural-cli/pkg/common.Commit=${APP_COMMIT}" \ + -X "github.com/pluralsh/plural-cli/pkg/common.Date=${APP_DATE}"' \ + -o plrlctl ./cmd/plrlctl + +FROM golang:1.22-alpine3.19 AS final + +WORKDIR / + +RUN apk update && apk add --no-cache git build-base + +# Copy nonroot user and switch to it +COPY --from=user /etc/passwd /etc/passwd +USER nonroot + +COPY --chown=nonroot --from=builder /workspace/plrlctl /go/bin/ +RUN chmod a+x /go/bin/plrlctl + +ENTRYPOINT ["/go/bin/plrlctl"]