Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:buttahtoast/subst
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbaehler committed Feb 12, 2024
2 parents 6ed1d9a + 9e55572 commit a42c2cf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions Dockerfile.argo-cmp
Original file line number Diff line number Diff line change
@@ -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"]
File renamed without changes.
34 changes: 26 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion argocd-cmp/Dockerfile → argocd-cmp/Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

FROM bash:5
ENV ARGOCD_EXEC_TIMEOUT=90s
COPY subst /subst
Expand Down
4 changes: 2 additions & 2 deletions pkg/subst/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit a42c2cf

Please sign in to comment.