Skip to content

Commit 587b74f

Browse files
authored
Container Publishing and Build Paralellism (#215)
1 parent 61c2596 commit 587b74f

18 files changed

+614
-169
lines changed

.devcontainer/devcontainer.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
{
44
"name": "Workspace Dockerfile",
55

6-
// Sets the run context to one level up instead of the .devcontainer folder.
7-
"context": "..",
6+
// We have no context for the devcontainer.
7+
"context": ".",
88

99
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
10-
"dockerFile": "../docker/benchbase/Dockerfile",
10+
"dockerFile": "../docker/benchbase/devcontainer/Dockerfile",
1111
"build": {
12-
"target": "devcontainer",
1312
"args": {
1413
"--tag": "benchbase-dev:latest"
15-
}
14+
},
15+
"cacheFrom": "benchbase.azurecr.io/benchbase-dev"
1616
},
1717

1818
// Set *default* container specific settings.json values on container create.
@@ -35,6 +35,10 @@
3535

3636
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
3737
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
38+
// Use the local maven cache.
39+
"mounts": [
40+
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.m2,target=/home/containeruser/.m2,type=bind,consistency=cached"
41+
],
3842

3943
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
4044
"remoteUser": "containeruser"

.dockerignore

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/maven.yml

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,29 @@
77
# The CI jobs are set up as follows:
88
# - One job to build and upload artifacts.
99
# - One job per DBMS test suite.
10+
# - One job to build/test the docker images.
11+
# - One job to publish the docker image.
1012

1113
name: BenchBase (Java with Maven)
1214

1315
on:
1416
push:
1517
branches: [ main ]
18+
# Generate new docker images on release tags.
19+
tags:
20+
- 'v*'
1621
pull_request:
1722
branches: [ main ]
23+
# Run these workflows on a schedule so that docker images are regularly updated for security patches.
24+
schedule:
25+
- cron: "1 0 * * *"
26+
# Give us a button to allow running the workflow on demand for testing.
27+
workflow_dispatch:
28+
inputs:
29+
tags:
30+
description: 'Manual Workflow Run'
31+
required: false
32+
type: string
1833

1934
env:
2035
POM_VERSION: 2021-SNAPSHOT
@@ -356,10 +371,14 @@ jobs:
356371
java -jar benchbase.jar -b ${{matrix.benchmark}} -c config/sqlserver/sample_${{matrix.benchmark}}_config.xml --create=true --load=true --execute=true
357372
358373
## ----------------------------------------------------------------------------------
359-
## Docker Build Test
374+
## Docker Build Test Publish
360375
## ----------------------------------------------------------------------------------
361-
docker-build-test:
376+
docker-build-test-publish:
362377
runs-on: ubuntu-latest
378+
env:
379+
DOCKER_BUILDKIT: 1
380+
BENCHBASE_PROFILES: 'cockroachdb mariadb mysql postgres spanner phoenix sqlserver sqlite'
381+
CONTAINER_REGISTRY_NAME: ${{ secrets.ACR_LOGINURL }}
363382
services:
364383
postgres: # https://hub.docker.com/_/postgres
365384
image: postgres:latest
@@ -381,25 +400,58 @@ jobs:
381400
PGPASSWORD=password createdb -h localhost -U admin benchbase
382401
- name: Checkout repo
383402
uses: actions/checkout@v2
384-
- name: Build docker image with all packages and run test suite
403+
# https://github.com/actions/cache/blob/master/examples.md#java---maven
404+
- name: Cache local Maven repository
405+
uses: actions/cache@v2
406+
with:
407+
path: ~/.m2/repository
408+
# Try to use the same key as https://github.com/actions/setup-java uses in the steps above.
409+
key: setup-java-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
410+
restore-keys: |
411+
setup-java-${{ runner.os }}-maven-
412+
- name: Build benchbase-dev image
413+
run: |
414+
./docker/benchbase/build-dev-image.sh
415+
# Note: this script maps the local .m2 cache into the container.
416+
- name: Build the benchbase docker image with all profiles using the dev image
385417
env:
386-
DOCKER_BUILDKIT: 1
387-
BENCHBASE_PROFILES: 'cockroachdb mariadb mysql postgres spanner phoenix sqlserver'
418+
SKIP_TESTS: 'false'
388419
run: |
389-
docker build --build-arg "BENCHBASE_PROFILES=$BENCHBASE_PROFILES" --build-arg TEST_TARGET=test \
390-
--build-arg CONTAINERUSER_UID=$UID --build-arg CONTAINERUSER_GID=$UID \
391-
-t benchbase:latest -f ./docker/benchbase/Dockerfile --target fullimage .
392-
- name: Run basic benchbase test from the docker image against postgres test DB
420+
./docker/benchbase/build-full-image.sh
421+
- name: Run a basic test from the docker image against postgres test DB
393422
env:
394423
benchmark: noop
395424
run: |
396-
# Adjust the sample config to talk to the container service instead of localhost.
397-
cat "config/postgres/sample_${benchmark}_config.xml" | sed -e 's/localhost:5432/postgres:5432/g' > /tmp/config.xml
398-
# Lookup the service container's docker network so we can place the benchbase container in it too.
399-
docker_network="$(docker ps --filter expose=5432 --format '{{.Networks}}')"
400-
# Map the adjusted config into the container and use it to run the test.
401-
mkdir -p results
402-
docker run --rm --name benchbase-postgres --network "$docker_network" \
403-
--env BENCHBASE_PROFILE=postgres -v /tmp/config.xml:/tmp/config.xml -v "$PWD/results:/benchbase/results" \
404-
benchbase:latest -b "$benchmark" -c /tmp/config.xml --create=true --load=true --execute=true
405-
ls results/${benchmark}_*.csv
425+
for image in benchbase benchbase-postgres; do
426+
# Adjust the sample config to talk to the container service instead of localhost.
427+
cat "config/postgres/sample_${benchmark}_config.xml" | sed -e 's/localhost:5432/postgres:5432/g' > /tmp/config.xml
428+
# Lookup the service container's docker network so we can place the benchbase container in it too.
429+
docker_network="$(docker ps --filter expose=5432 --format '{{.Networks}}')"
430+
# Map the adjusted config into the container and use it to run the test.
431+
rm -rf results
432+
mkdir -p results
433+
docker run --rm --name benchbase-postgres --network "$docker_network" \
434+
--env BENCHBASE_PROFILE=postgres -v /tmp/config.xml:/tmp/config.xml -v "$PWD/results:/benchbase/results" \
435+
"$image" -b "$benchmark" -c /tmp/config.xml --create=true --load=true --execute=true
436+
# Test that the results files were produced.
437+
ls results/${benchmark}_*.csv
438+
done
439+
# Publish the docker image if the build/test was successful.
440+
# Only do this with approved PRs and if the login secrets are available.
441+
# Typically we expect to publish to benchbase.azurecr.io,
442+
# but setting ACR_LOGINURL to something else allows us to do testing on forks.
443+
- name: Log in to Docker Hub
444+
if: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && env.CONTAINER_REGISTRY_NAME != '' }}
445+
uses: docker/login-action@v2
446+
with:
447+
registry: ${{ secrets.ACR_LOGINURL }}
448+
username: ${{ secrets.ACR_USERNAME }}
449+
password: ${{ secrets.ACR_PASSWORD }}
450+
- name: Push Docker image
451+
if: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && env.CONTAINER_REGISTRY_NAME != '' }}
452+
run: |
453+
docker push -a ${{ secrets.ACR_LOGINURL}}/benchbase-dev
454+
docker push -a ${{ secrets.ACR_LOGINURL}}/benchbase
455+
for profile in $BENCHBASE_PROFILES; do
456+
docker push -a ${{ secrets.ACR_LOGINURL }}/benchbase-$profile
457+
done

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ results
1111
HELP.md
1212
PRIVATE.md
1313
target/
14+
profiles/
15+
docker/benchbase/fullimage/tmp/
1416
!.mvn/wrapper/maven-wrapper.jar
1517
!**/src/main/**
1618
!**/src/test/**

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ To modify the logging level you can update [`logging.properties`](src/main/resou
170170

171171
### How use with Docker
172172

173+
- Build or pull a dev image to help building from source:
174+
175+
```sh
176+
./docker/benchbase/build-dev-image.sh
177+
./docker/benchbase/run-dev-image.sh
178+
```
179+
180+
or
181+
182+
```sh
183+
docker run -it --rm --pull \
184+
-v /path/to/benchbase-source:/benchbase \
185+
-v $HOME/.m2:/home/containeruser/.m2 \
186+
benchbase.azure.cr.io/benchbase-dev
187+
```
188+
173189
- Build the full image:
174190

175191
```sh
@@ -186,7 +202,14 @@ To modify the logging level you can update [`logging.properties`](src/main/resou
186202
BENCHBASE_PROFILE='postgres' ./docker/benchbase/run-full-image.sh --help # or other benchbase args as before
187203
```
188204

189-
> See [scripts](./docker/benchbase/) for further details.
205+
or
206+
207+
```sh
208+
docker run -it --rm --env BENCHBASE_PROFILE='postgres' \
209+
-v results:/benchbase/results benchbase.azurecr.io/benchbase --help # or other benchbase args as before
210+
```
211+
212+
> See the [docker/benchbase/README.md](./docker/benchbase/) for further details.
190213
191214
[Github Codespaces](https://github.com/features/codespaces) and [VSCode devcontainer](https://code.visualstudio.com/docs/remote/containers) support is also available.
192215

docker/benchbase/Dockerfile

Lines changed: 0 additions & 82 deletions
This file was deleted.

docker/benchbase/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Benchbase Containers
2+
3+
This directory provides scripts for producing and running two different containers.
4+
5+
## Building Containers
6+
7+
1. `benchbase-dev` which can be used for *building* and *developing* `benchbase`.
8+
9+
It contains a full JDK and is expected to be run with the local source code checkout mapped into it (e.g. `docker run -v $repo_root:/benchbase benchbase-dev`).
10+
11+
The [`.devcontainer.json`](../../.devcontainer/devcontainer.json) config references this one and can be used with [Github Codespaces](https://github.com/features/codespaces) or [VS Code dev containers](https://code.visualstudio.com/docs/remote/containers).
12+
13+
See [`build-dev-image.sh`](./build-dev-image.sh) and [`run-dev-image.sh`](./run-dev-image.sh) for further details.
14+
15+
2. `benchbase` which can be used for easily *running* `benchbase` in a container environment (e.g. via Kubernetes).
16+
17+
It contains just a JRE and can be used for running prebuilt profiles of `benchbase`.
18+
19+
The `benchbase-dev` image is used to produce the prebuilt profiles.
20+
21+
By default all profiles are built, though this can be controlled by setting the `BENCHBASE_PROFILES` environment variable to a specific subset of profiles when building the image with the `build-full-image.sh` script.
22+
For instance:
23+
24+
```sh
25+
BENCHBASE_PROFILES='postgres mysql' ./build-full-image.sh
26+
```
27+
28+
The test suite can also be skipped during the build phase by setting `SKIP_TESTS='true'`.
29+
30+
Additionally, an `benchbase-{profile_name}` image with just that profile in it will be created for each of the `BENCHBASE_PROFILES`.
31+
32+
When running the `benchbase` image, results are placed in `/benchbase/results`, which is expected to be mapped back into the host environment (e.g. `docker run -v /place/to/save/results:/benchbase/results benchbase`)
33+
34+
See [`build-full-image.sh`](./build-full-image.sh) and [`run-full-image.sh`](./run-full-image.sh) for further details.
35+
36+
### Publishing Containers
37+
38+
These scripts are used to publish the images to a container registry for easy consumption with `docker pull` as well.
39+
40+
If you would like to publish them to an alternative repository, you can setup the appropriate tags during the build by setting the `CONTAINER_REGISTRY_NAME` environment variable.
41+
For instance:
42+
43+
```sh
44+
export CONTAINER_REGISTRY_NAME='benchbasedev.azurecr.io'
45+
./build-dev-image.sh
46+
./build-full-image.sh
47+
48+
docker push $CONTAINER_REGISTRY_NAME/benchbase-dev
49+
docker push $CONTAINER_REGISTRY_NAME/benchbase
50+
```
51+
52+
## Running Containers
53+
54+
### With Local Builds
55+
56+
```sh
57+
# This will build and run a container shell with maven and java preloaded and the current source checkout mapped into it:
58+
./docker/benchbase/run-dev-image.sh
59+
```
60+
61+
62+
```sh
63+
# This will build and run a container for running the postgres benchbase profile:
64+
BENCHBASE_PROFILE='postgres' ./docker/benchbase/run-full-image.sh
65+
```
66+
67+
### Prebuilt Containers
68+
69+
To use prebuilt containers, the following can be used:
70+
71+
```sh
72+
docker pull benchbase.azurecr.io/benchbase-dev
73+
74+
# Provide a build environment for working with the local source code:
75+
docker run -it --rm -v /path/to/src:/benchbase benchbase.azurecr.io/benchbase-dev
76+
```
77+
78+
> Optional: also reuse the local `MAVEN_CONFIG` and it's repository download cache with the following argument:
79+
>
80+
> `-v "${MAVEN_CONFIG:-$HOME/.m2}:/home/containeruser/.m2"`
81+
82+
```sh
83+
docker pull benchbase.azurecr.io/benchbase
84+
85+
# Run benchbase against a postgres instance and store the results in /results:
86+
docker run --rm --env BENCHBASE_PROFILE='postgres' -v /results:/benchbase/results benchbase.azurecr.io/benchbase --help
87+
88+
# Or by referencing the standalone image for that profile:
89+
docker run --rm -v /results:/benchbase/results benchbase.azurecr.io/benchbase-postgres --help
90+
```

docker/benchbase/build-dev-image.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)