Skip to content

Commit

Permalink
[native] PrestoCpp build from source pipeline
Browse files Browse the repository at this point in the history
Fully automated build process for PrestoCpp and Velox from source.
README file added for clarification.

Signed-off-by: Linkiewicz, Milosz <milosz.linkiewicz@intel.com>
  • Loading branch information
Mionsz authored and kgpai committed Nov 28, 2022
1 parent eeb5a7d commit bffd8c6
Show file tree
Hide file tree
Showing 9 changed files with 1,039 additions and 12 deletions.
15 changes: 13 additions & 2 deletions presto-native-execution/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.PHONY: all cmake build clean debug release unit submodules velox-submodule
.PHONY: all cmake build clean debug release unittest submodules velox-submodule

BUILD_BASE_DIR=_build
BUILD_DIR=release
Expand All @@ -19,15 +19,19 @@ ENABLE_WALL ?= 1
NUM_THREADS ?= $(shell getconf _NPROCESSORS_CONF 2>/dev/null || echo 1)
CPU_TARGET ?= "avx"
CMAKE_PREFIX_PATH ?= "/usr/local"
PRESTOCPP_ROOT_DIR="$(shell pwd)"

PRESTO_ENABLE_PARQUET ?= "OFF"
PRESTO_ENABLE_S3 ?= "OFF"
PRESTO_ENABLE_HDFS ?= "OFF"
EXTRA_CMAKE_FLAGS ?= ""

CMAKE_FLAGS := -DTREAT_WARNINGS_AS_ERRORS=${TREAT_WARNINGS_AS_ERRORS}
CMAKE_FLAGS += -DENABLE_ALL_WARNINGS=${ENABLE_WALL}
CMAKE_FLAGS += -DCMAKE_PREFIX_PATH=$(CMAKE_PREFIX_PATH)
CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
CMAKE_FLAGS += -DPRESTO_ENABLE_PARQUET=$(PRESTO_ENABLE_PARQUET)
CMAKE_FLAGS += -DPRESTO_ENABLE_S3=$(PRESTO_ENABLE_S3)
CMAKE_FLAGS += -DPRESTO_ENABLE_HDFS=$(PRESTO_ENABLE_HDFS)

SHELL := /bin/bash
Expand Down Expand Up @@ -58,7 +62,7 @@ velox-submodule: #: Check out code for velox submodule
submodules: velox-submodule

cmake: submodules #: Use CMake to create a Makefile build system
cmake -B "$(BUILD_BASE_DIR)/$(BUILD_DIR)" $(FORCE_COLOR) $(CMAKE_FLAGS)
cmake -B "$(BUILD_BASE_DIR)/$(BUILD_DIR)" $(FORCE_COLOR) $(CMAKE_FLAGS) $(EXTRA_CMAKE_FLAGS)

build: #: Build the software based in BUILD_DIR and BUILD_TYPE variables
cmake --build $(BUILD_BASE_DIR)/$(BUILD_DIR) -j $(NUM_THREADS)
Expand Down Expand Up @@ -109,6 +113,13 @@ linux-container:
cd /tmp/docker && \
docker build --build-arg cpu_target=$(CPU_TARGET) --tag "prestocpp/prestocpp-$(CPU_TARGET)-$(CONTAINER_NAME):$(USER)-$(shell date +%Y%m%d)" -f $(CONTAINER_NAME)-container.dockfile .

runtime-container:
rm -rf /tmp/release-centos-dockerfile && \
mkdir -p /tmp/release-centos-dockerfile && \
cp -r scripts/build-centos.sh scripts/release-centos-dockerfile /tmp/release-centos-dockerfile && \
cd /tmp/release-centos-dockerfile && \
PRESTOCPP_ROOT_DIR=$(PRESTOCPP_ROOT_DIR) ./build-centos.sh

help: #: Show the help messages
@cat $(firstword $(MAKEFILE_LIST)) | \
awk '/^[-a-z]+:/' | \
Expand Down
26 changes: 16 additions & 10 deletions presto-native-execution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Run `make` in the root directory to compile the sources. For development, use
`make debug` to build a non-optimized debug version. Use `make unittest` to build
and run tests.

## Building Dockerfile from source
Run `make runtime-container` in the presto-native-execution root directory
to build run-ready containerized version of PrestoCpp. Information on available
configuration options can be found in [scripts/release-centos-dockerfile/README.md](scripts/release-centos-dockerfile/README.md)

### Makefile targets
A reminder of the available Makefile targets can be obtained using `make help`
```
Expand All @@ -39,6 +44,7 @@ A reminder of the available Makefile targets can be obtained using `make help`
tidy-fix Fix clang-tidy issues in the current branch
tidy-check Check clang-tidy issues in the current branch
linux-container Build the CircleCi linux container from scratch
runtime-container Build the software in container using current git commit
help Show the help messages
```

