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
16 changes: 12 additions & 4 deletions components/execd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ FROM golang:1.24.0 AS builder

WORKDIR /build

COPY go.mod go.sum ./
# Prepare local modules to satisfy replace directives.
COPY components/internal/go.mod components/internal/go.sum ./components/internal/

Choose a reason for hiding this comment

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

P1 Badge Preserve execd Docker build context compatibility

This COPY components/... path assumes the build context is the repository root, but the current callers still build from components/execd (for example scripts/python-e2e.sh, scripts/java-e2e.sh, scripts/javascript-e2e.sh, and components/execd/build.sh all run docker build ... . after cd components/execd). In that context, components/internal/... is outside the build context, so Docker fails during COPY and the execd image can no longer be built in local or CI flows.

Useful? React with 👍 / 👎.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice suggestion, fixed this

COPY components/execd/go.mod components/execd/go.sum ./components/execd/

RUN go mod download
# Download deps with only mod files for better caching.
RUN cd components/internal && go mod download
RUN cd components/execd && go mod download

COPY . .
# Copy sources.
COPY components/internal ./components/internal
COPY components/execd/. ./components/execd
Copy link
Collaborator

Choose a reason for hiding this comment

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

COPY components/execd/. here is a little bit strange, use COPY components/execd directly?


WORKDIR /build/components/execd

RUN CGO_ENABLED=0 go build -o /build/execd ./main.go

FROM alpine:latest

COPY --from=builder /build/execd .
COPY bootstrap.sh .
COPY components/execd/bootstrap.sh ./bootstrap.sh

ENTRYPOINT ["./execd"]
5 changes: 4 additions & 1 deletion components/execd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set -ex

TAG=${TAG:-latest}

REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"

docker buildx rm execd-builder || true

docker buildx create --use --name execd-builder
Expand All @@ -30,4 +32,5 @@ docker buildx build \
-t sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/execd:${TAG} \
--platform linux/amd64,linux/arm64 \
--push \
.
-f components/execd/Dockerfile \
"${REPO_ROOT}"
5 changes: 4 additions & 1 deletion components/execd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/alibaba/opensandbox/execd
go 1.24.0

