Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

multiplatform docker builds (#131)

Kilian Lieretf54135157209
diff --git a/docker/getconda.sh b/docker/getconda.sh
new file mode 100755
index 00000000..46785697
--- /dev/null
+++ b/docker/getconda.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+# Helper script to get the right conda version inside of the container
+# This logic is put inside of the container rather than in the build script
+# so that we can easily do multi-platform builds
+
+arch=$1
+echo "arch", $arch
+if [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then
+ echo "Building the x86 Docker image"
+ wget https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-x86_64.sh -O miniconda.sh
+elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then
+ echo "Ayy, arm64 in the house!"
+ wget https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-aarch64.sh -O miniconda.sh
+else
+ echo "unknown architecture detected?"
+ echo $arch
+ exit 1
+fi
diff --git a/docker/swe.Dockerfile b/docker/swe.Dockerfile
index ecf5be09..3ea7ad14 100644
--- a/docker/swe.Dockerfile
+++ b/docker/swe.Dockerfile
@@ -1,6 +1,6 @@
FROM ubuntu:jammy
-ARG MINICONDA_URL
+ARG TARGETARCH
# Install third party tools
RUN apt-get update && \
@@ -27,7 +27,9 @@ RUN echo "alias ls='ls -F'" >> /root/.bashrc
# Install miniconda
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
-RUN wget ${MINICONDA_URL} -O miniconda.sh \
+COPY docker/getconda.sh .
+RUN bash getconda.sh ${TARGETARCH} \
+ && rm getconda.sh \
&& mkdir /root/.conda \
&& bash miniconda.sh -b \
&& rm -f miniconda.sh
diff --git a/release_dockerhub.sh b/release_dockerhub.sh
index 1fdf9e24..72c8c0c6 100755
--- a/release_dockerhub.sh
+++ b/release_dockerhub.sh
@@ -3,94 +3,82 @@
# This script builds the official docker images and pushes them to dockerhub
# after checking with the user.
+# NOTE: To clear the buildx cache, run the following command:
+# docker buildx prune --all or more specifically docker buildx rm <context_name>
+
# bash strict mode
set -euo pipefail
# Check if exactly one argument is supplied
-if [ "$#" -ne 1 ]; then
- echo "Usage: $0 <version>" >&2
+if [ "$#" -ne 2 ]; then
+ echo "Usage: $0 <user> <version>" >&2
exit 1
fi
-VERSION_STR=${1}
+USER=${1}
+VERSION_STR=${2}
+
+if [[ -z "$USER" ]]; then
+ echo "User name cannot be empty" >&2
+ exit 3
+fi
+if [[ "$USER" != "sweagent" ]]; then
+ echo "Careful here! Even if the username isn't sweagent, swe-eval will still be built on top of the sweagent/swe-agent image." >&2
+ read -p "Do you want to proceed? (yes) " response
+ if [[ "${response}" != "yes" ]]; then
+ echo "Exiting..." >&2
+ exit 4
+ fi
+fi
# The argument should be in the form of x.x.x where each x can be one or more digits
-if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+if [[ $VERSION_STR =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || [ "$VERSION_STR" = "latest" ]; then
echo "Validated version number"
else
- echo "Argument must be in the form x.x.x, where x is one or more numbers." >&2
+ echo "Argument must be 'latest' or in the form x.x.x, where x is one or more numbers." >&2
exit 2
fi
+DOCKER_CONTEXT_NAME="sweagent-multiplatform"
+docker buildx use "$DOCKER_CONTEXT_NAME" || docker buildx create --use --name "$DOCKER_CONTEXT_NAME"
+
+on_error() {
+ echo "====> ERROR!!! IMPORTANT: Make sure if you've already pushed something to dockerhub or pushed the tag to github!" >&2
+}
+trap on_error ERR
+
echo "------------------------------------------"
echo "Building swe-agent"
echo "------------------------------------------"
-docker build -t sweagent/swe-agent:${VERSION_STR} --build-arg MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-aarch64.sh -f docker/swe.Dockerfile .
-docker build -t sweagent/swe-agent:latest --build-arg MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-aarch64.sh -f docker/swe.Dockerfile .
+docker buildx build --platform=linux/amd64,linux/arm64 -t ${USER}/swe-agent:${VERSION_STR} -f docker/swe.Dockerfile --push .
+echo "πŸ”₯ swe-agent pushed to dockerhub"
echo "------------------------------------------"
echo "Building swe-eval"
echo "------------------------------------------"
-docker build -t sweagent/swe-eval:${VERSION_STR} -f docker/eval.Dockerfile .
-docker build -t sweagent/swe-eval:latest -f docker/eval.Dockerfile .
+docker buildx build --platform=linux/amd64,linux/arm64 -t ${USER}/swe-eval:${VERSION_STR} -f docker/eval.Dockerfile --push .
+echo "πŸ”₯ swe-eval pushed to dockerhub"
echo "------------------------------------------"
echo "Building swe-agent-run"
echo "------------------------------------------"
-docker build -t sweagent/swe-agent-run:${VERSION_STR} .
-docker build -t sweagent/swe-agent-run:latest .
+docker buildx build --platform=linux/amd64,linux/arm64 -t ${USER}/swe-agent-run:${VERSION_STR} --push .
+echo "πŸ”₯ swe-agent-run pushed to dockerhub"
echo "------------------------------------------"
echo "Building of all images done"
echo "------------------------------------------"
-read -p "Do you want to push to dockerhub and add the tag to github? (yes to proceed) " answer
-if [ "$answer" != "yes" ]; then
- echo "Abort; Bye" >&2
- exit 3
-fi
-# Check if the tags already exist on Docker Hub
-IMAGES=("sweagent/swe-agent:${VERSION_STR}" "sweagent/swe-agent:latest" "sweagent/swe-eval:${VERSION_STR}" "sweagent/swe-eval:latest" "sweagent/swe-agent-run:${VERSION_STR}" "sweagent/swe-agent-run:latest")
-for image in "${IMAGES[@]}"; do
- if [[ $image == *"latest"* ]]; then
- continue
- fi
- IMAGE_NAME="${image%:*}"
- TAG="${image##*:}"
- URL="https://hub.docker.com/v2/repositories/${IMAGE_NAME}/tags/${TAG}/"
- HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${URL}")
- if [ "$HTTP_STATUS" -eq 200 ]; then
- echo "The tag '${TAG}' exists for '${IMAGE_NAME}' on Docker Hub." >&2
- echo "Abort" >&2
- exit 4
- fi
-done
-
-docker login || {
- echo "Failed to login to dockerhub" >&2
- exit 8
-}
-
-# Let's get serious
-# Function to execute upon exit
-on_error() {
- echo "====> ERROR!!! IMPORTANT: Make sure if you've already pushed something to dockerhub or pushed the tag to github!" >&2
-}
-trap on_error ERR
-
-git tag v${VERSION_STR} || {
- echo "Failed to create a tag in git" >&2
- exit 5
-}
-echo "πŸ”₯ Tag v${VERSION_STR} created in git!"
-
-git push origin v${VERSION_STR} || {
- echo "Failed to push the tag to github" >&2
- exit 6
-}
-echo "πŸ”₯ Tag v${VERSION_STR} pushed to github"
+if [ "$VERSION_STR" != "latest" ]; then
+ git tag v${VERSION_STR} || {
+ echo "Failed to create a tag in git" >&2
+ exit 5
+ }
+ echo "πŸ”₯ Tag v${VERSION_STR} created in git (local)!"
-for image in "${IMAGES[@]}"; do
- docker push ${image}
- echo "πŸ”₯ Pushed ${image} to dockerhub"
-done
+ git push origin v${VERSION_STR} || {
+ echo "Failed to push the tag to github" >&2
+ exit 6
+ }
+ echo "πŸ”₯ Tag v${VERSION_STR} pushed to github"
+fi
\ No newline at end of file
diff --git a/setup.sh b/setup.sh
index b392a2bd..faa0c313 100755
--- a/setup.sh
+++ b/setup.sh
@@ -3,22 +3,9 @@
# bash strict mode
set -euo pipefail
-# Create docker image
echo "Setting up docker image for swe-agent..."
-arch=$(uname -m)
-if [[ "$arch" == "x86_64" ]]; then
- echo "Building the x86 Docker image"
- docker build -t sweagent/swe-agent:latest --build-arg MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-x86_64.sh -f docker/swe.Dockerfile .
-elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then
- echo "Ayy, arm64 in the house!"
- docker build -t sweagent/swe-agent:latest --build-arg MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-1-Linux-aarch64.sh -f docker/swe.Dockerfile .
-else
- echo "unknown architecture detected?"
- echo $arch
- exit 1
-fi
+docker build -t sweagent/swe-agent:latest -f docker/swe.Dockerfile .
-# build eval.Dockerfile
echo "Setting up docker image for evaluation..."
docker build -t sweagent/swe-eval:latest -f docker/eval.Dockerfile .