diff --git a/.goreleaser.yml b/.goreleaser.yml index 644f944..f4a0664 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -43,7 +43,7 @@ dockers: - image_templates: - "ghcr.io/buttahtoast/{{ .ProjectName }}:{{ .Tag }}" - "ghcr.io/buttahtoast/{{ .ProjectName }}:latest" - dockerfile: Dockerfile + dockerfile: Dockerfile.goreleaser goos: linux goarch: amd64 use: buildx @@ -87,7 +87,7 @@ dockers: - image_templates: - "ghcr.io/buttahtoast/{{ .ProjectName }}-cmp:{{ .Tag }}" - "ghcr.io/buttahtoast/{{ .ProjectName }}-cmp:latest" - dockerfile: argocd-cmp/Dockerfile + dockerfile: argocd-cmp/Dockerfile.goreleaser goos: linux goarch: amd64 use: buildx diff --git a/Dockerfile.argo-cmp b/Dockerfile.argo-cmp index 50fa168..43a0f50 100644 --- a/Dockerfile.argo-cmp +++ b/Dockerfile.argo-cmp @@ -1,7 +1,21 @@ -FROM bash:5 -COPY subst /subst -COPY argocd-cmp/cmp.yaml /home/argocd/cmp-server/config/plugin.yaml -RUN adduser -H -D -s /bin/bash -G nobody -u 999 argocd -USER argocd:nobody -#ENTRYPOINT ["/usr/local/bin/subst"] +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19 as builder + +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + +WORKDIR /app/ +ADD . . +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s -X github.com/buttahtoast/subst/subst/cmd.Version={{ .Tag }} -X github.com/buttahtoast/subst/subst/cmd.GitCommit={{ .Commit }} -X github.com/buttahtoast/subst/subst/cmd.BuildDate={{ .Date }}" -o subst ./subst/main.go + +FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch +ENV ARGOCD_EXEC_TIMEOUT=90s +COPY --from=builder /app/subst /subst +COPY cmp.yaml /home/argocd/cmp-server/config/plugin.yaml +COPY entrypoint.sh /entrypoint.sh +RUN adduser -H -D -s /bin/bash -G nobody -u 999 argocd && \ + chmod +x /entrypoint.sh +USER argocd:nobody +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile.goreleaser similarity index 100% rename from Dockerfile rename to Dockerfile.goreleaser diff --git a/Makefile b/Makefile index 0916f11..28bec00 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,26 @@ projectname?=subst K3S_NAME ?= subst-cmp -VERSION ?= $$(git describe --abbrev=0 --tags --match "v*") -IMG ?= ghcr.io/buttahtoast/subst:$(VERSION) -PLUGIN_IMG ?= ghcr.io/buttahtoast/subst-cmp:$(VERSION) - # Get information about git current status +GOOS ?= $(shell go env GOOS) +GOARCH ?= $(shell go env GOARCH) GIT_HEAD_COMMIT ?= $$(git rev-parse --short HEAD) GIT_TAG_COMMIT ?= $$(git rev-parse --short $(VERSION)) GIT_MODIFIED_1 ?= $$(git diff $(GIT_HEAD_COMMIT) $(GIT_TAG_COMMIT) --quiet && echo "" || echo ".dev") GIT_MODIFIED_2 ?= $$(git diff --quiet && echo "" || echo ".dirty") GIT_MODIFIED ?= $$(echo "$(GIT_MODIFIED_1)$(GIT_MODIFIED_2)") GIT_REPO ?= $$(git config --get remote.origin.url) -BUILD_DATE ?= $$(git log -1 --format="%at" | xargs -I{} date -d @{} +%Y-%m-%dT%H:%M:%S) +BUILD_DATE ?= $(shell git log -1 --format="%at" | xargs -I{} sh -c 'if [ "$(shell uname)" = "Darwin" ]; then date -r {} +%Y-%m-%dT%H:%M:%S; else date -d @{} +%Y-%m-%dT%H:%M:%S; fi') + +# Docker Build +DOCKER_CLI_EXPERIMENTAL ?= enabled +LOCAL_PLATFORM := linux/$(GOARCH) +# Define platforms in cli if multiple needed linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x +TARGET_PLATFORMS ?= $(LOCAL_PLATFORM) + +VERSION ?= $$(git describe --abbrev=0 --tags --match "v*") +IMG ?= ghcr.io/buttahtoast/subst:$(VERSION) +PLUGIN_IMG ?= ghcr.io/buttahtoast/subst-cmp:$(VERSION) default: help @@ -58,14 +66,24 @@ PHONY: lint lint: ## lint go files golangci-lint run -c .golang-ci.yml + .PHONY: docker-build -docker-build: ## dockerize golang application - docker build . -f Dockerfile -t ${IMG} --build-arg GIT_HEAD_COMMIT=$(GIT_HEAD_COMMIT) \ +docker-build: + @docker buildx create --use --name=cross --node=cross && \ + docker buildx build \ + --build-arg GIT_HEAD_COMMIT=$(GIT_HEAD_COMMIT) \ --build-arg GIT_TAG_COMMIT=$(GIT_TAG_COMMIT) \ --build-arg GIT_MODIFIED=$(GIT_MODIFIED) \ --build-arg GIT_REPO=$(GIT_REPO) \ --build-arg GIT_LAST_TAG=$(VERSION) \ - --build-arg BUILD_DATE=$(BUILD_DATE) + --build-arg BUILD_DATE=$(BUILD_DATE) \ + --platform $(TARGET_PLATFORMS) \ + --output "type=docker,push=false" \ + --tag $(IMG) \ + -f Dockerfile.argo-cmp \ + ./ + + .PHONY: docker-build-cmp docker-build-cmp: ## build argocd plugin diff --git a/argocd-cmp/Dockerfile b/argocd-cmp/Dockerfile.goreleaser similarity index 99% rename from argocd-cmp/Dockerfile rename to argocd-cmp/Dockerfile.goreleaser index f482587..65e0834 100644 --- a/argocd-cmp/Dockerfile +++ b/argocd-cmp/Dockerfile.goreleaser @@ -1,4 +1,3 @@ - FROM bash:5 ENV ARGOCD_EXEC_TIMEOUT=90s COPY subst /subst diff --git a/go.mod b/go.mod index 0b37e8c..2ad126f 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/buttahtoast/subst go 1.19 -replace github.com/buttahtoast/pkg/decryptors => /Users/pariah/Projects/pkg/decryptors - require ( github.com/BurntSushi/toml v1.2.1 github.com/MakeNowJust/heredoc v1.0.0 diff --git a/pkg/subst/build.go b/pkg/subst/build.go index e2da314..c6b6b50 100644 --- a/pkg/subst/build.go +++ b/pkg/subst/build.go @@ -190,13 +190,13 @@ func (b *Build) decryptors() (decryptors []decrypt.Decryptor, cleanups []func(), if err == nil { b.kubeClient, err = kubernetes.NewForConfig(cfg) if err != nil { - logrus.Warnf("could not load kubernetes client: %s", err) + logrus.Debug("could not load kubernetes client: %s", err) } else { ctx := context.Background() for _, decr := range decryptors { err = decr.KeysFromSecret(b.cfg.SecretName, b.cfg.SecretNamespace, b.kubeClient, ctx) if err != nil { - logrus.Warnf("failed to load secrets from Kubernetes: %s", err) + logrus.Debug("failed to load secrets from Kubernetes: %s", err) } }