Skip to content

Commit

Permalink
Makefile: fix make docker (tikv#7498)
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Shen <[email protected]>
  • Loading branch information
overvenus authored Apr 17, 2020
1 parent 2a817a0 commit f5ee17b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is almost the same as .gitignore expect the next line.
.git

# OSX leaves these everywhere on SMB shares
._*
Expand All @@ -22,9 +24,9 @@ out/
.vscode/**

target
dist
tmp
/bin
/dist

# fuzzing hack, see fuzz/cli.rs
fuzz-incremental/
Expand Down
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
## ----------------------------------
Expand Down
46 changes: 22 additions & 24 deletions scripts/gen-dockerfile.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@
# 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.
# Install the system dependencies
# Attempt to clean and rebuild the cache to avoid 404s
cat <<EOT
FROM centos:7.6.1810 as builder
RUN yum clean all && \
yum makecache && \
yum update -y && \
yum install -y epel-release && \
RUN yum install -y epel-release && \
yum clean all && \
yum makecache && \
yum update -y && \
yum install -y tar wget git which file unzip python-pip openssl-devel \
make cmake3 gcc gcc-c++ libstdc++-static pkg-config psmisc gdb \
libdwarf-devel elfutils-libelf-devel elfutils-devel binutils-devel \
dwz && \
yum clean all
yum makecache
RUN yum install -y \
perl \
make cmake3 dwz \
gcc gcc-c++ libstdc++-static && \
yum clean all
EOT


Expand All @@ -54,11 +51,6 @@ RUN rustup set profile minimal
RUN rustup default \$(cat "rust-toolchain")
EOT

# Use Makefile to build
cat <<EOT
COPY Makefile ./
EOT

# For cargo
cat <<EOT
COPY scripts ./scripts
Expand All @@ -78,18 +70,18 @@ done

# Create dummy files, build the dependencies
# then remove TiKV fingerprint for following rebuild.
# Finally, remove test dependencies and profile features.
# Finally, remove fuzz and profile features.
cat <<EOT
RUN mkdir -p ./cmd/src/bin && \\
echo 'fn main() {}' > ./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.
Expand All @@ -102,7 +94,13 @@ echo "COPY src src"

# Build real binaries now
cat <<EOT
COPY ./.git ./.git
ARG GIT_FULLBACK="Unknown (no git or not git repo)"
ARG GIT_HASH=\${GIT_FULLBACK}
ARG GIT_TAG=\${GIT_FULLBACK}
ARG GIT_BRANCH=\${GIT_FULLBACK}
ENV TIKV_BUILD_GIT_HASH=\${GIT_HASH}
ENV TIKV_BUILD_GIT_TAG=\${GIT_TAG}
ENV TIKV_BUILD_GIT_BRANCH=\${GIT_BRANCH}
RUN make build_dist_release
EOT

Expand Down

0 comments on commit f5ee17b

Please sign in to comment.