-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
998b863
commit cfed02b
Showing
5 changed files
with
154 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#syntax=docker/dockerfile-upstream:1.4 | ||
ARG GO_APP | ||
|
||
FROM base as deps | ||
|
||
ARG GO_APP | ||
|
||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ARG TARGETVARIANT | ||
|
||
RUN mkdir -p /go/bin /go/src | ||
|
||
COPY --from=build /go/src/dist /go/src/dist | ||
|
||
RUN <<EOT | ||
set -e | ||
apk add --no-cache ca-certificates jq | ||
if [[ ${TARGETARCH} == "arm" ]]; then VARIANT=$(echo ${TARGETVARIANT} | sed 's/^v//'); fi | ||
BIN_PATH=$(jq -r ".[] |select(.type == \"Binary\" and \ | ||
.name == \"${GO_APP}\" and \ | ||
.goos == \"${TARGETOS}\" and \ | ||
.goarch == \"${TARGETARCH}\" and \ | ||
(.goarm == \"${VARIANT}\" or .goarm == null)) | .path" < /go/src/dist/artifacts.json) | ||
cp ${BIN_PATH} /go/bin | ||
EOT | ||
|
||
FROM base | ||
|
||
ARG GO_APP | ||
|
||
COPY --from=deps --chmod=755 /go/bin/${GO_APP} /usr/local/bin/${GO_APP} | ||
|
||
COPY --from=deps /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
RUN ln -s /usr/local/bin/${GO_APP} /entrypoint | ||
|
||
ENTRYPOINT ["/entrypoint"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#syntax=docker/dockerfile-upstream:1.4 | ||
FROM --platform=$BUILDPLATFORM goreleaser | ||
|
||
ARG CI | ||
ARG GITHUB_TOKEN | ||
|
||
COPY --from=src . /go/src | ||
|
||
RUN <<EOT | ||
set -e | ||
cd /go/src | ||
FLAGS="--rm-dist" | ||
if [[ -z ${GITHUB_TOKEN} ]]; then | ||
if [[ ${CI} != "true" ]]; then FLAGS="${FLAGS} --skip-validate --single-target"; fi | ||
goreleaser build ${FLAGS} | ||
else | ||
goreleaser release ${FLAGS} | ||
fi | ||
EOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
################### | ||
### Variables | ||
################### | ||
|
||
variable REGISTRY { | ||
default = "" | ||
} | ||
|
||
# Comma delimited list of tags | ||
variable TAGS { | ||
default = "latest" | ||
} | ||
|
||
variable CI { | ||
default = false | ||
} | ||
|
||
variable image_base { | ||
default = "docker-image://alpine:3.17.1" | ||
} | ||
|
||
variable image_goreleaser { | ||
default = "docker-image://goreleaser/goreleaser:v1.14.1" | ||
} | ||
|
||
################### | ||
### Functions | ||
################### | ||
|
||
function "get_tags" { | ||
params = [image] | ||
result = [for tag in split(",", TAGS) : join("/", compact([REGISTRY, "${image}:${tag}"]))] | ||
} | ||
|
||
function "get_platforms_multiarch" { | ||
params = [] | ||
result = CI ? ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64"] : [] | ||
} | ||
|
||
function "get_output" { | ||
params = [] | ||
result = CI ? ["type=registry"] : ["type=docker"] | ||
} | ||
|
||
################### | ||
### Groups | ||
################### | ||
|
||
group "default" { | ||
targets = [ | ||
"prometheus-nats-exporter" | ||
] | ||
} | ||
|
||
################### | ||
### Targets | ||
################### | ||
|
||
target "goreleaser" { | ||
contexts = { | ||
goreleaser = image_goreleaser | ||
src = "." | ||
} | ||
args = { | ||
CI = CI | ||
GITHUB_TOKEN = "" | ||
} | ||
dockerfile = "cicd/Dockerfile_goreleaser" | ||
} | ||
|
||
target "prometheus-nats-exporter" { | ||
contexts = { | ||
base = image_base | ||
build = "target:goreleaser" | ||
} | ||
args = { | ||
GO_APP = "prometheus-nats-exporter" | ||
} | ||
dockerfile = "cicd/Dockerfile" | ||
platforms = get_platforms_multiarch() | ||
tags = get_tags("prometheus-nats-exporter") | ||
output = get_output() | ||
} |