Skip to content
Merged
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
12 changes: 10 additions & 2 deletions components/egress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ FROM golang:1.24-bookworm AS builder

WORKDIR /workspace

ARG VERSION=dev
ARG GIT_COMMIT=unknown
ARG BUILD_TIME=unknown

# Copy only go mod/sum first for better caching
COPY components/egress/go.mod components/egress/go.sum ./components/egress/
# Bring internal module so replace ../internal works during download/build
Expand All @@ -28,8 +32,12 @@ ENV CGO_ENABLED=0
RUN go mod download

# Copy the rest of the egress sources
COPY components/egress ./
RUN go build -o /out/egress .
COPY components/egress ./
RUN CGO_ENABLED=0 go build \
-ldflags "-X 'github.com/alibaba/opensandbox/internal/version.Version=${VERSION}' \
-X 'github.com/alibaba/opensandbox/internal/version.BuildTime=${BUILD_TIME}' \
-X 'github.com/alibaba/opensandbox/internal/version.GitCommit=${GIT_COMMIT}'" \
-o /out/egress .

FROM debian:bookworm-slim

Expand Down
6 changes: 6 additions & 0 deletions components/egress/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
set -ex

TAG=${TAG:-latest}
VERSION=${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo "dev")}
GIT_COMMIT=${GIT_COMMIT:-$(git rev-parse HEAD 2>/dev/null || echo "unknown")}
BUILD_TIME=${BUILD_TIME:-$(date -u +"%Y-%m-%dT%H:%M:%SZ")}
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || realpath "$(dirname "$0")/../..")
cd "${REPO_ROOT}"

Expand All @@ -28,6 +31,9 @@ docker buildx build \
-t opensandbox/egress:${TAG} \
-t sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/egress:${TAG} \
-f components/egress/Dockerfile \
--build-arg VERSION="${VERSION}" \
--build-arg GIT_COMMIT="${GIT_COMMIT}" \
--build-arg BUILD_TIME="${BUILD_TIME}" \
--platform linux/amd64,linux/arm64 \
--push \
.
3 changes: 3 additions & 0 deletions components/egress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import (
"github.com/alibaba/opensandbox/egress/pkg/iptables"
"github.com/alibaba/opensandbox/egress/pkg/log"
slogger "github.com/alibaba/opensandbox/internal/logger"
"github.com/alibaba/opensandbox/internal/version"
)

func main() {
version.EchoVersion("OpenSandbox Egress")

ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

Expand Down
10 changes: 9 additions & 1 deletion components/execd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ FROM golang:1.24.0 AS builder

WORKDIR /build

ARG VERSION=dev
ARG GIT_COMMIT=unknown
ARG BUILD_TIME=unknown

# Prepare local modules to satisfy replace directives.
COPY components/internal/go.mod components/internal/go.sum ./components/internal/
COPY components/execd/go.mod components/execd/go.sum ./components/execd/
Expand All @@ -30,7 +34,11 @@ COPY components/execd ./components/execd

WORKDIR /build/components/execd

RUN CGO_ENABLED=0 go build -o /build/execd ./main.go
RUN CGO_ENABLED=0 go build \
-ldflags "-X 'github.com/alibaba/opensandbox/internal/version.Version=${VERSION}' \
-X 'github.com/alibaba/opensandbox/internal/version.BuildTime=${BUILD_TIME}' \
-X 'github.com/alibaba/opensandbox/internal/version.GitCommit=${GIT_COMMIT}'" \
-o /build/execd ./main.go

FROM alpine:latest

Expand Down
12 changes: 10 additions & 2 deletions components/execd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ install-golint:
golint: fmt install-golint
golangci-lint run -v --fix ./...

VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -X 'github.com/alibaba/opensandbox/internal/version.Version=$(VERSION)' \
-X 'github.com/alibaba/opensandbox/internal/version.BuildTime=$(BUILD_TIME)' \
-X 'github.com/alibaba/opensandbox/internal/version.GitCommit=$(GIT_COMMIT)'

.PHONY: build
build: vet ## Build the binary.
go build -o bin/execd main.go
@mkdir -p bin
go build -ldflags "$(LDFLAGS)" -o bin/execd main.go

.PHONY: multi-build
multi-build: vet ## Cross-compile for linux/windows/darwin amd64/arm64.
Expand All @@ -38,6 +46,6 @@ multi-build: vet ## Cross-compile for linux/windows/darwin amd64/arm64.
out=bin/execd-$${os}-$${arch}; \
[ "$${os}" = "windows" ] && out="$${out}.exe"; \
echo ">> building $${os}/$${arch} -> $${out}"; \
GOOS=$${os} GOARCH=$${arch} CGO_ENABLED=0 go build -o "$${out}" main.go || exit $$?; \
GOOS=$${os} GOARCH=$${arch} CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o "$${out}" main.go || exit $$?; \
done; \
done
2 changes: 1 addition & 1 deletion components/execd/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if ! touch "$EXECD_ENVS" 2>/dev/null; then
fi
export EXECD_ENVS

echo "starting OpenSandbox execd daemon at $EXECD with version v1.0.6. https://github.com/alibaba/OpenSandbox/releases/tag/docker%2Fexecd%2Fv1.0.6"
echo "starting OpenSandbox Execd daemon at $EXECD."
$EXECD &

# Allow chained shell commands (e.g., /test1.sh && /test2.sh)
Expand Down
13 changes: 10 additions & 3 deletions components/execd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
set -ex

TAG=${TAG:-latest}
VERSION=${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo "dev")}
GIT_COMMIT=${GIT_COMMIT:-$(git rev-parse HEAD 2>/dev/null || echo "unknown")}
BUILD_TIME=${BUILD_TIME:-$(date -u +"%Y-%m-%dT%H:%M:%SZ")}

REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || realpath "$(dirname "$0")/../..")
cd "${REPO_ROOT}"

docker buildx rm execd-builder || true

Expand All @@ -30,7 +34,10 @@ docker buildx ls
docker buildx build \
-t opensandbox/execd:${TAG} \
-t sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/execd:${TAG} \
-f components/execd/Dockerfile \
--build-arg VERSION="${VERSION}" \
--build-arg GIT_COMMIT="${GIT_COMMIT}" \
--build-arg BUILD_TIME="${BUILD_TIME}" \
--platform linux/amd64,linux/arm64 \
--push \
-f components/execd/Dockerfile \
"${REPO_ROOT}"
.
3 changes: 3 additions & 0 deletions components/execd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import (
_ "github.com/alibaba/opensandbox/execd/pkg/util/safego"
"github.com/alibaba/opensandbox/execd/pkg/web"
"github.com/alibaba/opensandbox/execd/pkg/web/controller"
"github.com/alibaba/opensandbox/internal/version"
)

// main initializes and starts the execd server.
func main() {
version.EchoVersion("OpenSandbox Execd")

flag.InitFlags()

log.Init(flag.ServerLogLevel)
Expand Down
6 changes: 3 additions & 3 deletions components/ingress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ COPY components/ingress/. ./components/ingress
WORKDIR /build/components/ingress

RUN CGO_ENABLED=0 go build \
-ldflags "-X 'github.com/alibaba/opensandbox/ingress/version.Version=${VERSION}' \
-X 'github.com/alibaba/opensandbox/ingress/version.BuildTime=${BUILD_TIME}' \
-X 'github.com/alibaba/opensandbox/ingress/version.GitCommit=${GIT_COMMIT}'" \
-ldflags "-X 'github.com/alibaba/opensandbox/internal/version.Version=${VERSION}' \
-X 'github.com/alibaba/opensandbox/internal/version.BuildTime=${BUILD_TIME}' \
-X 'github.com/alibaba/opensandbox/internal/version.GitCommit=${GIT_COMMIT}'" \
-o /build/ingress ./main.go

FROM alpine:latest
Expand Down
6 changes: 3 additions & 3 deletions components/ingress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ golint: fmt install-golint
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -X 'github.com/alibaba/opensandbox/router/version.Version=$(VERSION)' \
-X 'github.com/alibaba/opensandbox/router/version.BuildTime=$(BUILD_TIME)' \
-X 'github.com/alibaba/opensandbox/router/version.GitCommit=$(GIT_COMMIT)'
LDFLAGS := -X 'github.com/alibaba/opensandbox/internal/version.Version=$(VERSION)' \
-X 'github.com/alibaba/opensandbox/internal/version.BuildTime=$(BUILD_TIME)' \
-X 'github.com/alibaba/opensandbox/internal/version.GitCommit=$(GIT_COMMIT)'

.PHONY: build
build: vet ## Build the binary.
Expand Down
4 changes: 2 additions & 2 deletions components/ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"github.com/alibaba/opensandbox/ingress/pkg/flag"
"github.com/alibaba/opensandbox/ingress/pkg/proxy"
"github.com/alibaba/opensandbox/ingress/pkg/sandbox"
"github.com/alibaba/opensandbox/ingress/version"
slogger "github.com/alibaba/opensandbox/internal/logger"
"github.com/alibaba/opensandbox/internal/version"
)

func main() {
version.EchoVersion()
version.EchoVersion("OpenSandbox Ingress")

flag.InitFlags()
if flag.Namespace == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Alibaba Group Holding Ltd.
// Copyright 2026 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,22 +19,21 @@ import (
"runtime"
)

// Version package values is auto-generated, the following values will be overridden at build time.
// Package values are typically overridden at build time via -ldflags.
var (
// Version represents the version of taskline suite.
Version = "1.0.0"

// BuildTime is the time when taskline-operator binary is built
// Version is the component version.
Version = "dirty"
// BuildTime is when the binary was built.
BuildTime = "assigned-at-build-time"

// GitCommit is the commit id to build taskline-operator
// GitCommit is the commit id used to build the binary.
GitCommit = "assigned-at-build-time"
)

// EchoVersion is used to echo current binary build info for diagnosing
func EchoVersion() {
// EchoVersion prints build info for the given component name (e.g. "OpenSandbox Ingress", "OpenSandbox Execd").
// All components can use this by passing their display name.
func EchoVersion(componentName string) {
fmt.Println("=====================================================")
fmt.Println(" OpenSandbox Ingress")
fmt.Printf(" %s\n", componentName)
fmt.Println("-----------------------------------------------------")
fmt.Printf(" Version : %s\n", Version)
fmt.Printf(" Git Commit : %s\n", GitCommit)
Expand Down
Loading