Skip to content

Commit fc9c147

Browse files
Refactor build env logic to switch between testing and production (opensearch-project#604)
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
1 parent 23b10f0 commit fc9c147

File tree

5 files changed

+20
-132
lines changed

5 files changed

+20
-132
lines changed

.github/workflows/docker-test.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
architecture: ['linux/amd64', 'linux/arm64']
21+
platform: ['linux/amd64', 'linux/arm64']
2222
steps:
2323
- name: Set up QEMU
2424
uses: docker/setup-qemu-action@v3
@@ -30,9 +30,12 @@ jobs:
3030
- uses: actions/checkout@v4
3131
with:
3232
path: 'opensearch-benchmark-git'
33-
- name: Docker Build and Test on ${{ matrix.architecture }}
33+
- name: Docker Build ${{ matrix.platform }}
3434
run: |
3535
docker buildx version
3636
cp -a opensearch-benchmark-git/* ./
3737
echo "Disable VERSION arg to enter docker build test mode"
38-
docker buildx build --platform ${{ matrix.architecture }} --build-arg BUILD_DATE=`date -u +%Y-%m-%dT%H:%M:%SZ` -f "docker/Dockerfile" .
38+
PLATFORM=${{ matrix.platform }}
39+
PLATFORM=`echo $PLATFORM | tr '/' '-'`
40+
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 .
41+
docker images | grep "osb/osb-$PLATFORM"

docker/Dockerfile

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
###############################################################################
2-
# Install OpenSearch Benchmark from PyPI to build a Docker image
3-
###############################################################################
1+
########################################################
2+
# Install OpenSearch Benchmark to build a Docker image #
3+
########################################################
44

5-
FROM python:3.11.2-slim
6-
ARG VERSION=testing
5+
ARG VERSION
6+
ARG BUILD_ENV=production
77

8-
ENV BENCHMARK_RUNNING_IN_DOCKER=True
8+
FROM python:3.11.2-slim as build_env_testing
9+
ONBUILD COPY opensearch-benchmark-git/ ./
10+
11+
FROM python:3.11.2-slim as build_env_production
12+
ONBUILD RUN echo Production Environment
913

14+
FROM build_env_${BUILD_ENV}
1015
WORKDIR /opensearch-benchmark
16+
ENV BENCHMARK_RUNNING_IN_DOCKER=True
1117

1218
RUN apt-get -y update && \
1319
apt-get install -y curl git gcc pbzip2 pigz && \
@@ -18,15 +24,8 @@ RUN groupadd --gid 1000 opensearch-benchmark && \
1824
useradd -d /opensearch-benchmark -m -k /dev/null -g 1000 -N -u 1000 -l -s /bin/bash benchmark
1925

2026
ENV PIP_ONLY_BINARY=h5py
21-
22-
# Copy file for test purpose and will remove during prod publishing
23-
COPY opensearch-benchmark-git/ ./opensearch-benchmark-git
24-
25-
# Currently we always have the $VERSION arg substituted during prod publishing
26-
# Default VERSION=testing to enter test mode based on user inputs.
27-
RUN if [ "$VERSION" = "testing" ] ; then echo Testing; cp -a opensearch-benchmark-git/* ./; ls -l; python3 -m pip install -e . ; \
28-
else echo Production; rm -rf opensearch-benchmark-git; ls -l; python3 -m pip install opensearch-benchmark==$VERSION ; fi
29-
27+
RUN if [ "$BUILD_ENV" = "testing" ] ; then echo Testing; ls -l; python3 -m pip install -e . ; \
28+
else echo Production; if [ -z "$VERSION" ] ; then python3 -m pip install opensearch-benchmark ; else python3 -m pip install opensearch-benchmark==$VERSION ; fi; fi
3029

3130
RUN mkdir -p /opensearch-benchmark/.benchmark && \
3231
chown -R 1000:0 /opensearch-benchmark/.benchmark

docker/Dockerfile-development

-75
This file was deleted.

docker/docker-compose-tests.yml

-37
This file was deleted.

jenkins/release.JenkinsFile

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ standardReleasePipelineWithGenericTrigger(
1818
string(name: 'DOCKER_BUILD_GIT_REPOSITORY_REFERENCE', value: 'main'),
1919
string(name: 'DOCKER_BUILD_SCRIPT_WITH_COMMANDS', value: [
2020
'su $(id -un 1000) -c "cd docker/ci',
21-
'mkdir -p opensearch-benchmark-git',
22-
'echo Production > opensearch-benchmark-git/status.txt'
2321
'git clone https://github.com/opensearch-project/opensearch-benchmark opensearch-benchmark',
2422
'cp -a opensearch-benchmark/* ./"',
2523
'cd docker/ci',

0 commit comments

Comments
 (0)