Skip to content

Commit b33bf12

Browse files
committed
chore: default base image changed to distroless; feat: allow build-args on build_container script; fix: dry_run quotation
1 parent 233a369 commit b33bf12

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
ARG BASE_IMAGE=gcr.io/distroless/static
2+
13
# build stage
24
FROM golang:alpine AS build
3-
ARG UID=1000
45

56
COPY go* main* .
67

78
RUN apk add --no-cache git
8-
RUN adduser -u ${UID} -D -h /app -H scratchuser
99

1010
RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -o rabbitmq-dump-queue .
1111

@@ -18,14 +18,14 @@ ENTRYPOINT [ "go", "test" ]
1818

1919

2020
# production stage
21-
FROM scratch AS production
21+
FROM ${BASE_IMAGE} AS production
22+
ARG UID=65532
23+
ARG GID=65532
2224

23-
# copy root-less user
24-
COPY --from=build /etc/passwd /etc/passwd
2525
# make latest alpine certs available
2626
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2727

28-
USER scratchuser
28+
USER ${UID}:${GID}
2929

3030
# copy app binary
3131
COPY --from=build /go/rabbitmq-dump-queue /usr/local/bin/

scripts/build_container

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ set -e -o pipefail
44

55
usage() {
66
cat << USAGE >&2
7-
Usage: $(basename "$0") [OPTIONS]
7+
Usage: $0 [OPTIONS]
88
99
Options:
1010
-b, --builder <builder> Specify the builder (docker or kaniko).
11+
-e, --extra-args <arg=value> Specify additional build-args.
1112
-t, --target <target> Specify the target (build, test, debug or production).
1213
Default: production.
1314
-g, --tag <tag> Specify the tag.
@@ -16,8 +17,9 @@ Options:
1617
-h, --help Display this help message.
1718
1819
Examples:
19-
$(basename "$0") -b docker -t my-image --tag latest
20-
$(basename "$0") --builder kaniko --target debug
20+
$0 -b docker -t test --tag latest
21+
$0 --builder kaniko --target debug
22+
$0 -g local -e UID=\$UID -e GID=\$GID -e BASE_IMAGE=scratch
2123
2224
USAGE
2325
exit 1
@@ -30,16 +32,18 @@ main() {
3032
}
3133

3234
build_with_docker() {
33-
"${DRY_RUN}" docker buildx build \
35+
${DRY_RUN} docker buildx build \
3436
-t "${IMAGE_NAME}:${TAG}" \
37+
"${BUILD_ARGS[@]}" \
3538
--target="${TARGET}" .
3639
}
3740

3841
build_with_kaniko() {
3942
KANIKO_IMG="gcr.io/kaniko-project/executor:latest"
40-
"${DRY_RUN}" docker run -w /build \
43+
${DRY_RUN} docker run -w /build \
4144
-v "$PWD":/build \
4245
--rm \
46+
"${BUILD_ARGS[@]}" \
4347
"${KANIKO_IMG}" \
4448
-d "${IMAGE_NAME}:${TAG}" \
4549
--target "${TARGET}" \
@@ -54,6 +58,7 @@ parse_args() {
5458
opt="$1"; shift
5559
case $opt in
5660
--builder|-b) BUILDER="$1"; shift; ;;
61+
--extra-args|-e) BUILD_ARGS+=( --build-arg "$1" ); shift; ;;
5762
--target|-t) TARGET="$1"; shift; ;;
5863
--tag|-g) TAG="$1"; shift; ;;
5964
--help|-h) usage; ;;

0 commit comments

Comments
 (0)