forked from AliyunContainerService/terway
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile.windows
161 lines (136 loc) · 5.6 KB
/
Dockerfile.windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
ARG WINDBAGRELEASE_BASE_IMAGE_TAG="7.1.4-nanoserver-1809-20210812"
# --
# -- construct builder,
# -- inspired from https://raw.githubusercontent.com/rancher/rancher/master/package/windows/Dockerfile.agent
# --
FROM registry.cn-hongkong.aliyuncs.com/acs/golang-windows:1.17.3-windowsservercore as builder
MAINTAINER weijia.mwj "[email protected]"
ARG GOPROXY
# $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# --
# -- download rancher-wins
# --
ENV WINS_VERSION v0.1.3
RUN $URL = ('https://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/windows/wins/wins-{0}.zip' -f $env:WINS_VERSION); \
\
Write-Host ('Downloading wins from {0} ...' -f $URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -UseBasicParsing -OutFile c:\wins.zip -Uri $URL; \
\
Write-Host 'Expanding ...'; \
Expand-Archive c:\wins.zip c:\; \
\
Write-Host 'Complete.'
# --
# -- download yq
# --
ENV YQ_VERSION v4.6.3
RUN $URL = ('https://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/windows/yq/yq-{0}.zip' -f $env:YQ_VERSION); \
\
Write-Host ('Downloading yq from {0} ...' -f $URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -UseBasicParsing -OutFile c:\yq.zip -Uri $URL; \
\
Write-Host 'Expanding ...'; \
Expand-Archive c:\yq.zip c:\; \
\
Write-Host 'Complete.'
# --
# -- download cni plugins
# --
ENV CNI_PLUGINS_VERSION v0.9.2-aliyun.4
RUN $URL = ('https://github.com/thxCode/containernetworking-plugins/releases/download/{0}/cni-plugins-windows-amd64-{0}.tgz' -f $env:CNI_PLUGINS_VERSION); \
\
Write-Host ('Downloading cni plugins from {0} ...' -f $URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
New-Item -Force -ItemType Directory -Path c:\containernetworking\bin | Out-Null; \
Invoke-WebRequest -UseBasicParsing -OutFile c:\containernetworking\bin\plugins.tgz -Uri $URL; \
\
Write-Host 'Expanding ...'; \
pushd c:\containernetworking\bin; \
tar -xf plugins.tgz; \
popd; \
\
Write-Host 'Complete.'
# --
# -- download calico-felix
# --
ENV CALICO_VERSION v3.21.2.3-8d55145b-aliyun
RUN $URL = ('https://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/windows/calico/calico-windows-{0}.zip' -f $env:CALICO_VERSION); \
\
Write-Host ('Downloading calico-felix from {0} ...' -f $URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -UseBasicParsing -OutFile c:\calico.zip -Uri $URL; \
\
Write-Host 'Expanding ...'; \
Expand-Archive c:\calico.zip c:\; \
\
Write-Host 'Complete.'
# --
# -- build
# --
WORKDIR /gopath/src/github.com/AliyunContainerService/terway/
# specify environment
ENV GOPROXY=$GOPROXY \
CGO_ENABLED=0 \
GOOS=windows \
GO111MODULE=on
# cache vendor
COPY go.mod .
COPY go.sum .
RUN go mod download
# go build
COPY . .
RUN Write-Host 'Getting hash ...'; \
$VSC_DATE = $(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ'); \
$VSC_VERSION = $(git describe --tags --match='v*' --long --abbrev=7 --dirty 2>$null); \
$VSC_HASH = $(git rev-parse --short HEAD 2>$null); \
\
Write-Host 'Building terwayd ...'; \
$TERWAYD_BUILD_LDFLAGS=$('-X "k8s.io/client-go/pkg/version.buildDate={0}" -X "k8s.io/client-go/pkg/version.gitVersion={1}" -X "k8s.io/client-go/pkg/version.gitCommit={2}" -X "github.com/AliyunContainerService/terway/pkg/aliyun.kubernetesAlicloudIdentity=Kubernetes.Alicloud/{2}"' -f $VSC_DATE,$VSC_VERSION,$VSC_HASH); \
go build -tags default_build -trimpath \
-ldflags $TERWAYD_BUILD_LDFLAGS \
-o terwayd.exe ./cmd/terway; \
\
Write-Host 'Building terway cni plugin ...'; \
$TERWAY_BUILD_LDFLAGS=$('-X "github.com/containernetworking/plugins/pkg/utils/buildversion.BuildVersion={0}({1})"' -f $VSC_VERSION,$VSC_DATE); \
go build -tags default_build -trimpath \
-ldflags $TERWAY_BUILD_LDFLAGS \
-o terway.exe ./plugin/terway; \
\
Write-Host 'Building terway cli ...'; \
go build -tags default_build -trimpath \
-o terway-cli.exe ./cmd/terway-cli; \
\
Write-Host 'Complete.'
# --
# -- construct terway
# --
FROM mcr.microsoft.com/powershell:${WINDBAGRELEASE_BASE_IMAGE_TAG}
MAINTAINER weijia.mwj "[email protected]"
USER ContainerAdministrator
ENV CLUSTER_SERVER="" \
LOG_LEVEL="info" \
BACKEND_TYPE="" \
DEBUG_SOCKET="unix:///var/run/eni/eni_debug.socket" \
POOL_CHECK_PERIOD_SECONDS="0"\
NODE_NAME="" \
POD_NAMESPACE="" \
POD_NAME="" \
CONTAINER_NAME="" \
ENABLE_METRICS="false" \
DISABLE_POLICY="false" \
NETWORK_NAME_REGEX="^ethernet_.*"
# copy artifacts from builder
COPY --from=builder /Windows/System32/certoc.exe /Windows/System32/netapi32.dll /Windows/System32/
COPY --from=builder /yq/yq.exe /wins/wins.exe /Windows/System32/
COPY --from=builder /containernetworking/bin/host-local.exe /opt/cni/bin/
COPY --from=builder /CalicoWindows/calico-felix.exe /opt/bin/
COPY --from=builder /gopath/src/github.com/AliyunContainerService/terway/terway-cli.exe /Windows/System32/
COPY --from=builder /gopath/src/github.com/AliyunContainerService/terway/terway.exe /opt/cni/bin/
COPY --from=builder /gopath/src/github.com/AliyunContainerService/terway/terwayd.exe /opt/bin/
# copy scripts from host
COPY policy/*.ps1 /
COPY entrypoint.ps1 /
ENTRYPOINT ["pwsh.exe", "-NoLogo"]