added VERSION & BUILD_TIME as build-arg

This commit is contained in:
Kwitsch 2022-09-12 10:33:14 +02:00
parent d824a439f8
commit a035197eff
2 changed files with 17 additions and 9 deletions

View File

@ -1,8 +1,12 @@
# build stage
FROM golang:1-alpine AS build-env
# set working directory
WORKDIR /src
# add blocky user
RUN adduser -S -D -H -h /app -s /sbin/nologin blocky
RUN tail -n 1 /etc/passwd > /tmp/blocky_passwd
# add packages
RUN apk add --no-cache \
build-base \
@ -19,19 +23,23 @@ RUN apk add --no-cache \
ca-certificates \
libcap
ENV GO111MODULE=on \
CGO_ENABLED=0
WORKDIR /src
# get go modules
COPY go.mod go.sum ./
RUN go mod download
# add source
ADD . .
ARG opts
RUN env ${opts} make build-static
# setup environment
ARG VERSION
ENV VERSION ${VERSION}
ARG BUILD_TIME
ENV BUILD_TIME ${BUILD_TIME}
ENV GO111MODULE=on
ENV CGO_ENABLED=0
# build binary
RUN make build-static
RUN setcap 'cap_net_bind_service=+ep' /src/bin/blocky
RUN chown blocky /src/bin/blocky

View File

@ -4,7 +4,7 @@
.DEFAULT_GOAL := help
VERSION?=$(shell git describe --always --tags)
BUILD_TIME=$(shell date '+%Y%m%d-%H%M%S')
BUILD_TIME?=$(shell date '+%Y%m%d-%H%M%S')
DOCKER_IMAGE_NAME=spx01/blocky
BINARY_NAME=blocky
BIN_OUT_DIR=bin
@ -49,7 +49,7 @@ fmt: ## gofmt and goimports all go files
find . -name '*.go' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
docker-build: ## Build docker image
docker buildx build -o type=docker --network=host -t ${DOCKER_IMAGE_NAME} .
docker buildx build -o type=docker --build-arg VERSION=${VERSION} --build-arg BUILD_TIME=${BUILD_TIME} --network=host -t ${DOCKER_IMAGE_NAME} .
help: ## Shows help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'