/ components / execd / Dockerfile
Dockerfile
 1  # Copyright 2025 Alibaba Group Holding Ltd.
 2  #
 3  # Licensed under the Apache License, Version 2.0 (the "License");
 4  # you may not use this file except in compliance with the License.
 5  # You may obtain a copy of the License at
 6  #
 7  #     http://www.apache.org/licenses/LICENSE-2.0
 8  #
 9  # Unless required by applicable law or agreed to in writing, software
10  # distributed under the License is distributed on an "AS IS" BASIS,
11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  # See the License for the specific language governing permissions and
13  # limitations under the License.
14  
15  FROM golang:1.24.0 AS builder
16  
17  WORKDIR /build
18  
19  ARG VERSION=dev
20  ARG GIT_COMMIT=unknown
21  ARG BUILD_TIME=unknown
22  
23  # Prepare local modules to satisfy replace directives.
24  COPY components/internal/go.mod components/internal/go.sum ./components/internal/
25  COPY components/execd/go.mod components/execd/go.sum ./components/execd/
26  
27  # Download deps with only mod files for better caching.
28  RUN cd components/internal && go mod download
29  RUN cd components/execd && go mod download
30  
31  # Copy sources.
32  COPY components/internal ./components/internal
33  COPY components/execd ./components/execd
34  
35  WORKDIR /build/components/execd
36  
37  RUN CGO_ENABLED=0 go build \
38      -ldflags "-X 'github.com/alibaba/opensandbox/internal/version.Version=${VERSION}' \
39                -X 'github.com/alibaba/opensandbox/internal/version.BuildTime=${BUILD_TIME}' \
40                -X 'github.com/alibaba/opensandbox/internal/version.GitCommit=${GIT_COMMIT}'" \
41      -o /build/execd ./main.go
42  
43  RUN CGO_ENABLED=0 GOOS=windows go build \
44      -ldflags "-X 'github.com/alibaba/opensandbox/internal/version.Version=${VERSION}' \
45                -X 'github.com/alibaba/opensandbox/internal/version.BuildTime=${BUILD_TIME}' \
46                -X 'github.com/alibaba/opensandbox/internal/version.GitCommit=${GIT_COMMIT}'" \
47      -o /build/execd.exe ./main.go
48  
49  FROM alpine:latest
50  
51  COPY --from=builder /build/execd .
52  COPY --from=builder /build/execd.exe ./execd.exe
53  COPY components/execd/bootstrap.sh ./bootstrap.sh
54  COPY components/execd/install.bat ./install.bat
55  
56  ENTRYPOINT ["./execd"]