Skip to content

Commit

Permalink
build: fix docker build (OpenAtomFoundation#1391)
Browse files Browse the repository at this point in the history
  • Loading branch information
machinly authored May 9, 2023
1 parent 9d7db8a commit 1c44263
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 39 deletions.
85 changes: 47 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
FROM centos:7 as builder
FROM ubuntu:22.04 AS builder

LABEL maintainer="[email protected], [email protected]"

ENV PIKA /pika
ENV PIKA_BUILD_DIR /tmp/pika
ENV PATH ${PIKA}:${PIKA}/bin:${PATH}
ENV PIKA=/pika \
PIKA_BUILD_DIR=/tmp/pika \
PATH=${PIKA}:${PIKA}/bin:${PATH}

COPY . ${PIKA_BUILD_DIR}
ARG ENABLE_PROXY=false

RUN if [ "$ENABLE_PROXY" = "true" ] ; \
then sed -i 's/http:\/\/archive.ubuntu.com/http:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list ; \
sed -i 's/http:\/\/ports.ubuntu.com/http:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list ; \
fi

RUN apt-get update && apt-get install -y \
ca-certificates \
build-essential \
git \
cmake \
autoconf

WORKDIR ${PIKA_BUILD_DIR}

RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm && \
yum clean all && \
yum -y makecache && \
yum -y install snappy-devel && \
yum -y install protobuf-devel && \
yum -y install gflags-devel && \
yum -y install glog-devel && \
yum -y install bzip2-devel && \
yum -y install zlib-devel && \
yum -y install lz4-devel && \
yum -y install libzstd-devel && \
yum -y install gcc-c++ && \
yum -y install make && \
yum -y install which && \
yum -y install git && \
make -j$(shell grep -c ^processor /proc/cpuinfo 2>/dev/null) && \
cp -r ${PIKA_BUILD_DIR}/output ${PIKA} && \
cp -r ${PIKA_BUILD_DIR}/entrypoint.sh ${PIKA} && \
yum -y remove gcc-c++ && \
yum -y remove make && \
yum -y remove which && \
yum -y remove git && \
yum -y clean all

FROM centos:7
ENV PIKA /pika
ENV PATH ${PIKA}:${PIKA}/bin:${PATH}

RUN set -eux; yum install -y epel-release; \
yum install -y snappy protobuf gflags glog bzip2 zlib lz4 libzstd rsync; \
yum clean all;
COPY . ${PIKA_BUILD_DIR}

RUN ${PIKA_BUILD_DIR}/build.sh

FROM ubuntu:22.04

ARG ENABLE_PROXY=false

RUN if [ "$ENABLE_PROXY" = "true" ] ; \
then sed -i 's/http:\/\/archive.ubuntu.com/http:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list ; \
sed -i 's/http:\/\/ports.ubuntu.com/http:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list ; \
fi

RUN apt-get update && apt-get install -y \
ca-certificates \
rsync && \
apt-get clean && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

ENV PIKA=/pika \
PIKA_BUILD_DIR=/tmp/pika \
PATH=${PIKA}:${PIKA}/bin:${PATH}

WORKDIR ${PIKA}
COPY --from=builder $PIKA ./

ENTRYPOINT ["/pika/entrypoint.sh"]
COPY --from=builder ${PIKA_BUILD_DIR}/output/pika ${PIKA}/bin/pika
COPY --from=builder ${PIKA_BUILD_DIR}/entrypoint.sh /entrypoint.sh
COPY --from=builder ${PIKA_BUILD_DIR}/conf/pika.conf ${PIKA}/conf/pika.conf

ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 9221

CMD ["/pika/bin/pika", "-c", "/pika/conf/pika.conf"]
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -x

#color code
C_RED="\033[31m"
C_GREEN="\033[32m"
Expand Down Expand Up @@ -112,4 +114,7 @@ make -j ${CPU_CORE}

if [ $? -eq 0 ]; then
echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}"
else
echo -e "${C_RED} pika compile fail ${C_END}"
exit 1
fi
102 changes: 102 additions & 0 deletions build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#! /bin/bash

# parse arguments
# -t tag, default is "pikadb/pika:<git tag>"
# -p platform , it will use docker buildx, options: all, linux/amd64, linux/arm64, linux/arm, linux/arm64, darwin/amd64 more details: https://docs.docker.com/build/building/multi-platform/
# --proxy proxy, proxy has no value, if you want to use proxy, just add --proxy. if you are in China, you may need to use proxy download the package for up speed the build process
# --help help

while getopts "t:p:-:" opt; do
case $opt in
t)
TAG=$OPTARG
;;
p)
PLATFORM=$OPTARG
MULTIARCHIVE=true
;;
-)
case $OPTARG in
proxy)
proxy=1
;;
help)
echo "Usage: build_docker.sh [-t tag] [-p platform] [--proxy] [--help]"
echo ""
echo "Options:"
echo " -t tag default is \"pikadb/pika:<git tag>\""
echo " -p <plat>,[<plat>] default is current docker platform. "
echo " options: all, linux/amd64, linux/arm, linux/arm64"
echo " more details: https://docs.docker.com/build/building/multi-platform "
echo " --proxy use proxy download the package for up speed the build process in CN."
echo " --help help"
echo ""
echo "eg:"
echo " ./build_docker.sh -p linux/amd64,linux/arm64 -t pikadb/pika:latest --proxy "
exit 0
;;

*)
echo "Unknown option --$OPTARG"
exit 1
;;
esac
;;
*)
echo "Unknown option -$opt"
exit 1
;;
esac
done


# if TAG is not set, set it "pikadb/pika"
if [ -z "$TAG" ]
then
TAG="pikadb/pika:$(git describe --tags --abbrev=0 --always)"
fi

# if Platform is not set, set it "linux/amd64"
if [ -z "$PLATFORM" ]
then
PLATFORM="linux/amd64"
fi

# if Platform is "all", set it "linux/amd64,linux/arm64,linux/arm"
if [ "$PLATFORM" = "all" ]
then
PLATFORM="linux/amd64,linux/arm,linux/arm64"
fi

# if proxy is set, set it
if [ -n "$proxy" ]
then
PROXY=true
else
PROXY=false
fi

# check if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed.' >&2
exit 1
fi


if [ "$MULTIARCHIVE" = true ]
then
# check if `docker buildx inpsect pika-builder` is ok
if ! docker buildx inspect pika-builder > /dev/null 2>&1; then
docker buildx create --use --name=pika-builder --driver docker-container
else
docker buildx use pika-builder
fi

docker buildx build --platform ${PLATFORM} -t ${TAG} --build-arg ENABLE_PROXY=${PROXY} .

else
# build single-arch image
docker build -t ${TAG} --build-arg ENABLE_PROXY=${PROXY} .
fi


2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# CONFIG(path1;path2)
# You can add the path of configuration file or folder to the CONFIG
Expand Down

0 comments on commit 1c44263

Please sign in to comment.