Skip to content

Commit

Permalink
Refactored the OSB build system (#632)
Browse files Browse the repository at this point in the history
Signed-off-by: Govind Kamat <[email protected]>
  • Loading branch information
gkamat authored Sep 4, 2024
1 parent d039711 commit 6f0ae23
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 263 deletions.
116 changes: 14 additions & 102 deletions .ci/build.sh
Original file line number Diff line number Diff line change
@@ -1,128 +1,40 @@
#!/usr/bin/env bash

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you 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.

# fail this script immediately if any command fails with a non-zero exit code
set -e
# fail on pipeline errors, e.g. when grepping
set -o pipefail
# fail on any unset environment variables
set -u

function update_pyenv {
# need to have the latest pyenv version to ensure latest patch releases are installable
cd $HOME/.pyenv/plugins/python-build/../.. && git pull origin master --rebase && cd -
pyenv_init() {
PATH=$HOME/.pyenv/shims:$PATH:$HOME/.pyenv/bin
}

function build {
function setup {
export THESPLOG_FILE="${THESPLOG_FILE:-${BENCHMARK_HOME}/.benchmark/logs/actor-system-internal.log}"
# this value is in bytes, the default is 50kB. We increase it to 200kiB.
export THESPLOG_FILE_MAXSIZE=${THESPLOG_FILE_MAXSIZE:-204800}
# adjust the default log level from WARNING
export THESPLOG_THRESHOLD="INFO"

# turn nounset off because some of the following commands fail if nounset is turned on
set +u

export PATH="$HOME/.pyenv/bin:$PATH"
pyenv_init
export TERM=dumb
export LC_ALL=en_US.UTF-8
update_pyenv
eval "$(pyenv init -)"
# ensure pyenv shims are added to PATH, see https://github.com/pyenv/pyenv/issues/1906
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
}

function build {
setup

make prereq
make install
make precommit
set -e
make install-devel
make lint
make test
}

function build_it {
export THESPLOG_FILE="${THESPLOG_FILE:-${BENCHMARK_HOME}/.benchmark/logs/actor-system-internal.log}"
# this value is in bytes, the default is 50kB. We increase it to 200kiB.
export THESPLOG_FILE_MAXSIZE=${THESPLOG_FILE_MAXSIZE:-204800}
# adjust the default log level from WARNING
export THESPLOG_THRESHOLD="INFO"
setup

# turn nounset off because some of the following commands fail if nounset is turned on
set +u

export PATH="$HOME/.pyenv/bin:$PATH"
export TERM=dumb
export LC_ALL=en_US.UTF-8
export BENCHMARK_HOME="$GITHUB_WORKSPACE"

update_pyenv
eval "$(pyenv init -)"
# ensure pyenv shims are added to PATH, see https://github.com/pyenv/pyenv/issues/1906
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"

python3_version=`python3 --version`
echo "Python3 version is ... $python3_version"

python3 -m pip install opensearch-benchmark
docker pull ubuntu/squid:latest

make prereq
make install
make precommit

# make it38, it39, etc.
# make it38, it39, etc. so they run as concurrent GHA jobs
make "it${1//./}"
}

function license-scan {
# turn nounset off because some of the following commands fail if nounset is turned on
set +u

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
# ensure pyenv shims are added to PATH, see https://github.com/pyenv/pyenv/issues/1906
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"

make prereq
# only install depdencies that are needed by end users
make install-user
fossa analyze
}

function archive {
# Treat unset env variables as an error, but only in this function as there are other functions that allow unset variables
set -u

# this will only be done if the build number variable is present
BENCHMARK_DIR=${BENCHMARK_HOME}/.benchmark
if [[ -d ${BENCHMARK_DIR} ]]; then
find ${BENCHMARK_DIR} -name "*.log" -printf "%P\\0" | tar -cvjf ${BENCHMARK_DIR}/${BUILD_NUMBER}.tar.bz2 -C ${BENCHMARK_DIR} --transform "s,^,ci-${BUILD_NUMBER}/," --null -T -
else
echo "Benchmark directory [${BENCHMARK_DIR}] not present. Ensure the BENCHMARK_DIR environment variable is correct"
exit 1
fi
}
$@

if declare -F "$1" > /dev/null; then
"$@"
exit
else
echo "Please specify a function to run"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build and Test
name: Docker Build
on:
pull_request:
workflow_dispatch:
Expand Down Expand Up @@ -28,14 +28,12 @@ jobs:
with:
version: 'v0.9.1'
- uses: actions/checkout@v4
with:
path: 'opensearch-benchmark-git'

- name: Docker Build ${{ matrix.platform }}
run: |
docker buildx version
cp -a opensearch-benchmark-git/* ./
echo "Disable VERSION arg to enter docker build test mode"
PLATFORM=${{ matrix.platform }}
PLATFORM=`echo $PLATFORM | tr '/' '-'`
docker buildx build --platform ${{ matrix.platform }} --build-arg BUILD_ENV=testing --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` -f "docker/Dockerfile" -t "osb/osb-$PLATFORM" -o type=docker .
docker images | grep "osb/osb-$PLATFORM"
tag=osb/osb-`echo ${{ matrix.platform }} | tr '/' '-'`
set -x
docker buildx build --platform ${{ matrix.platform }} --build-arg VERSION=`cat version.txt` --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` -f docker/Dockerfile -t "$tag" -o type=docker .
set +x
docker images | grep "$tag"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integ Actions
name: Run Integration Tests
on: [workflow_dispatch, pull_request]
jobs:
Integration-Tests:
Expand All @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: KengoTODA/actions-setup-docker-compose@v1
with:
version: '1.29.2'

# - name: Enforce docker-compose v1
# run: |
# echo "GitHub starts to switch runners to include docker-compose v2"
Expand All @@ -27,43 +27,21 @@ jobs:
# sudo pip install docker-compose==1.29.2
# docker --version
# docker-compose --version

- name: Check out repository code
uses: actions/checkout@v2
- name: Clone pyenv

- name: Install pyenv
run: git clone https://github.com/pyenv/pyenv.git ~/.pyenv
- name: Clone pyenv-virtualenv
run: git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
- name: Install JDK 8
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '8'
- run: echo "JAVA8_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Install JDK 11
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- run: echo "JAVA11_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Install JDK 15
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '15'
- run: echo "JAVA15_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Install JDK 16
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '16'
- run: echo "JAVA16_HOME=$JAVA_HOME" >> $GITHUB_ENV

- name: Install JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'
- run: echo "JAVA17_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Run the CI build_it script

- name: Run the CI build script
run: bash .ci/build.sh build_it ${{ matrix.python-version }}
env:
BENCHMARK_HOME: env.GITHUB_WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI Actions
on: [pull_request]
name: Run Unit Tests
on: [workflow_dispatch, pull_request]
jobs:
Unit-Tests:
strategy:
Expand All @@ -8,11 +8,14 @@ jobs:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}

steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Clone pyenv
run: git clone https://github.com/pyenv/pyenv.git ~/.pyenv

- name: Run the CI build script
run: bash .ci/build.sh build
env:
Expand Down
11 changes: 2 additions & 9 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This document will walk you through on what's needed to start contributing code

### Prerequisites

- **Pyenv** : Install `pyenv` and follow the instructions in the output of `pyenv init` to set up your shell and restart it before proceeding.
- **Pyenv**: Install `pyenv` and follow the instructions in the output of `pyenv init` to set up your shell and restart it before proceeding.
For more details please refer to the [PyEnv installation instructions](https://github.com/pyenv/pyenv#installation).

**Optional Step:** For Debian-based systems, install the following modules to continue with the next steps:
Expand Down Expand Up @@ -54,15 +54,8 @@ For those working on WSL2, it is recommended to clone the repository and set up
After you git cloned the forked copy of OpenSearch Benchmark, use the following command-line instructions to set up OpenSearch Benchmark for development:
```
cd opensearch-benchmark
make prereq
make install
```

NOTE: `make prereq` produces the following message.
```
IMPORTANT: please add `eval "$(pyenv init -)"` to your bash profile and restart your terminal before proceeding any further.
make install-devel
```
This line is commonly thought of as an error message but rather it's just a warning. Unless you haven't already added `eval "$(pyenv init -)"` to your bash profile and restarted your terminal, then feel free to proceed forward. This eval statement is necessary in the startup configuration as it allows Pyenv to manage python versions by adding python shims to your path. If you experience any issues, please see https://github.com/pyenv/pyenv.

Depending on the platform and shell you have, use the following command to activate the virtual environment:

Expand Down
Loading

0 comments on commit 6f0ae23

Please sign in to comment.