diff --git a/Dockerfile b/Dockerfile index d8a0770afd..faba82872d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,11 @@ COPY go.sum . RUN go mod download COPY . . - +ARG PACKAGE_VERSION +ARG PACKAGE_COMMIT_ID +ARG GIT_STATUS RUN mkdir -p $GOPATH/pkg/linux_amd64/github.com/iotexproject/ && \ - make clean build-all + PACKAGE_VERSION=$PACKAGE_VERSION PACKAGE_COMMIT_ID=$PACKAGE_COMMIT_ID GIT_STATUS=$GIT_STATUS make clean build-all FROM alpine diff --git a/Makefile b/Makefile index 58ede04119..5cac57851b 100644 --- a/Makefile +++ b/Makefile @@ -38,13 +38,19 @@ ROOT_PKG := "github.com/iotexproject/iotex-core" DOCKERCMD=docker # Package Info +ifndef PACKAGE_VERSION PACKAGE_VERSION := $(shell git describe --tags) +endif +ifndef PACKAGE_COMMIT_ID PACKAGE_COMMIT_ID := $(shell git rev-parse HEAD) +endif +ifndef GIT_STATUS GIT_STATUS := $(shell git status --porcelain) ifdef GIT_STATUS - GIT_STATUS := "dirty" + GIT_STATUS := "dirty" else - GIT_STATUS := "clean" + GIT_STATUS := "clean" +endif endif GO_VERSION := $(shell go version) BUILD_TIME=$(shell date +%F-%Z/%T) diff --git a/hooks/build b/hooks/build new file mode 100644 index 0000000000..27ddc627cb --- /dev/null +++ b/hooks/build @@ -0,0 +1,2 @@ +#!/bin/bash +docker build --build-arg PACKAGE_COMMIT_ID=$SOURCE_COMMIT --build-arg PACKAGE_VERSION=$DOCKER_TAG --build-arg GIT_STATUS=clean -f $DOCKERFILE_PATH -t $IMAGE_NAME . \ No newline at end of file