fix(Makefile, Dockerfile): use build-args

This commit is contained in:
Markus Pesch 2019-11-12 21:42:16 +01:00
parent b634834a3e
commit 4eb41e8dfa
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 35 additions and 18 deletions

View File

@ -1,9 +1,19 @@
FROM volkerraschek/build-image:1.4.0 AS build-env ARG BASE_IMAGE
ARG BUILD_IMAGE
ARG EXECUTABLE_TARGET
ARG VERSION
# BUILD
# ==============================================================================
FROM ${BUILD_IMAGE} AS build-env
ADD ./ /workspace ADD ./ /workspace
RUN make bin/linux/amd64/dhdu RUN make clean ${EXECUTABLE_TARGET} GOPROXY=${GOPROXY}
FROM busybox:latest # TARGET
COPY --from=build-env /workspace/bin/linux/amd64/dhdu /usr/bin/dhdu # ==============================================================================
FROM ${BASE_IMAGE}
COPY --from=build-env /workspace/${EXECUTABLE_TARGET} /usr/bin/dhdu
RUN chmod +x /usr/bin/dhdu
ENTRYPOINT [ "/usr/bin/dhdu" ] ENTRYPOINT [ "/usr/bin/dhdu" ]

View File

@ -10,9 +10,9 @@ EXECUTABLE:=dhdu
# LINUX_EXECUTABLES AND TARGETS # LINUX_EXECUTABLES AND TARGETS
LINUX_EXECUTABLES:=\ LINUX_EXECUTABLES:=\
linux/amd64/$(EXECUTABLE) \ linux/amd64/${EXECUTABLE} \
linux/arm/5/$(EXECUTABLE) \ linux/arm/5/${EXECUTABLE} \
linux/arm/7/$(EXECUTABLE) linux/arm/7/${EXECUTABLE}
LINUX_EXECUTABLE_TARGETS:=${LINUX_EXECUTABLES:%=bin/%} LINUX_EXECUTABLE_TARGETS:=${LINUX_EXECUTABLES:%=bin/%}
@ -50,11 +50,12 @@ REGISTRY_USER:=volkerraschek
REGISTRY_MIRROR=docker.io REGISTRY_MIRROR=docker.io
REGISTRY_NAMESPACE:=${REGISTRY_USER} REGISTRY_NAMESPACE:=${REGISTRY_USER}
# CONTAINER_IMAGE_VERSION / CONTAINER_IMAGE_NAME / CONTAINER_IMAGE # CONTAINER_IMAGE_VERSION / CONTAINER_IMAGE_NAME / CONTAINER_IMAGE
# Defines the name of the new container to be built using several variables. # Defines the name of the new container to be built using several variables.
BASE_IMAGE=busybox:latest
CONTAINER_IMAGE_NAME=${EXECUTABLE} CONTAINER_IMAGE_NAME=${EXECUTABLE}
CONTAINER_IMAGE_VERSION?=latest CONTAINER_IMAGE_VERSION?=latest
CONTAINER_IMAGE=${REGISTRY_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION}
README_FILE:=README.md README_FILE:=README.md
@ -66,17 +67,17 @@ ${EXECUTABLE}: bin/tmp/${EXECUTABLE}
all: ${EXECUTABLE_TARGETS} all: ${EXECUTABLE_TARGETS}
bin/linux/amd64/$(EXECUTABLE): bindata bin/linux/amd64/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "${@}" CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
bin/linux/arm/5/$(EXECUTABLE): bindata bin/linux/arm/5/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "${@}" CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
bin/linux/arm/7/$(EXECUTABLE): bindata bin/linux/arm/7/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "${@}" CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
bin/tmp/${EXECUTABLE}: bindata bin/tmp/${EXECUTABLE}: bindata
go build -ldflags "-X main.version=${VERSION}" -o "${@}" go build -ldflags "-X main.version=${VERSION}" -o ${@}
# BINDATA # BINDATA
# ============================================================================== # ==============================================================================
@ -112,8 +113,14 @@ clean:
# ============================================================================== # ==============================================================================
container-image/build: container-image/build:
${CONTAINER_RUNTIME} build \ ${CONTAINER_RUNTIME} build \
--tag ${REGISTRY_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION} \ --build-arg BASE_IMAGE=${BASE_IMAGE} \
--tag ${REGISTRY_MIRROR}/${REGISTRY_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION} \ --build-arg BUILD_IMAGE=${BUILD_IMAGE} \
--build-arg EXECUTABLE_TARGET=bin/linux/amd64/${EXECUTABLE} \
--build-arg GOPROXY=${GOPROXY} \
--build-arg VERSION=${VERSION} \
--no-cache \
--tag ${CONTAINER_IMAGE} \
--tag ${REGISTRY_MIRROR}/${CONTAINER_IMAGE} \
. .
if [ -f $(shell which docker) ] && [ "${CONTAINER_RUNTIME}" == "$(shell which podman)" ]; then \ if [ -f $(shell which docker) ] && [ "${CONTAINER_RUNTIME}" == "$(shell which podman)" ]; then \
@ -122,7 +129,7 @@ container-image/build:
container-image/push: container-image/build container-image/push: container-image/build
${CONTAINER_RUNTIME} login ${REGISTRY_MIRROR} --username ${REGISTRY_USER} --password ${REGISTRY_PASSWORD} ${CONTAINER_RUNTIME} login ${REGISTRY_MIRROR} --username ${REGISTRY_USER} --password ${REGISTRY_PASSWORD}
${CONTAINER_RUNTIME} push ${REGISTRY_MIRROR}/${REGISTRY_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION} ${CONTAINER_RUNTIME} push ${REGISTRY_MIRROR}/${CONTAINER_IMAGE}
# CONTAINER STEPS - BINARY # CONTAINER STEPS - BINARY
# ============================================================================== # ==============================================================================