Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 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
131 changes: 131 additions & 0 deletions benchmarks/wrappers/local/golang/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package golang

import (
"bytes"
"context"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/google/uuid"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)

type Storage struct {
client *minio.Client
}

var instance *Storage

func UniqueName(name string) string {
ext := filepath.Ext(name)
basename := name[:len(name)-len(ext)]
uuidStr := strings.Split(uuid.New().String(), "-")[0]
return fmt.Sprintf("%s.%s%s", basename, uuidStr, ext)
}

func NewStorage() (*Storage, error) {
address, exists := os.LookupEnv("MINIO_ADDRESS")
if !exists {
return nil, nil
}

accessKey := os.Getenv("MINIO_ACCESS_KEY")
secretKey := os.Getenv("MINIO_SECRET_KEY")

parts := strings.Split(address, ":")
endpoint := parts[0]
var port int = 9000 // Default port

if len(parts) > 1 {
var err error
port, err = strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("invalid port in MINIO_ADDRESS: %v", err)
}
}

client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKey, secretKey, ""),
Secure: false,
Port: uint16(port),
})
if err != nil {
return nil, err
}

return &Storage{client: client}, nil
}

func (s *Storage) Upload(bucket, file, filepath string) (string, error) {
keyName := UniqueName(file)
_, err := s.client.FPutObject(context.Background(), bucket, keyName, filepath, minio.PutObjectOptions{})
if err != nil {
return "", err
}
return keyName, nil
}

func (s *Storage) Download(bucket, file, filepath string) error {
return s.client.FGetObject(context.Background(), bucket, file, filepath, minio.GetObjectOptions{})
}

func (s *Storage) DownloadDirectory(bucket, prefix, path string) error {
ctx := context.Background()
objects := s.client.ListObjects(ctx, bucket, minio.ListObjectsOptions{
Prefix: prefix,
Recursive: true,
})

for object := range objects {
if object.Err != nil {
return object.Err
}

objectPath := filepath.Join(path, object.Key)
if err := os.MkdirAll(filepath.Dir(objectPath), 0755); err != nil {
return err
}

if err := s.Download(bucket, object.Key, objectPath); err != nil {
return err
}
}

return nil
}

func (s *Storage) UploadStream(bucket, file string, data []byte) (string, error) {
keyName := UniqueName(file)
reader := bytes.NewReader(data)
_, err := s.client.PutObject(context.Background(), bucket, keyName, reader, int64(len(data)), minio.PutObjectOptions{})
if err != nil {
return "", err
}
return keyName, nil
}

func (s *Storage) DownloadStream(bucket, file string) ([]byte, error) {
obj, err := s.client.GetObject(context.Background(), bucket, file, minio.GetObjectOptions{})
if err != nil {
return nil, err
}
defer obj.Close()

return io.ReadAll(obj)
}

func GetInstance() (*Storage, error) {
if instance == nil {
var err error
instance, err = NewStorage()
if err != nil {
return nil, err
}
}
return instance, nil
}
96 changes: 96 additions & 0 deletions config/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@
],
"packages": []
}
},
"golang": {
"base_images": {
"x64": {
"1.22.0": "golang:1.22",
"1.23.0": "golang:1.23",
"1.24.0": "golang:1.24"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"storage.go"
],
"packages": []
}
}
},
"architecture": ["x64"],
Expand Down Expand Up @@ -121,6 +140,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 +217,26 @@
"uuid": "3.4.0"
}
}
},
"golang": {
"base_images": {
"x64": {
"1.22.0": "mcr.microsoft.com/devcontainers/go:1.4-1.22",
"1.23.0": "mcr.microsoft.com/devcontainers/go:1.4-1.23",
"1.24.0": "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 +306,26 @@
"uuid": "3.4.0"
}
}
},
"golang": {
"base_images": {
"x64": {
"1.22.0": "ubuntu:22.04",
"1.23.0": "ubuntu:22.04",
"1.24.0": "ubuntu:22.04"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"images": {
Expand Down Expand Up @@ -316,6 +392,26 @@
"minio": "7.0.16"
}
}
},
"golang": {
"base_images": {
"x64": {
"1.21.0": "openwhisk/action-golang-v1.21",
"1.22.0": "openwhisk/action-golang-v1.22",
"1.23.0": "openwhisk/action-golang-v1.23"
}
},
"images": [
"build"
],
"username": "docker_user",
"deployment": {
"files": [
"handler.go",
"storage.go"
],
"packages": []
}
}
},
"architecture": ["x64"],
Expand Down
46 changes: 46 additions & 0 deletions dockerfiles/aws/golang/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

# Define Go version from VERSION build argument
ARG VERSION
ENV GO_VERSION=${VERSION}
ARG TARGETARCH=amd64

#######################################
# Install required utilities
RUN yum install -y shadow-utils wget ca-certificates tar zip

# Install gosu for running commands as another user
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

# Download and install Go
RUN wget -q "https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz" -O go.tar.gz && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the base image is amazon/aws-lambda-go:1.2024.10.04.19, then do we need to install Go separately?

echo "Downloading Go ${GO_VERSION} for ${TARGETARCH}" && \
# Remove any previous Go installation
rm -rf /usr/local/go && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz

# Add Go to PATH permanently
ENV PATH="/usr/local/go/bin:${PATH}"

# Verify installation
RUN go version

# Set up SeBS environment
RUN mkdir -p /sebs/
COPY dockerfiles/golang_installer.sh /sebs/installer.sh
COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/installer.sh /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

# Set the entry point and command
ENTRYPOINT ["/sebs/entrypoint.sh"]
CMD ["/bin/bash", "/sebs/installer.sh"]
46 changes: 46 additions & 0 deletions dockerfiles/azure/golang/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

# Define Go version from VERSION build argument
ARG VERSION
ENV GO_VERSION=${VERSION}
ARG TARGETARCH=amd64

# Install dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
wget \
ca-certificates \
tar \
zip \
gosu \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Download and install Go
RUN wget -q "https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz" -O go.tar.gz && \
echo "Downloading Go ${GO_VERSION} for ${TARGETARCH}" && \
# Remove any previous Go installation
rm -rf /usr/local/go && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz

# Add Go to PATH permanently
ENV PATH="/usr/local/go/bin:${PATH}"

# Verify installation
RUN go version

# Set up SeBS environment
RUN mkdir -p /sebs/
COPY dockerfiles/golang_installer.sh /sebs/installer.sh
COPY dockerfiles/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/installer.sh /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

# Set the entry point and command
ENTRYPOINT ["/sebs/entrypoint.sh"]
CMD ["/bin/bash", "/sebs/installer.sh"]
Loading