Skip to content

Add GoLang support for benchmarks #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
97 changes: 97 additions & 0 deletions config/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@
],
"packages": []
}
},
"go": {
"base_images": {
"x64": {
"1.22": "golang:1.22",
"1.23": "golang:1.23",
"1.24": "golang:1.24"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"architecture": ["x64"],
Expand Down Expand Up @@ -121,6 +141,23 @@
"uuid": "3.4.0"
}
}
},
"golang": {
"base_images": {
"x64": {
"1" : "amazon/aws-lambda-go:1.2024.10.04.19"
}
},
"images": [
"build"
],
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"architecture": ["x64", "arm64"],
Expand Down Expand Up @@ -181,6 +218,26 @@
"uuid": "3.4.0"
}
}
},
"golang": {
"base_images": {
"x64": {
"1.22": "mcr.microsoft.com/devcontainers/go:1.4-1.22",
"1.23": "mcr.microsoft.com/devcontainers/go:1.4-1.23",
"1.24": "mcr.microsoft.com/devcontainers/go:1.4-1.24"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"images": {
Expand Down Expand Up @@ -250,6 +307,26 @@
"uuid": "3.4.0"
}
}
},
"golang": {
"base_images": {
"x64": {
"1.22": "ubuntu:22.04",
"1.23": "ubuntu:22.04",
"1.24": "ubuntu:22.04"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"images": {
Expand Down Expand Up @@ -316,6 +393,26 @@
"minio": "7.0.16"
}
}
},
"golang": {
"base_images": {
"x64": {
"1.21": "openwhisk/action-golang-v1.21",
"1.22": "openwhisk/action-golang-v1.22",
"1.23": "openwhisk/action-golang-v1.23"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"architecture": ["x64"],
Expand Down
23 changes: 23 additions & 0 deletions dockerfiles/aws/golang/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

#######################################
# useradd, groupmod
RUN yum install -y shadow-utils
ENV GOSU_VERSION 1.14
# https://github.com/tianon/gosu/releases/tag/1.14
# key https://keys.openpgp.org/search?q=tianon%40debian.org
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" \
&& chmod +x /usr/local/bin/gosu


RUN mkdir -p /sebs/
COPY dockerfiles/golang_installer.sh /sebs/installer.sh
COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/entrypoint.sh

# useradd and groupmod is installed in /usr/sbin which is not in PATH
ENV PATH=/usr/sbin:$PATH
ENV SCRIPT_FILE=/mnt/function/package.sh
CMD /bin/bash /sebs/installer.sh
ENTRYPOINT ["/sebs/entrypoint.sh"]
17 changes: 17 additions & 0 deletions dockerfiles/azure/golang/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

RUN apt-get update\
&& apt-get install -y --no-install-recommends zip gosu golang-1.23\
&& apt-get purge -y --auto-remove

RUN mkdir -p /sebs/
COPY dockerfiles/golang_installer.sh /sebs/installer.sh
COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/entrypoint.sh

# useradd and groupmod is installed in /usr/sbin which is not in PATH
ENV PATH=/usr/sbin:$PATH
ENV SCRIPT_FILE=/mnt/function/package.sh
CMD /bin/bash /sebs/installer.sh
ENTRYPOINT ["/sebs/entrypoint.sh"]
17 changes: 17 additions & 0 deletions dockerfiles/gcp/golang/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

RUN apt-get update\
&& apt-get install -y --no-install-recommends zip gosu golang-1.23\
&& apt-get purge -y --auto-remove

RUN mkdir -p /sebs/
COPY dockerfiles/golang_installer.sh /sebs/installer.sh
COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/entrypoint.sh

# useradd and groupmod is installed in /usr/sbin which is not in PATH
ENV PATH=/usr/sbin:$PATH
ENV SCRIPT_FILE=/mnt/function/package.sh
CMD /bin/bash /sebs/installer.sh
ENTRYPOINT ["/sebs/entrypoint.sh"]
5 changes: 5 additions & 0 deletions dockerfiles/golang_installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd /mnt/function

go mod tidy
19 changes: 19 additions & 0 deletions dockerfiles/local/golang/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}


RUN apt-get update\
&& apt-get install -y --no-install-recommends zip gosu golang-1.23\
&& apt-get purge -y --auto-remove

RUN mkdir -p /sebs/
COPY dockerfiles/golang_installer.sh /sebs/installer.sh
COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/entrypoint.sh


# useradd and groupmod is installed in /usr/sbin which is not in PATH
ENV PATH=/usr/sbin:$PATH
ENV SCRIPT_FILE=/mnt/function/package.sh
CMD /bin/bash /sebs/installer.sh
ENTRYPOINT ["/sebs/entrypoint.sh"]
Empty file.
11 changes: 9 additions & 2 deletions sebs/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ def hash_directory(directory: str, deployment: str, language: str):
FILES = {
"python": ["*.py", "requirements.txt*"],
"nodejs": ["*.js", "package.json"],
"golang": ["*.go"],
}
WRAPPERS = {"python": "*.py", "nodejs": "*.js"}
WRAPPERS = {"python": "*.py", "nodejs": "*.js", "golang": "*.go"}
NON_LANG_FILES = ["*.sh", "*.json"]
selected_files = FILES[language] + NON_LANG_FILES
for file_type in selected_files:
Expand Down Expand Up @@ -316,6 +317,7 @@ def copy_code(self, output_dir):
FILES = {
"python": ["*.py", "requirements.txt*"],
"nodejs": ["*.js", "package.json"],
"golang": ["*.go", "*.mod"],
}
path = os.path.join(self.benchmark_path, self.language_name)
for file_type in FILES[self.language_name]:
Expand Down Expand Up @@ -399,13 +401,18 @@ def add_deployment_package_nodejs(self, output_dir):
with open(package_config, "w") as package_file:
json.dump(package_json, package_file, indent=2)

def add_deployment_package_golang(self, output_dir):
pass

def add_deployment_package(self, output_dir):
from sebs.faas.function import Language

if self.language == Language.PYTHON:
self.add_deployment_package_python(output_dir)
elif self.language == Language.NODEJS:
self.add_deployment_package_nodejs(output_dir)
elif self.language == Language.GOLANG:
self.add_deployment_package_golang(output_dir)
else:
raise NotImplementedError

Expand Down Expand Up @@ -463,7 +470,7 @@ def install_dependencies(self, output_dir):
}

# run Docker container to install packages
PACKAGE_FILES = {"python": "requirements.txt", "nodejs": "package.json"}
PACKAGE_FILES = {"python": "requirements.txt", "nodejs": "package.json", "golang": "go.mod"}
file = os.path.join(output_dir, PACKAGE_FILES[self.language_name])
if os.path.exists(file):
try:
Expand Down
3 changes: 0 additions & 3 deletions sebs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ def supported_language_versions(
) -> List[str]:
languages = self._system_config.get(deployment_name, {}).get("languages", {})
base_images = languages.get(language_name, {}).get("base_images", {})

if deployment_name == "local":
return list(base_images.keys())
return list(base_images.get(architecture, {}).keys())

def supported_architecture(self, deployment_name: str) -> List[str]:
Expand Down
1 change: 1 addition & 0 deletions sebs/faas/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def deserialize(cached_config: dict) -> "Trigger":
class Language(Enum):
PYTHON = "python"
NODEJS = "nodejs"
GOLANG = "golang"

# FIXME: 3.7+ python with future annotations
@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tools/build_docker_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"--deployment", default=None, choices=["local", "aws", "azure", "gcp"], action="store"
)
parser.add_argument("--type", default=None, choices=["build", "run", "manage"], action="store")
parser.add_argument("--language", default=None, choices=["python", "nodejs"], action="store")
parser.add_argument("--language", default=None, choices=["python", "nodejs", "golang"], action="store")
parser.add_argument("--language-version", default=None, type=str, action="store")
args = parser.parse_args()
config = json.load(open(os.path.join(PROJECT_DIR, "config", "systems.json"), "r"))
Expand Down