From 5730c330f413176cd1e75f0b422059c8bdc708a8 Mon Sep 17 00:00:00 2001 From: Michael Hohn Date: Wed, 12 Jun 2024 11:28:37 -0700 Subject: [PATCH] Add codeql to server container for standalone testing For full test, we cannot have ERROR codeql database analyze failed: error="exec: \"codeql\": executable file not found in $PATH" job="{MirvaRequestID:0 QueryPackId:54674 QueryLanguage:cpp ORepo:{Owner:psycopg Repo:psycopg2}}" For linux/arm64, use a Dockerfile that: - uses ubuntu 22.04 base image - adds the 1.17 version of the codeql bundle - extracts the bundle - adds a recent version of the JRE - extracts it - sets the CODEQL_JAVA_HOME environment variable to point to the JRE The instructions are updated --- README.md | 3 +++ cmd/server/Dockerfile | 40 ++++++++++++++++++++++++++++++++-------- docker-compose.yml | 4 ++-- pkg/storage/storage.go | 3 +++ 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 502a8f6..3e8f732 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ These are simple steps using a single container. 2. build docker image + cd cmd/server docker build -t server-image . 3. Start container with shared directory @@ -32,6 +33,8 @@ These are simple steps using a single container. ## Using docker-compose ### Steps to build and run the server in a multi-container environment set up by docker-compose. +1. Built the server-image, above + 1. Build server on host cd ~/work-gh/mrva/mrvacommander/cmd/server/ diff --git a/cmd/server/Dockerfile b/cmd/server/Dockerfile index 8780222..d12ebc8 100644 --- a/cmd/server/Dockerfile +++ b/cmd/server/Dockerfile @@ -1,14 +1,38 @@ -# Use Ubuntu 22.04 as the base image -FROM arm64v8/ubuntu:22.04 +# Use the ubuntu 22.04 base image +FROM ubuntu:22.04 -# Set environment variables to non-interactive to avoid prompts during installation +# Set architecture to arm64 +ARG ARCH=arm64 +ARG AARCH=aarch64 + +# Set environment variables ENV DEBIAN_FRONTEND=noninteractive +ENV CODEQL_VERSION=codeql-bundle-v2.17.5 +ENV CODEQL_DOWNLOAD_URL=https://github.com/github/codeql-action/releases/download/${CODEQL_VERSION}/codeql-bundle-linux64.tar.gz +ENV JDK_VERSION=22.0.1 +ENV JDK_DOWNLOAD_URL=https://download.oracle.com/java/21/latest/jdk-${JDK_VERSION}_linux-${AARCH}_bin.tar.gz +ENV JDK_DOWNLOAD_URL=https://download.java.net/java/GA/jdk${JDK_VERSION}/c7ec1332f7bb44aeba2eb341ae18aca4/8/GPL/openjdk-${JDK_VERSION}_linux-${AARCH}_bin.tar.gz -# Update the package list +ENV CODEQL_JAVA_HOME=/usr/local/jdk-${JDK_VERSION} + +# Install necessary tools RUN apt-get update && \ - apt-get clean + apt-get install -y curl tar && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +# Add and extract the CodeQL bundle +RUN curl -L $CODEQL_DOWNLOAD_URL -o /tmp/${CODEQL_VERSION}.tar.gz && \ + tar -xzf /tmp/${CODEQL_VERSION}.tar.gz -C /opt && \ + rm /tmp/${CODEQL_VERSION}.tar.gz + +# Add and extract the JDK +RUN curl -L $JDK_DOWNLOAD_URL -o /tmp/jdk-${JDK_VERSION}.tar.gz && \ + tar -xzf /tmp/jdk-${JDK_VERSION}.tar.gz -C /usr/local && \ + rm /tmp/jdk-${JDK_VERSION}.tar.gz + +# Set PATH +ENV PATH=/opt/codeql:"$PATH" + +# Prepare host mount point RUN mkdir /mrva - -# Set the default command -CMD ["bash"] diff --git a/docker-compose.yml b/docker-compose.yml index df5297a..e8a5e03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,11 +35,11 @@ services: server: - image: ubuntu:22.04 + image: server-image container_name: server environment: - MRVA_SERVER_ROOT=/mrva/mrvacommander/cmd/server - command: sh -c "apt-get update && apt-get install -y curl && tail -f /dev/null" + command: sh -c "tail -f /dev/null" ports: - "8080:8080" volumes: diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 42f394e..cfb19f9 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -115,6 +115,9 @@ func ArtifactURL(js common.JobSpec, vaid int) (string, error) { slog.Error("Error packaging results:", "error", err) return "", err } + // TODO Need url valid in container network and externally + // For now, we assume the container port 8080 is port 8080 on user's machine + hostname = "localhost" au := fmt.Sprintf("http://%s:8080/download-server/%s", hostname, zfpath) return au, nil }