require (
github.com/alibaba/opensandbox/internal v0.0.0
github.com/bmatcuk/doublestar/v4 v4.9.1
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.28.0
Expand All @@ -12,7 +13,6 @@ require (
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/stretchr/testify v1.10.0
go.uber.org/automaxprocs v1.6.0
go.uber.org/zap v1.27.0
k8s.io/apimachinery v0.34.2
k8s.io/client-go v0.34.2
)
Expand Down Expand Up @@ -49,6 +49,7 @@ require (
github.com/x448/float16 v0.8.4 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
Expand All @@ -65,3 +66,5 @@ require (
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
)

replace github.com/alibaba/opensandbox/internal => ../internal
2 changes: 1 addition & 1 deletion components/execd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func main() {
flag.InitFlags()

log.SetLevel(flag.ServerLogLevel)
log.Init(flag.ServerLogLevel)

controller.InitCodeRunner()
engine := web.NewRouter(flag.ServerAccessToken)
Expand Down
85 changes: 34 additions & 51 deletions components/execd/pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,83 +15,66 @@
package log

import (
"fmt"
"os"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
slogger "github.com/alibaba/opensandbox/internal/logger"
)

const logFileEnvKey = "EXECD_LOG_FILE"

var (
atomicLevel = zap.NewAtomicLevelAt(zap.InfoLevel)
base *zap.Logger
sugar *zap.SugaredLogger
)

func init() {
cfg := zap.NewProductionConfig()
cfg.Level = atomicLevel
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
cfg.EncoderConfig.CallerKey = ""
cfg.DisableCaller = true
cfg.DisableStacktrace = true
cfg.EncoderConfig.StacktraceKey = ""

logFile := os.Getenv(logFileEnvKey)
if logFile != "" {
cfg.OutputPaths = []string{logFile}
cfg.ErrorOutputPaths = []string{logFile}
} else {
// outputs log to stdout pipe by default
cfg.OutputPaths = []string{"stdout"}
cfg.ErrorOutputPaths = []string{"stdout"}
}

logger, err := cfg.Build()
if err != nil {
panic(fmt.Sprintf("failed to init logger: %v", err))
}
base = logger
sugar = base.Sugar()
}
var current slogger.Logger

// SetLevel maps legacy Beego log levels to zap levels.
// 0/1/2 => Fatal, 3 => Error, 4 => Warn, 5/6 => Info, 7+ => Debug.
func SetLevel(level int) {
atomicLevel.SetLevel(mapLevel(level))
// Init constructs the singleton logger. Call once during startup.
// Legacy levels: 0/1/2=fatal, 3=error, 4=warn, 5/6=info, 7+=debug.
func Init(level int) {
current = newLogger(mapLevel(level))
}

func mapLevel(level int) zapcore.Level {
func mapLevel(level int) string {
switch {
case level <= 2:
return zapcore.FatalLevel
return "fatal"
case level == 3:
return zapcore.ErrorLevel
return "error"
case level == 4:
return zapcore.WarnLevel
return "warn"
case level == 5 || level == 6:
return zapcore.InfoLevel
return "info"
default:
return zapcore.DebugLevel
return "debug"
}
}

func Sync() {
_ = base.Sync()
func newLogger(level string) slogger.Logger {
cfg := slogger.Config{
Level: level,
}
if logFile := os.Getenv(logFileEnvKey); logFile != "" {
cfg.OutputPaths = []string{logFile}
cfg.ErrorOutputPaths = cfg.OutputPaths
}
return slogger.MustNew(cfg)
}

func getLogger() slogger.Logger {
if current != nil {
return current
}
l := newLogger("info")
current = l
return l
}

func Debug(format string, args ...any) {
sugar.Debugf(format, args...)
getLogger().Debugf(format, args...)
}

func Info(format string, args ...any) {
sugar.Infof(format, args...)
getLogger().Infof(format, args...)
}

func Warn(format string, args ...any) {
sugar.Warnf(format, args...)
getLogger().Warnf(format, args...)
}

// Warning is an alias to Warn for compatibility.
Expand All @@ -100,5 +83,5 @@ func Warning(format string, args ...any) {
}

func Error(format string, args ...any) {
sugar.Errorf(format, args...)
getLogger().Errorf(format, args...)
}
7 changes: 4 additions & 3 deletions scripts/java-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ set -euxo pipefail

TAG=${TAG:-latest}

# build execd image locally
cd components/execd && docker build -t opensandbox/execd:local .
cd ../..
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"

# build execd image locally (context must include internal/)
docker build -f components/execd/Dockerfile -t opensandbox/execd:local "${REPO_ROOT}"

# prepare required images from registry
docker pull opensandbox/code-interpreter:${TAG}
Expand Down
7 changes: 4 additions & 3 deletions scripts/javascript-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ set -euxo pipefail

TAG=${TAG:-latest}

# build execd image locally
cd components/execd && docker build -t opensandbox/execd:local .
cd ../..
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"

# build execd image locally (context must include internal/)
docker build -f components/execd/Dockerfile -t opensandbox/execd:local "${REPO_ROOT}"

# prepare required images from registry
docker pull opensandbox/code-interpreter:${TAG}
Expand Down
7 changes: 4 additions & 3 deletions scripts/python-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ set -euxo pipefail

TAG=${TAG:-latest}

# build execd image locally
cd components/execd && docker build -t opensandbox/execd:local .
cd ../..
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"

# build execd image locally (context must include internal/)
docker build -f components/execd/Dockerfile -t opensandbox/execd:local "${REPO_ROOT}"

# prepare required images from registry
docker pull opensandbox/code-interpreter:${TAG}
Expand Down
Loading