From f5ee17b3101a24aafb897a76fbf3524fb19ccc58 Mon Sep 17 00:00:00 2001 From: Neil Shen Date: Fri, 17 Apr 2020 22:35:03 +0800 Subject: [PATCH] Makefile: fix make docker (#7498) Signed-off-by: Neil Shen --- .dockerignore | 4 +++- Makefile | 18 ++++++++++----- scripts/gen-dockerfile.sh | 46 +++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 30 deletions(-) mode change 100755 => 100644 scripts/gen-dockerfile.sh diff --git a/.dockerignore b/.dockerignore index 21ac71c8972..b0a83d43c41 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ +# This file is almost the same as .gitignore expect the next line. +.git # OSX leaves these everywhere on SMB shares ._* @@ -22,9 +24,9 @@ out/ .vscode/** target +dist tmp /bin -/dist # fuzzing hack, see fuzz/cli.rs fuzz-incremental/ diff --git a/Makefile b/Makefile index 33cd98727f8..b91a3481dbe 100644 --- a/Makefile +++ b/Makefile @@ -81,12 +81,15 @@ CARGO_TARGET_DIR ?= $(CURDIR)/target # Build-time environment, captured for reporting by the application binary BUILD_INFO_GIT_FALLBACK := "Unknown (no git or not git repo)" BUILD_INFO_RUSTC_FALLBACK := "Unknown" +export TIKV_ENABLE_FEATURES := ${ENABLE_FEATURES} export TIKV_BUILD_TIME := $(shell date -u '+%Y-%m-%d %I:%M:%S') -export TIKV_BUILD_GIT_HASH := $(shell git rev-parse HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK}) -export TIKV_BUILD_GIT_TAG := $(shell git describe --tag || echo ${BUILD_INFO_GIT_FALLBACK}) -export TIKV_BUILD_GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK}) export TIKV_BUILD_RUSTC_VERSION := $(shell rustc --version 2> /dev/null || echo ${BUILD_INFO_RUSTC_FALLBACK}) -export TIKV_ENABLE_FEATURES := ${ENABLE_FEATURES} +export TIKV_BUILD_GIT_HASH ?= $(shell git rev-parse HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK}) +export TIKV_BUILD_GIT_TAG ?= $(shell git describe --tag || echo ${BUILD_INFO_GIT_FALLBACK}) +export TIKV_BUILD_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK}) + +export DOCKER_IMAGE_NAME ?= "pingcap/tikv" +export DOCKER_IMAGE_TAG ?= "latest" # Turn on cargo pipelining to add more build parallelism. This has shown decent # speedups in TiKV. @@ -327,7 +330,12 @@ ctl: # A special target for building TiKV docker image. .PHONY: docker docker: - bash ./scripts/gen-dockerfile.sh | docker build -t pingcap/tikv -f - . + bash ./scripts/gen-dockerfile.sh | docker build \ + -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} \ + -f - . \ + --build-arg GIT_HASH=${TIKV_BUILD_GIT_HASH} \ + --build-arg GIT_TAG=${TIKV_BUILD_GIT_TAG} \ + --build-arg GIT_BRANCH=${TIKV_BUILD_GIT_BRANCH} ## The driver for script/run-cargo.sh ## ---------------------------------- diff --git a/scripts/gen-dockerfile.sh b/scripts/gen-dockerfile.sh old mode 100755 new mode 100644 index c417ed21fed..5970f9ff131 --- a/scripts/gen-dockerfile.sh +++ b/scripts/gen-dockerfile.sh @@ -8,7 +8,7 @@ # it is our lowest common denominator in terms of distro support. # Some commands in this script are structured in order to reduce the number of layers Docker -# generates. Unfortunately Docker is limited to only 125 layers: +# generates. Unfortunately Docker is limited to only 125 layers: # https://github.com/moby/moby/blob/a9507c6f76627fdc092edc542d5a7ef4a6df5eec/layer/layer.go#L50-L53 # We require epel packages, so enable the fedora EPEL repo then install dependencies. @@ -16,18 +16,15 @@ # Attempt to clean and rebuild the cache to avoid 404s cat < ./cmd/src/bin/tikv-ctl.rs && \\ echo 'fn main() {}' > ./cmd/src/bin/tikv-server.rs && \\ for cargotoml in \$(find . -name "Cargo.toml"); do \\ sed -i '/fuzz/d' \${cargotoml} && \\ - sed -i '/test\_/d' \${cargotoml} && \\ - sed -i '/profiler/d' \${cargotoml} && \\ - sed -i '/\"tests\",/d' \${cargotoml} ; \\ - done && \\ - make build_dist_release + sed -i '/profiler/d' \${cargotoml} ; \\ + done + +COPY Makefile ./ +RUN make build_dist_release EOT # Remove fingerprints for when we build the real binaries. @@ -102,7 +94,13 @@ echo "COPY src src" # Build real binaries now cat <