Expand All @@ -48,12 +54,12 @@ A reminder of the available Makefile targets can be obtained using `make help`

Makefile targets exist for showing, fixing and checking formatting, license
headers and clang-tidy warnings. These targets are shortcuts for calling
`./scripts/check.py`.
`./scripts/check.py`.

GitHub Actions run `make format-check`, `make header-check` and
`make tidy-check` as part of our continuous integration. Pull requests should
pass linux-build, format-check, header-check and other jobs without errors
before being accepted.
before being accepted.

Formatting issues found on the changed lines in the current commit can be
displayed using `make format-show`. These issues can be fixed by using `make
Expand All @@ -68,13 +74,13 @@ commit.
Similar commands `make tidy-show`, `make-tidy-fix`, `make tidy-check` exist for
running clang-tidy, but these checks are currently advisory only.

An entire directory tree of files can be formatted and have license headers added
An entire directory tree of files can be formatted and have license headers added
using the `tree` variant of the format.sh commands:
```
./scripts/check.py format tree
./scripts/check.py format tree
./scripts/check.py format tree --fix
./scripts/check.py header tree
./scripts/check.py header tree
./scripts/check.py header tree --fix
```

Expand Down Expand Up @@ -103,7 +109,7 @@ export PATH=$HOME/bin:$HOME/Library/Python/3.7/bin:$PATH
* Clone the whole Presto repository.
* Run `presto/presto-native-execution/scripts/setup-centos.sh`

### Setting up local Presto environment on MacOS (with optional IntelliJ and CLion)
### Setting up local Presto environment on MacOS (with optional IntelliJ and CLion)
Clone the whole Presto repository.

Close IntelliJ and CLion
Expand Down Expand Up @@ -133,7 +139,7 @@ Run IntelliJ
In "presto/presto-native-execution" run:
* `make -C presto-native-execution submodules`
* `git/presto/presto-native-execution % sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/sbin; sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/bin; sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/lib; chmod u+w /usr/local/bin /usr/local/lib /usr/local/sbin; chmod u+w /usr/local/bin /usr/local/lib /usr/local/bin; chmod u+w /usr/local/bin /usr/local/lib /usr/local/lib; ./scripts/setup-macos.sh`

Run CLion:
* File->Close Project if any is open.
* Open `presto/presto-native-execution` folder as CMake project and wait till CLion loads/generates cmake files, symbols, etc.
Expand Down Expand Up @@ -166,7 +172,7 @@ Running Presto Coordinator + Worker on MacOS
### Running Integration (End to End or E2E) Tests on MacOS (with optional IntelliJ and CLion)
* Note that everything below can be done w/o using IDEs by running command line commands (not in this readme).
* Open a test file which has the test(s) you want to run in IntelliJ from `presto/presto-native-execution/src/test/java/com/facebook/presto/nativeworker` path.
* Click the green arrow to the left of the test class line of code and chose if you want to Run or Debug. This will run all tests in this class.
* Click the green arrow to the left of the test class line of code and chose if you want to Run or Debug. This will run all tests in this class.
* Alternatively click the green arrow to the left of the test class' test method line of code and chose if you want tor Run or Debug. This will run all tests only in this class's member.
* The framework will launch single Coordinator and four native workers to test-run the queries.
* Similarly, the unit tests of Velox and presto_cpp can be run from CLion.
Expand All @@ -181,5 +187,5 @@ Running Presto Coordinator + Worker on MacOS

### Creating PRs for presto/presto-native-execution/
* Submit PRs as usual following [Presto repository guidelines](https://github.com/prestodb/presto/wiki/Review-and-Commit-guidelines).
* On top of it please add `[native]` prefix in the `title` as well as to the `commit message` for PRs modifying anything in `presto-native-execution`.
* PRs that only change files in `presto-native-execution` should be approved by a Code Owner ([team-velox](https://github.com/orgs/prestodb/teams/team-velox)) to have merging enabled.
* On top of it please add `[native]` prefix in the `title` as well as to the `commit message` for PRs modifying anything in `presto-native-execution`.
* PRs that only change files in `presto-native-execution` should be approved by a Code Owner ([team-velox](https://github.com/orgs/prestodb/teams/team-velox)) to have merging enabled.
112 changes: 112 additions & 0 deletions presto-native-execution/scripts/build-centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SCRIPT_DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
source $SCRIPT_DIR/release-centos-dockerfile/opt/common.sh

set -eE -o pipefail
trap 'error "Stage failed, exiting"; exit 5' SIGSTOP SIGINT SIGTERM SIGQUIT ERR

print_logo

export CPU_TARGET=${CPU_TARGET:-'avx'}
export BASE_IMAGE=${BASE_IMAGE:-'quay.io/centos/centos:stream8'}
export IMAGE_NAME=${IMAGE_NAME:-"presto/prestissimo-${CPU_TARGET}-centos"}
export IMAGE_TAG=${IMAGE_TAG:-"latest"}
export IMAGE_REGISTRY=${IMAGE_REGISTRY:-''}
export IMAGE_PUSH=${IMAGE_PUSH:-'0'}

export USER_FLAGS=${USER_FLAGS:-''}
export PRESTOCPP_ROOT_DIR=${PRESTOCPP_ROOT_DIR:-"$(readlink -f "$SCRIPT_DIR/..")"}
export PRESTODB_REPOSITORY=${PRESTODB_REPOSITORY:-"$(cd "${PRESTOCPP_ROOT_DIR}/.." && git config --get remote.origin.url)"}
export PRESTODB_CHECKOUT=${PRESTODB_CHECKOUT:-"$(cd "${PRESTOCPP_ROOT_DIR}/.." && git show -s --format="%H" HEAD)"}
BUILD_LOGS_FILEPATH="${SCRIPT_DIR}/$(date +%Y%m%d%H%M%S)-${USER}-${CPU_TARGET}-build-centos.log"
(
prompt "Using build time variables:"
prompt "------------"
prompt "\tIMAGE_NAME=${IMAGE_NAME}"
prompt "\tIMAGE_TAG=${IMAGE_TAG}"
prompt "\tIMAGE_REGISTRY=${IMAGE_REGISTRY}"
prompt "\tBASE_IMAGE=${BASE_IMAGE}"
prompt "\tCPU_TARGET=${CPU_TARGET}"
prompt "\tUSER_FLAGS=${USER_FLAGS}"
prompt "------------"
prompt "\tPRESTODB_REPOSITORY=${PRESTODB_REPOSITORY}"
prompt "\tPRESTODB_CHECKOUT=${PRESTODB_CHECKOUT}"
prompt "------------"
prompt "Using build time computed variables:"
prompt "\t[1/2] Base build image: ${BASE_IMAGE}"
prompt "\t[2/2] Release image tag: ${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG}"
prompt "------------"
prompt "Build logs: ${BUILD_LOGS_FILEPATH}"
prompt "------------"
) 2>&1 |
tee "${BUILD_LOGS_FILEPATH}"
(
prompt "[1/2] Preflight Git checks stage starting $(txt_yellow remote commit exisitance)" &&
prompt "[1/2] Fetching remote repository" &&
cd "${PRESTOCPP_ROOT_DIR}/.." > /dev/null &&
git fetch --all > /dev/null &&
prompt "[1/2] Checking if local hash is available on remote repository" &&
git branch -r --contains $PRESTODB_CHECKOUT > /dev/null ||
( error '[1/2] Preflight stage failed, commit not found. Exiting.' && exit 1 )
) 2>&1 |
tee -a "${BUILD_LOGS_FILEPATH}"
(
prompt "[2/2] Preflight CPU checks stage starting $(txt_yellow processor instructions)"
error=0
check=$(txt_green success)
prompt "Velox build requires bellow CPU instructions to be available:"
for flag in 'bmi|bmi1' 'bmi2' 'f16c';
do
echo $(cat /proc/cpuinfo) | grep -E -q " $flag " && check=$(txt_green success) || check=$(txt_red failed) error=1
prompt "Testing (${flag}): \t$check"
done
prompt "Velox build suggest bellow CPU instructions to be available:"
for flag in avx avx2 sse;
do
echo $(cat /proc/cpuinfo) | grep -q " $flag " && check=$(txt_green success) || check=$(txt_yellow failed)
prompt "Testing (${flag}): \t$check"
done
[ $error -eq 0 ] || ( error 'Preflight checks failed, lack of CPU functionality. Exiting.' && exit 1 )
prompt "[2/2] Preflight CPU checks $(txt_green success)"
) 2>&1 |
tee -a "${BUILD_LOGS_FILEPATH}"
(
prompt "[1/1] Build stage starting $(txt_yellow ${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG})" &&
cd "${SCRIPT_DIR}" &&
docker build $USER_FLAGS \
--network=host \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg no_proxy \
--build-arg CPU_TARGET \
--build-arg BASE_IMAGE \
--build-arg PRESTODB_REPOSITORY \
--build-arg PRESTODB_CHECKOUT \
--tag "${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG}" \
./release-centos-dockerfile &&
prompt "[1/1] Build finished" &&
(
[ "$IMAGE_PUSH" == "1" ] &&
prompt "[1/1] Pushing image $(txt_yellow ${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG})" &&
docker push "${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG}" || true
) &&
prompt "[1/1] Build finished $(txt_green ${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG})" ||
( error '[1/1] Build failed. Exiting' && exit 2 )
) 2>&1 |
tee -a "${BUILD_LOGS_FILEPATH}"

prompt "Prestissimo is ready for deployment"
prompt "Image tagged as: ${IMAGE_REGISTRY}${IMAGE_NAME}:${IMAGE_TAG}"
Loading

0 comments on commit bffd8c6

Please sign in to comment.