Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ------------------------------------------------------------------
# INACTIVE BY DEFAULT -- manual trigger only (workflow_dispatch).
#
# This workflow builds and publishes a multi-architecture Docker image
# (linux/amd64 + linux/arm64) to Docker Hub.
#
# TO ACTIVATE:
# 1. Add two repository secrets (Settings > Secrets and variables > Actions):
# DOCKERHUB_USERNAME - your Docker Hub username
# DOCKERHUB_TOKEN - a Docker Hub access token (not your password)
# 2. Optionally add automatic triggers by uncommenting the lines below:
# push:
# branches: [master]
# paths: ['VMs/Dockerfile']
# release:
# types: [published]
#
# Until you do both steps, this workflow does nothing on its own.
# ------------------------------------------------------------------

name: Docker Publish

on:
workflow_dispatch:
# Uncomment the triggers below when ready to automate:
# push:
# branches: [master]
# paths: ['VMs/Dockerfile']
# release:
# types: [published]

env:
IMAGE_NAME: owasp/benchmark
PLATFORMS: linux/amd64,linux/arm64

jobs:
build-and-push:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU (multi-arch emulation)
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with:
context: VMs
file: VMs/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ env.IMAGE_NAME }}:latest
53 changes: 27 additions & 26 deletions VMs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
# This dockerfile builds a container that pulls down and runs the latest version of BenchmarkJava
FROM ubuntu:latest
FROM ubuntu:22.04
LABEL org.opencontainers.image.authors="Dave Wichers dave.wichers@owasp.org"

RUN apt-get update
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata
RUN apt-get install -q -y \
openjdk-17-jre-headless \
openjdk-17-jdk \
git \
maven \
wget \
iputils-ping \
&& apt-get clean
RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata \
&& apt-get install -q -y \
openjdk-17-jre-headless \
openjdk-17-jdk \
git \
maven \
wget \
iputils-ping \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /owasp
WORKDIR /owasp

# Download, build, install Benchmark Utilities required by crawler and scorecard generation
RUN git clone https://github.com/OWASP-Benchmark/BenchmarkUtils.git
WORKDIR /owasp/BenchmarkUtils
RUN mvn install
RUN git clone https://github.com/OWASP-Benchmark/BenchmarkUtils.git \
&& cd BenchmarkUtils \
&& mvn install

# Download, build BenchmarkJava
WORKDIR /owasp
RUN git clone https://github.com/OWASP-Benchmark/BenchmarkJava

# Workaround for security fix for CVE-2022-24765
RUN git config --global --add safe.directory /owasp/BenchmarkJava
RUN git clone https://github.com/OWASP-Benchmark/BenchmarkJava \
&& git config --global --add safe.directory /owasp/BenchmarkJava \
&& cd BenchmarkJava \
&& mvn clean package cargo:install

WORKDIR /owasp/BenchmarkJava
RUN mvn clean package cargo:install

RUN useradd -d /home/bench -m -s /bin/bash bench
RUN echo bench:bench | chpasswd
RUN useradd -d /home/bench -m -s /bin/bash bench \
&& echo bench:bench | chpasswd

RUN chown -R bench /owasp/
ENV PATH=/owasp/BenchmarkJava:$PATH

# start up Benchmark once, for 60 seconds, then kill it, so the additional dependencies required to run it are downloaded/cached in the image as well.
# exit 0 is required to return a 'success' code, otherwise the timeout returns a failure code, causing the Docker build to fail.
# Start up Benchmark once for 60 seconds then kill it, so additional runtime
# dependencies are downloaded and cached in the image.
# exit 0 prevents the timeout return code from failing the Docker build.
WORKDIR /owasp/BenchmarkJava
RUN timeout 60 ./runBenchmark.sh; exit 0

EXPOSE 8443
CMD ["./runBenchmark.sh"]

36 changes: 24 additions & 12 deletions VMs/buildDockerImage.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# Pull in latest version of ubuntu. This builds an image using the OS native to this platform.
docker pull ubuntu:latest
# Remove any ubuntu:<none> image if it was left behind by a new version of ubuntu:latest being pulled
i=$(docker images | grep "ubuntu" | grep "<none" | awk '{print $3}')
if [ "$i" ]
then
docker rmi $i
#!/usr/bin/env bash
set -euo pipefail

IMAGE="owasp/benchmark"
TAG="latest"
PLATFORMS="linux/amd64,linux/arm64"
BUILDER_NAME="benchmark-multiarch"

# Create (or re-use) a buildx builder that supports multi-platform builds.
if ! docker buildx inspect "$BUILDER_NAME" >/dev/null 2>&1; then
echo "Creating buildx builder: $BUILDER_NAME"
docker buildx create --name "$BUILDER_NAME" --use
else
docker buildx use "$BUILDER_NAME"
fi

# Since Docker doesn't auto delete anything, just like for the Ubuntu update, delete any existing benchmark:latest image before building a new one
docker image rm benchmark:latest
docker build -t benchmark .
# Build and push a multi-architecture image in one step.
# --push is required because multi-arch manifest lists cannot be loaded into
# the local daemon. The image is pushed directly to Docker Hub.
echo "Building ${IMAGE}:${TAG} for ${PLATFORMS} ..."
docker buildx build \
--platform "$PLATFORMS" \
--tag "${IMAGE}:${TAG}" \
--push \
.

# Once verified/tested, to publish an update to the OWASP Benchmark Docker image, run the following:
# docker push owasp/benchmark:latest
echo "Done. Published ${IMAGE}:${TAG} for ${PLATFORMS}."

Loading