-
Notifications
You must be signed in to change notification settings - Fork 657
Expand file tree
/
Copy pathDockerfile.windows
More file actions
88 lines (70 loc) · 3.9 KB
/
Copy pathDockerfile.windows
File metadata and controls
88 lines (70 loc) · 3.9 KB
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
ARG BASE_IMAGE_GO=golang:1.26.5-windowsservercore-ltsc2022@sha256:4e7754f6cc0f11bea333132cfcd406422ceaf5bd219336dd74dde71c90ef1fc7
ARG BASE_IMAGE_WINDOWS=mcr.microsoft.com/windows/nanoserver:ltsc2022@sha256:3680dad0bb773da8efcd9d928eaf4e33817875ab71a43792640ab1bcc0b3c074
FROM ${BASE_IMAGE_GO} AS builder
ARG VERSION
ARG RELEASE_BUILD=1
ARG GO_TAGS
####################
# The snippet below was taken from build-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 to 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
# mingw - gcc compiler (mingw-w64) for compiling C dependencies (CGO)
# make - building with a Makefile
# docker - building images
# git - bash for windows
# mingw-w64 (packaged from the WinLibs build) provides a modern gcc that links
# CGO dependencies compiled with -fstack-protector correctly.
RUN choco install mingw --version 14.2.0 -y
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
RUN choco install nodejs.install --version 24.4.0 -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 snippet from build-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} GO_TAGS=\"embedalloyui ${GO_TAGS}\" make alloy && rm -rf internal/web/ui/node_modules""
# 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\toolchain@v0.0.1-go1.22.3.windows-amd64\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"]
# Provide otelcol compatibility entrypoint. Useful when using Alloy's OTel Engine with
# OpenTelemetry Collector helm chart and other ecosystem tools that expect otelcol binary.
COPY ["packaging/docker/otelcol.cmd", "C:/Program Files/GrafanaLabs/Alloy/otelcol.cmd"]
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"]