-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathDockerfile.windows
96 lines (78 loc) · 4.25 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
ARG BASE_IMAGE_GO=library/golang:1.24-windowsservercore-ltsc2022
ARG BASE_IMAGE_WINDOWS=mcr.microsoft.com/windows/nanoserver:ltsc2022
FROM ${BASE_IMAGE_GO} AS builder
ARG VERSION
ARG RELEASE_BUILD=1
ARG GO_TAGS
####################
# The snippet below was taken from tools/build-image/windows/Dockerfile.
# This is so that we don't have to run the CI step inside a build image container.
#
# TODO: Build Alloy outside of the Dockerfile?
# Then we don't need to install all those dependencies.
# However, the versions of Windows may not match.
# GitHub Actions may use one version of Windows ot build Alloy,
# and Docker may put it into a container with a different version.
####################
SHELL ["powershell", "-command"]
# Use a fixed version of chocolatey to avoid dependency on .net framework install
# See https://stackoverflow.com/questions/76470752/chocolatey-installation-in-docker-started-to-fail-restart-due-to-net-framework
ENV chocolateyVersion=1.4.0
# Install chocolatey for package management
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
#
# Go Build Dependencies
#
# golang - building go code
# 7zip - unzipping stuff during TDM GCC install
# TDM GCC - gcc compiler in windows
# make - building with a Makefile
# docker - building images
# git - bash for windows
RUN choco install 7zip --version 22.1 -y
# TDM GCC doesn't currently have a way to silently install
ADD https://github.com/jmeubank/tdm-gcc/releases/download/v10.3.0-tdm64-2/tdm64-gcc-10.3.0-2.exe C:\\Windows\\temp\\TDM-GCC-64.exe
RUN mkdir C:\\TDM-GCC-64; \
Start-Process 7z -ArgumentList 'e C:\\Windows\\temp\\TDM-GCC-64.exe -oC:\\TDM-GCC-64 -y' -Wait; \
Start-Process 7z -ArgumentList 'e C:\\TDM-GCC-64\\*.tar.xz -oC:\\TDM-GCC-64 -y' -Wait; \
Start-Process 7z -ArgumentList 'x C:\\TDM-GCC-64\\*.tar -oC:\\TDM-GCC-64 -y' -Wait; \
Remove-Item "C:\\TDM-GCC-64\\*" -Include *.tar.xz, *.tar -Force; \
setx /M PATH $('C:\TDM-GCC-64\bin;' + $Env:PATH); \
Remove-Item -Path C:\\Windows\\temp\\TDM-GCC-64.exe -Force
RUN choco install make --version 4.3 -y
RUN choco install docker-cli --version 20.10.22 -y
RUN choco install git --version 2.39.0 -y
#
# React App Dependencies
#
# nodejs - node server
# yarn - installs node dependencies
RUN choco install nodejs.install --version 19.2.0 -y
RUN choco install yarn --version 1.22.19 -y
# Git tries to prevent misuse of repositories (CVE-2022-24765), but we don't
# care about this for build containers, where it's expected that the repository
# will be accessed by other users (the root user of the build container).
#
# Disable that safety check.
RUN git config --global --add safe.directory \*
####################
# End of snipped from tools/build-image/windows/Dockerfile.
####################
COPY . /src/alloy
WORKDIR /src/alloy
SHELL ["cmd", "/S", "/C"]
# Creating new layers can be really slow on Windows so we clean up any caches
# we can before moving on to the next step.
RUN ""C:\Program Files\git\bin\bash.exe" -c "RELEASE_BUILD=${RELEASE_BUILD} VERSION=${VERSION} make generate-ui && rm -rf web/ui/node_modules && yarn cache clean --all""
RUN ""C:\Program Files\git\bin\bash.exe" -c "RELEASE_BUILD=${RELEASE_BUILD} VERSION=${VERSION} GO_TAGS=\"builtinassets ${GO_TAGS}\" make alloy""
# In this case, we're separating the clean command from make alloy to avoid an issue where access to some mod cache
# files is denied immediately after make alloy, for example:
# "go: remove C:\go\pkg\mod\golang.org\[email protected]\bin\go.exe: Access is denied."
RUN ""C:\Program Files\git\bin\bash.exe" -c "go clean -cache -modcache""
# Use the smallest container possible for the final image
FROM ${BASE_IMAGE_WINDOWS}
COPY --from=builder ["/src/alloy/build/alloy", "C:/Program Files/GrafanaLabs/Alloy/alloy.exe"]
COPY --from=builder ["/src/alloy/example-config.alloy", "C:/Program Files/GrafanaLabs/Alloy/config.alloy"]
ENTRYPOINT ["C:/Program Files/GrafanaLabs/Alloy/alloy.exe"]
ENV ALLOY_DEPLOY_MODE=docker
CMD ["run", "C:/Program Files/GrafanaLabs/Alloy/config.alloy", "--storage.path=C:/ProgramData/GrafanaLabs/Alloy/data"]