[Tool] Build and publish starrocks image in a hermetic multi-stage docker build pipeline. (#17238)
Signed-off-by: Deng Liu <d.liu@celonis.de> ## Context Build and publish starrocks image in a hermetic multi-stage docker build pipeline. The docker file can be later integrated into Github action CI. ## Changes - The name of the docker file will be mapped to a repo name in container registry. E.g. `be-ubuntu.Dockerfile` -> `ghcr.io/StarRocks/starrocks/be-ubuntu:<tag>` - Add [workflows/release.yml](https://github.com/dengliu/starrocks/actions/workflows/release.yml) to automatically build and publish images on cutting a release. - Please check [various image versions ](https://github.com/dengliu/starrocks/pkgs/container/starrocks%2Ffe-ubuntu)with image tags correspond to the release tags: ## Test Have run the command provided in the README.md and verified that build, package and publish succeeded in my forked repo. - The published image are available from my[ repo ghcr:](https://github.com/dengliu?tab=packages&repo_name=starrocks) - [Github action CI](https://github.com/dengliu/starrocks/actions/workflows/release-docker-image.yml) 
This commit is contained in:
parent
3d73112e9b
commit
76eaac0c7e
|
|
@ -15,6 +15,9 @@ thirdparty/src
|
|||
**/*.o
|
||||
|
||||
**/output
|
||||
# negate the output as it might be used for packing container from locally build artifact
|
||||
!output
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
name: 'release docker images'
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
# This allows a subsequently queued workflow run to interrupt previous runs
|
||||
concurrency:
|
||||
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
RELEASE_VERSION: ${{ github.ref_name }}
|
||||
REGISTRY: ghcr.io/${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
release-docker-images:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
packages: write
|
||||
contents: read
|
||||
steps:
|
||||
- name: checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: build artifact docker image
|
||||
run: |
|
||||
DOCKER_BUILDKIT=1 docker build --rm=true -f docker/dockerfiles/artifact-ubuntu.Dockerfile -t artifact-ubuntu:${RELEASE_VERSION} .
|
||||
|
||||
- name: build and publish fe docker image
|
||||
run: |
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACTIMAGE=artifact-ubuntu:${RELEASE_VERSION} -f docker/dockerfiles/fe-ubuntu.Dockerfile -t ${REGISTRY}/fe-ubuntu:${RELEASE_VERSION} .
|
||||
# Pushing to the GitHub packages docker registry regularly fails with "unknown blob" errors. The "fix" suggested by GitHub is looping.
|
||||
until docker push ${REGISTRY}/fe-ubuntu:${RELEASE_VERSION}
|
||||
do
|
||||
echo "Could not push ${REGISTRY}/fe-ubuntu:${RELEASE_VERSION} trying again."
|
||||
done
|
||||
- name: build and publish be docker image
|
||||
run: |
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACTIMAGE=artifact-ubuntu:${RELEASE_VERSION} -f docker/dockerfiles/be-ubuntu.Dockerfile -t ${REGISTRY}/be-ubuntu:${RELEASE_VERSION} .
|
||||
# Pushing to the GitHub packages docker registry regularly fails with "unknown blob" errors. The "fix" suggested by GitHub is looping.
|
||||
until docker push ${REGISTRY}/be-ubuntu:${RELEASE_VERSION}
|
||||
do
|
||||
echo "Could not push ${REGISTRY}/be-ubuntu:${RELEASE_VERSION} trying again."
|
||||
done
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
The building of Starrocks artifacts and packaging to runtime container images are performed in a hermetic, [multi-stage docker build](https://docs.docker.com/build/building/multi-stage/) environment. This setup enables the reuse of FE/BE artifacts for packaging into container images for different deployment scenarios. The building of artifacts will be executed in parallel leveraging the [BuildKit](https://docs.docker.com/build/buildkit/) for optimal speed.
|
||||
|
||||

|
||||
|
||||
# 1. Starrocks Ubuntu dev env image
|
||||
This [dev-env-ubuntu.Dockerfile](dev-env-ubuntu.Dockerfile) build the docker image for the dev environment.
|
||||
It builds and pre-install all the toolchains, dependence libraries, and maven dependencies that are needed for building Starrocks FE and BE.
|
||||
|
||||
## 1.1 Build Ubuntu dev env image
|
||||
```
|
||||
DOCKER_BUILDKIT=1 docker build --rm=true -f dev-env-ubuntu.Dockerfile -t ghcr.io/OWNER/starrocks/dev-env-ubuntu:<tag> ../..
|
||||
```
|
||||
E.g.:
|
||||
```shell
|
||||
DOCKER_BUILDKIT=1 docker build --rm=true -f dev-env-ubuntu.Dockerfile -t ghcr.io/dengliu/starrocks/dev-env-ubuntu:latest ../..
|
||||
```
|
||||
## 1.2 Publish image to ghcr
|
||||
```
|
||||
docker push ghcr.io/OWNER/starrocks/dev-env-ubuntu:<tag>
|
||||
```
|
||||
E.g.:
|
||||
```shell
|
||||
docker push ghcr.io/dengliu/starrocks/dev-env-ubuntu:latest
|
||||
```
|
||||
|
||||
# 2 Starrocks artifacts image
|
||||
|
||||
Artifact Package Stage packages the artifacts into a Busybox based image. The busybox base image is only 1MB, the packaged artifact image serves as a carrier to pass the Starrocks artifact to the next stage of docker build to package into various types of k8s deployment runtime images.
|
||||
|
||||
|
||||
## 2.1 Build Starrocks aftifacts image for Ubuntu
|
||||
Build the Starrocks artifacts fe & be and package them into a busybox basedimage
|
||||
|
||||
```
|
||||
DOCKER_BUILDKIT=1 docker build -f artifact-ubuntu.Dockerfile -t ghcr.io/OWNER/starrocks/artifact-ubuntu:<tag> ../..
|
||||
```
|
||||
E.g.
|
||||
```shell
|
||||
DOCKER_BUILDKIT=1 docker build -f artifact-ubuntu.Dockerfile -t ghcr.io/dengliu/starrocks/artifact-ubuntu:latest ../..
|
||||
```
|
||||
|
||||
## 2.2 Publish image to ghcr
|
||||
```
|
||||
docker push ghcr.io/OWNER/starrocks/artifact-ubuntu:<tag>
|
||||
```
|
||||
E.g.:
|
||||
```shell
|
||||
docker push ghcr.io/dengliu/starrocks/artifact-ubuntu:latest
|
||||
```
|
||||
|
||||
|
||||
# 3. Starrocks be ubuntu image
|
||||
|
||||
## 3.1 Build Starrocks be ubuntu image for k8s deployment
|
||||
```
|
||||
DOCKER_BUILDKIT=1 docker build -f be-ubuntu.Dockerfile -t ghcr.io/OWNER/starrocks/be-ubuntu:<tag> ../..
|
||||
```
|
||||
E.g.:
|
||||
- Use artifact image to package runtime container
|
||||
```shell
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=image --build-arg ARTIFACTIMAGE=ghcr.io/dengliu/starrocks/artifact-ubuntu:latest -f be-ubuntu.Dockerfile -t be-ubuntu:latest ../..
|
||||
```
|
||||
|
||||
- Use locally build artifacts to package runtime container
|
||||
```shell
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=local --build-arg LOCAL_REPO_PATH=. -f be-ubuntu.Dockerfile -t be-ubuntu:latest ../..
|
||||
```
|
||||
|
||||
## 3.2 Publish image to ghcr
|
||||
```
|
||||
docker push ghcr.io/OWNER/starrocks/be-ubuntu:<tag>
|
||||
```
|
||||
E.g.:
|
||||
```shell
|
||||
docker push ghcr.io/dengliu/starrocks/be-ubuntu:latest
|
||||
```
|
||||
|
||||
|
||||
# 4. Starrocks fe ubuntu image
|
||||
|
||||
## 4.1 Build Starrocks fe ubuntu image for k8s deployment
|
||||
```
|
||||
DOCKER_BUILDKIT=1 docker build -f fe-ubuntu.Dockerfile -t ghcr.io/OWNER/starrocks/fe-ubuntu:<tag> ../..
|
||||
```
|
||||
E.g.:
|
||||
- Use artifact image to package runtime container
|
||||
```shell
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=image --build-arg ARTIFACTIMAGE=ghcr.io/dengliu/starrocks/artifact-ubuntu:latest -f fe-ubuntu.Dockerfile -t fe-ubuntu:latest ../..
|
||||
```
|
||||
|
||||
- Use locally build artifacts to package runtime container
|
||||
```shell
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=local --build-arg LOCAL_REPO_PATH=. -f fe-ubuntu.Dockerfile -t fe-ubuntu:latest ../..
|
||||
```
|
||||
|
||||
## 4.2 Publish image to ghcr
|
||||
```
|
||||
docker push ghcr.io/OWNER/starrocks/fe-ubuntu:<tag>
|
||||
```
|
||||
E.g.:
|
||||
```shell
|
||||
docker push ghcr.io/dengliu/starrocks/fe-ubuntu:latest
|
||||
```
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# This docker file build the Starrocks artifacts fe & be and package them into a busybox-based image
|
||||
# Please run this command from the git repo root directory to build:
|
||||
# DOCKER_BUILDKIT=1 docker build --rm=true -f docker/dockerfiles/artifact-ubuntu.Dockerfile -t starrocks/artifact-ubuntu:tag .
|
||||
|
||||
ARG builder=ghcr.io/StarRocks/starrocks/dev-env-ubuntu:latest
|
||||
|
||||
FROM ${builder} as fe-builder
|
||||
# clean and build Frontend and Spark Dpp application
|
||||
COPY . /build/starrocks
|
||||
WORKDIR /build/starrocks
|
||||
RUN MAVEN_OPTS='-Dmaven.artifact.threads=128' ./build.sh --fe --clean
|
||||
|
||||
|
||||
FROM ${builder} as be-builder
|
||||
# build Backend in different mode (build_type could be Release, Debug, or Asan. Default value is Release.
|
||||
ARG BUILD_TYPE=Release
|
||||
COPY . /build/starrocks
|
||||
WORKDIR /build/starrocks
|
||||
RUN BUILD_TYPE=${BUILD_TYPE} ./build.sh --be --clean -j `nproc`
|
||||
|
||||
|
||||
FROM busybox:latest
|
||||
|
||||
LABEL org.opencontainers.image.source="https://github.com/StarRocks/starrocks"
|
||||
|
||||
COPY --from=fe-builder /build/starrocks/output /release/fe_artifacts
|
||||
COPY --from=be-builder /build/starrocks/output /release/be_artifacts
|
||||
|
||||
WORKDIR /release
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
# This docker file build the Starrocks be ubuntu image
|
||||
# Please run this command from the git repo root directory to build:
|
||||
#
|
||||
# - Use artifact image to package runtime container:
|
||||
# > DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=image --build-arg ARTIFACTIMAGE=ghcr.io/dengliu/starrocks/artifact-ubuntu:latest -f docker/dockerfiles/be-ubuntu.Dockerfile -t be-ubuntu:latest .
|
||||
# - Use locally build artifacts to package runtime container:
|
||||
# > DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=local --build-arg LOCAL_REPO_PATH=. -f docker/dockerfiles/be-ubuntu.Dockerfile -t be-ubuntu:latest .
|
||||
|
||||
# The artifact source used for packing the runtime docker image
|
||||
# image: copy the artifacts from a artifact docker image.
|
||||
# local: copy the artifacts from a local repo. Mainly used for local development and test.
|
||||
ARG ARTIFACT_SOURCE=image
|
||||
|
||||
ARG ARTIFACTIMAGE=artifact:latest
|
||||
FROM ${ARTIFACTIMAGE} as artifacts-from-image
|
||||
|
||||
# create a docker build stage that copy locally build artifacts
|
||||
FROM busybox:latest as artifacts-from-local
|
||||
ARG LOCAL_REPO_PATH
|
||||
COPY ${LOCAL_REPO_PATH}/output/be /release/be_artifacts/be
|
||||
|
||||
|
||||
FROM artifacts-from-${ARTIFACT_SOURCE} as artifacts
|
||||
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update -y \
|
||||
&& apt-get install -y --no-install-recommends binutils-dev default-jdk python2 \
|
||||
mysql-client curl vim tree net-tools \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV JAVA_HOME=/lib/jvm/default-java
|
||||
|
||||
ARG STARROCKS_ROOT=/opt/starrocks
|
||||
|
||||
WORKDIR $STARROCKS_ROOT
|
||||
|
||||
# Copy all artifacts to the runtime container image
|
||||
COPY --from=artifacts /release/be_artifacts/ $STARROCKS_ROOT/
|
||||
|
||||
# Copy be k8s scripts to the runtime container image
|
||||
COPY docker/bin/be_* $STARROCKS_ROOT/
|
||||
|
||||
# Create directory for BE storage
|
||||
RUN mkdir -p $STARROCKS_ROOT/be/storage
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
# This docker file build the Starrocks backend developement environment with all the tooling, dependencies libraries and
|
||||
# maven dependencies pre-installed.
|
||||
# Please run this command from the git repo root directory to build:
|
||||
# DOCKER_BUILDKIT=1 docker build --rm=true -f docker/dockerfiles/dev-env-ubuntu.Dockerfile -t starrocks/dev-env-ubuntu:tag .
|
||||
|
||||
FROM ubuntu:22.04 as base
|
||||
|
||||
# Install common libraries and tools that are needed for dev environment
|
||||
RUN apt-get update -y && \
|
||||
apt-get install --no-install-recommends -y \
|
||||
automake binutils-dev bison byacc ccache flex libiberty-dev libtool maven zip python3 python-is-python3 make cmake gcc g++ default-jdk git patch lld bzip2 \
|
||||
wget unzip curl vim tree net-tools openssh-client && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV JAVA_HOME=/lib/jvm/default-java
|
||||
ENV STARROCKS_THIRDPARTY=/opt/starrocks/thirdparty
|
||||
ENV STARROCKS_LINKER=lld
|
||||
|
||||
WORKDIR /root
|
||||
|
||||
FROM base as builder
|
||||
COPY . ./starrocks
|
||||
|
||||
# build third-party dependencies
|
||||
RUN mkdir -p $STARROCKS_THIRDPARTY/installed && cd starrocks/thirdparty &&\
|
||||
./build-thirdparty.sh && cp -r installed $STARROCKS_THIRDPARTY/
|
||||
|
||||
# build fe to trigger downloading all the maven dependencies
|
||||
RUN cd starrocks && MAVEN_OPTS='-Dmaven.artifact.threads=128' ./build.sh --fe
|
||||
|
||||
# build be to trigger downloading all the maven dependencies
|
||||
RUN cd starrocks && ./build.sh --be --clean -j `nproc`
|
||||
|
||||
FROM base as dev-env
|
||||
|
||||
LABEL org.opencontainers.image.source="https://github.com/StarRocks/starrocks"
|
||||
|
||||
# Copy third-party dependencies
|
||||
COPY --from=builder $STARROCKS_THIRDPARTY $STARROCKS_THIRDPARTY
|
||||
|
||||
# Copy maven dependencies
|
||||
COPY --from=builder /root/.m2 /root/.m2
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
# This docker file build the Starrocks fe ubuntu image
|
||||
# Please run this command from the git repo root directory to build:
|
||||
# - Use artifact image to package runtime container:
|
||||
# > DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=image --build-arg ARTIFACTIMAGE=ghcr.io/dengliu/starrocks/artifact-ubuntu:latest -f docker/dockerfiles/fe-ubuntu.Dockerfile -t fe-ubuntu:latest .
|
||||
# - Use locally build artifacts to package runtime container:
|
||||
# > DOCKER_BUILDKIT=1 docker build --build-arg ARTIFACT_SOURCE=local --build-arg LOCAL_REPO_PATH=. -f docker/dockerfiles/fe-ubuntu.Dockerfile -t fe-ubuntu:latest .
|
||||
|
||||
|
||||
# The artifact source used for packing the runtime docker image
|
||||
# image: copy the artifacts from a artifact docker image.
|
||||
# local: copy the artifacts from a local repo. Mainly used for local development and test.
|
||||
ARG ARTIFACT_SOURCE=image
|
||||
|
||||
ARG ARTIFACTIMAGE=artifact:latest
|
||||
FROM ${ARTIFACTIMAGE} as artifacts-from-image
|
||||
|
||||
# create a docker build stage that copy locally build artifacts
|
||||
FROM busybox:latest as artifacts-from-local
|
||||
ARG LOCAL_REPO_PATH
|
||||
COPY ${LOCAL_REPO_PATH}/output/fe /release/fe_artifacts/fe
|
||||
|
||||
|
||||
FROM artifacts-from-${ARTIFACT_SOURCE} as artifacts
|
||||
|
||||
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update -y \
|
||||
&& apt-get install -y --no-install-recommends default-jdk \
|
||||
mysql-client curl vim tree net-tools \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV JAVA_HOME=/lib/jvm/default-java
|
||||
|
||||
ARG STARROCKS_ROOT=/opt/starrocks
|
||||
|
||||
WORKDIR $STARROCKS_ROOT
|
||||
|
||||
# Copy all artifacts to the runtime container image
|
||||
COPY --from=artifacts /release/fe_artifacts/ $STARROCKS_ROOT/
|
||||
|
||||
# Copy fe k8s scripts to the runtime container image
|
||||
COPY docker/bin/fe_* $STARROCKS_ROOT/
|
||||
|
||||
# Create directory for FE metadata
|
||||
RUN mkdir -p /opt/starrocks/fe/meta
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 172 KiB |
Loading…
Reference in New Issue