Skip to content

Commit

Permalink
refactor: unify the greptime artifacts building (#2015)
Browse files Browse the repository at this point in the history
* refactor: unify the make targets of building images

* refactor: make Dockerfile more clean

1. Add dev-builder image to build greptime binary easily;
2. Add 'docker/ci/Dockerfile-centos' to release centos image;
3. Delete Dockerfile of aarch64 and just need to use one Dockerfile;

Signed-off-by: zyy17 <[email protected]>

---------

Signed-off-by: zyy17 <[email protected]>
  • Loading branch information
zyy17 authored Jul 24, 2023
1 parent f1cd28f commit 657fcaf
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 170 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ jobs:
uses: docker/build-push-action@v3
if: success() || steps.unzip-arm64.conclusion == 'success' # Build and push all platform if unzip-arm64 succeeds
with:
context: ./docker/ci/
context: .
file: ./docker/ci/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
Expand All @@ -411,7 +411,7 @@ jobs:
uses: docker/build-push-action@v3
if: success() || steps.download-arm64.conclusion == 'failure' # Only build and push amd64 platform if download-arm64 fails
with:
context: ./docker/ci/
context: .
file: ./docker/ci/Dockerfile
push: true
platforms: linux/amd64
Expand Down
112 changes: 102 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
IMAGE_REGISTRY ?= greptimedb
# The arguments for building images.
CARGO_PROFILE ?=
FEATURES ?=
TARGET_DIR ?=
CARGO_BUILD_OPTS := --locked
IMAGE_REGISTRY ?= docker.io
IMAGE_NAMESPACE ?= greptime
IMAGE_TAG ?= latest
BUILDX_MULTI_PLATFORM_BUILD ?= false
BUILDX_BUILDER_NAME ?= gtbuilder
BASE_IMAGE ?= ubuntu
RUST_TOOLCHAIN ?= $(shell cat rust-toolchain.toml | grep channel | cut -d'"' -f2)
CARGO_REGISTRY_CACHE ?= ${HOME}/.cargo/registry

# The arguments for running integration tests.
ETCD_VERSION ?= v3.5.9
ETCD_IMAGE ?= quay.io/coreos/etcd:${ETCD_VERSION}
RETRY_COUNT ?= 3
BUILD_JOBS ?= $(shell expr $$(nproc) / 2)
ifeq ($(BUILD_JOBS), 0) # If the number of cores is less than 2, set the build jobs to 1.
BUILD_JOBS := 1
endif

ifdef CARGO_PROFILE
CARGO_BUILD_OPTS += --profile ${CARGO_PROFILE}
endif

ifdef FEATURES
CARGO_BUILD_OPTS += --features ${FEATURES}
endif

ifdef TARGET_DIR
CARGO_BUILD_OPTS += --target-dir ${TARGET_DIR}
endif

ifeq ($(BUILDX_MULTI_PLATFORM_BUILD), true)
BUILDX_MULTI_PLATFORM_BUILD_OPTS := --platform linux/amd64,linux/arm64 --push
else
BUILDX_MULTI_PLATFORM_BUILD_OPTS := -o type=docker
endif

##@ Build

.PHONY: build
build: ## Build debug version greptime.
cargo build
build: ## Build debug version greptime. If USE_DEV_BUILDER is true, the binary will be built in dev-builder.
ifeq ($(USE_DEV_BUILDER), true)
docker run --network=host \
-v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry \
-w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder:latest \
make build CARGO_PROFILE=${CARGO_PROFILE} FEATURES=${FEATURES} TARGET_DIR=${TARGET_DIR}
else
cargo build ${CARGO_BUILD_OPTS}
endif

.PHONY: release
release: ## Build release version greptime.
cargo build --release
release: ## Build release version greptime. If USE_DEV_BUILDER is true, the binary will be built in dev-builder.
ifeq ($(USE_DEV_BUILDER), true)
docker run --network=host \
-v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry \
-w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder:latest \
make release CARGO_PROFILE=${CARGO_PROFILE} FEATURES=${FEATURES} TARGET_DIR=${TARGET_DIR}
else
cargo build --release ${CARGO_BUILD_OPTS}
endif

.PHONY: clean
clean: ## Clean the project.
Expand All @@ -28,13 +80,38 @@ check-toml: ## Check all TOML files.
taplo format --check --option "indent_string= "

.PHONY: docker-image
docker-image: ## Build docker image.
docker build --network host -f docker/Dockerfile -t ${IMAGE_REGISTRY}:${IMAGE_TAG} .
docker-image: multi-platform-buildx ## Build docker image.
docker buildx build --builder ${BUILDX_BUILDER_NAME} \
--build-arg="CARGO_PROFILE=${CARGO_PROFILE}" --build-arg="FEATURES=${FEATURES}" \
-f docker/${BASE_IMAGE}/Dockerfile \
-t ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/greptimedb:${IMAGE_TAG} ${BUILDX_MULTI_PLATFORM_BUILD_OPTS} .

.PHONY: build-greptime-by-buildx
build-greptime-by-buildx: multi-platform-buildx ## Build greptime binary by docker buildx. The binary will be copied to the current directory.
docker buildx build --builder ${BUILDX_BUILDER_NAME} \
--target=builder \
--build-arg="CARGO_PROFILE=${CARGO_PROFILE}" --build-arg="FEATURES=${FEATURES}" \
-f docker/${BASE_IMAGE}/Dockerfile \
-t ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/greptimedb-builder:${IMAGE_TAG} ${BUILDX_MULTI_PLATFORM_BUILD_OPTS} .

docker run --rm -v ${PWD}:/data \
--entrypoint cp ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/greptimedb-builder:${IMAGE_TAG} \
/out/target/${CARGO_PROFILE}/greptime /data/greptime

.PHONY: dev-builder
dev-builder: multi-platform-buildx ## Build dev-builder image.
docker buildx build --builder ${BUILDX_BUILDER_NAME} \
--build-arg="RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" \
-f docker/dev-builder/Dockerfile \
-t ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder:${IMAGE_TAG} ${BUILDX_MULTI_PLATFORM_BUILD_OPTS} .

.PHONY: multi-platform-buildx
multi-platform-buildx: ## Create buildx multi-platform builder.
docker buildx inspect ${BUILDX_BUILDER_NAME} || docker buildx create --name ${BUILDX_BUILDER_NAME} --driver docker-container --bootstrap --use

##@ Test

test: nextest ## Run unit and integration tests.
cargo nextest run --retries 3
cargo nextest run --retries ${RETRY_COUNT} --build-jobs=${BUILD_JOBS}

.PHONY: nextest ## Install nextest tools.
nextest:
Expand All @@ -56,6 +133,21 @@ clippy: ## Check clippy rules.
fmt-check: ## Check code format.
cargo fmt --all -- --check

.PHONY: start-etcd
start-etcd: ## Start single node etcd for testing purpose.
docker run --rm -d --network=host -p 2379-2380:2379-2380 ${ETCD_IMAGE}

.PHONY: stop-etcd
stop-etcd: ## Stop single node etcd for testing purpose.
docker stop $$(docker ps -q --filter ancestor=${ETCD_IMAGE})

.PHONY: run-it-in-container
run-it-in-container: start-etcd ## Run integration tests in dev-builder.
docker run --network=host \
-v ${PWD}:/greptimedb -v ${CARGO_REGISTRY_CACHE}:/root/.cargo/registry -v /tmp:/tmp \
-w /greptimedb ${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/dev-builder:latest \
make test sqlness-test BUILD_JOBS=${BUILD_JOBS}

##@ General

# The help target prints out all targets with their descriptions organized
Expand All @@ -71,4 +163,4 @@ fmt-check: ## Check code format.

.PHONY: help
help: ## Display help messages.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
60 changes: 0 additions & 60 deletions docker/aarch64/Dockerfile

This file was deleted.

87 changes: 0 additions & 87 deletions docker/aarch64/compile-python.sh

This file was deleted.

31 changes: 29 additions & 2 deletions docker/Dockerfile-centos7-builder → docker/centos/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM centos:7
FROM centos:7 as builder

ARG CARGO_PROFILE
ARG FEATURES

ENV LANG en_US.utf8
WORKDIR /greptimedb
Expand All @@ -21,4 +24,28 @@ SHELL ["/bin/bash", "-c"]
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
ENV PATH /opt/rh/rh-python38/root/usr/bin:/usr/local/bin:/root/.cargo/bin/:$PATH

CMD ["cargo", "build", "--release"]
# Build the project in release mode.
RUN --mount=target=.,rw \
--mount=type=cache,target=/usr/local/cargo/registry \
make build \
CARGO_PROFILE=${CARGO_PROFILE} \
FEATURES=${FEATURES} \
TARGET_DIR=/out/target

# Export the binary to the clean image.
FROM centos:7 as base

ARG CARGO_PROFILE

RUN yum install -y epel-release \
openssl \
openssl-devel \
centos-release-scl \
rh-python38 \
rh-python38-python-devel

WORKDIR /greptime
COPY --from=builder /out/target/${CARGO_PROFILE}/greptime /greptime/bin/
ENV PATH /greptime/bin/:$PATH

ENTRYPOINT ["greptime"]
2 changes: 1 addition & 1 deletion docker/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
python3-pip \
curl

COPY requirements.txt /etc/greptime/requirements.txt
COPY ./docker/python/requirements.txt /etc/greptime/requirements.txt

RUN python3 -m pip install -r /etc/greptime/requirements.txt

Expand Down
16 changes: 16 additions & 0 deletions docker/ci/Dockerfile-centos
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM centos:7

RUN yum install -y epel-release \
openssl \
openssl-devel \
centos-release-scl \
rh-python38 \
rh-python38-python-devel

ARG TARGETARCH

ADD $TARGETARCH/greptime /greptime/bin/

ENV PATH /greptime/bin/:$PATH

ENTRYPOINT ["greptime"]
Loading

0 comments on commit 657fcaf

Please sign in to comment.