forked from grafana/pyroscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
189 lines (147 loc) · 6.47 KB
/
Dockerfile
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# _
# | |
# _ __ _ _ ___| |_
# | '__| | | / __| __|
# | | | |_| \__ \ |_
# |_| \__,_|___/\__|
FROM alpine:3.12 as rust-builder
RUN apk update &&\
apk add --no-cache git gcc g++ make build-base openssl-dev musl musl-dev curl zlib-static
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN /root/.cargo/bin/rustup target add $(uname -m)-unknown-linux-musl
RUN wget https://github.com/libunwind/libunwind/releases/download/v1.3.1/libunwind-1.3.1.tar.gz && \
tar -zxf libunwind-1.3.1.tar.gz && \
cd libunwind-1.3.1/ && \
./configure --with-pic --disable-minidebuginfo --enable-ptrace --disable-tests --disable-documentation && make && make install
COPY third_party/rustdeps /opt/rustdeps
WORKDIR /opt/rustdeps
RUN RUSTFLAGS="-L /lib -C target-feature=+crt-static" /root/.cargo/bin/cargo build --release --target $(uname -m)-unknown-linux-musl
RUN mv /opt/rustdeps/target/$(uname -m)-unknown-linux-musl/release/librustdeps.a /opt/rustdeps/librustdeps.a
# _
# | |
# _ __ | |__ _ __ ___ _ __ _ _
# | '_ \| '_ \| '_ \/ __| '_ \| | | |
# | |_) | | | | |_) \__ \ |_) | |_| |
# | .__/|_| |_| .__/|___/ .__/ \__, |
# | | | | | | __/ |
# |_| |_| |_| |___/
FROM php:7.3-fpm-alpine3.13 as phpspy-builder
RUN apk add --update alpine-sdk
COPY Makefile Makefile
RUN mkdir -p third_party/phpspy
RUN make build-phpspy-dependencies
# _
# | |
# __ _ ___ ___ ___| |_ ___
# / _` / __/ __|/ _ \ __/ __|
# | (_| \__ \__ \ __/ |_\__ \
# \__,_|___/___/\___|\__|___/
FROM node:14.17.6-alpine3.12 as js-builder
RUN apk add --no-cache make
WORKDIR /opt/pyroscope
COPY scripts ./scripts
COPY package.json yarn.lock Makefile lerna.json ./
COPY lib ./lib
COPY packages ./packages
COPY babel.config.js .eslintrc.js .eslintignore .prettierrc tsconfig.json ./
COPY webapp ./webapp
# we only need the dependencies required to BUILD the application
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn/v6 make install-build-web-dependencies
ARG EXTRA_METADATA=""
RUN EXTRA_METADATA=$EXTRA_METADATA make assets-release
# _
# | |
# __ _ ___ | | __ _ _ __ __ _
# / _` |/ _ \| |/ _` | '_ \ / _` |
# | (_| | (_) | | (_| | | | | (_| |
# \__, |\___/|_|\__,_|_| |_|\__, |
# __/ | __/ |
# |___/ |___/
# We build our own golang image because we need alpine 3.12 and go 1.17 is not available in alpine 3.12
# The dockerfile we use is a copy of this one:
# https://github.com/docker-library/golang/blob/48e32c58a6abc052253fba899cea876740cab262/1.16/alpine3.14/Dockerfile
# TODO: figure out why linking isn't working on alpine 3.13 or 3.14
# see https://github.com/pyroscope-io/pyroscope/pull/372 for more context
FROM pyroscope/golang:1.17.0-alpine3.12 AS go-builder
RUN apk add --no-cache make git zstd gcc g++ libc-dev musl-dev bash
RUN apk upgrade binutils
RUN apk upgrade elfutils
WORKDIR /opt/pyroscope
RUN mkdir -p /opt/pyroscope/third_party/rustdeps/target/release
COPY --from=rust-builder /opt/rustdeps/librustdeps.a /opt/pyroscope/third_party/rustdeps/target/release/librustdeps.a
COPY third_party/rustdeps/rbspy.h /opt/pyroscope/third_party/rustdeps/rbspy.h
COPY third_party/rustdeps/pyspy.h /opt/pyroscope/third_party/rustdeps/pyspy.h
COPY third_party/phpspy/phpspy.h /opt/pyroscope/third_party/phpspy/phpspy.h
COPY --from=phpspy-builder /var/www/html/third_party/phpspy/libphpspy.a /opt/pyroscope/third_party/phpspy/libphpspy.a
COPY --from=js-builder /opt/pyroscope/webapp/public ./webapp/public
COPY Makefile ./
COPY tools ./tools
COPY go.mod go.sum ./
RUN make install-dev-tools
RUN make install-go-dependencies
COPY pkg ./pkg
COPY cmd ./cmd
COPY webapp/assets_embedded.go ./webapp/assets_embedded.go
COPY webapp/assets.go ./webapp/assets.go
COPY scripts ./scripts
# Alpine's default stack size too small for pyspy, causing exec mode with pyspy to segfault.
# See https://github.com/pyroscope-io/pyroscope/issues/503
RUN EMBEDDED_ASSETS_DEPS="" \
CGO_LDFLAGS_ALLOW="-Wl,-z,stack-size=0x200000" \
EXTRA_LDFLAGS="-linkmode external -extldflags '-static -Wl,-z,stack-size=0x200000'" \
make build-release
# _ _ _ _ _ _
# | | | | (_) | (_) |
# ___| |_ __ _| |_ _ ___ | |_| |__ ___
# / __| __/ _` | __| |/ __| | | | '_ \/ __|
# \__ \ || (_| | |_| | (__ | | | |_) \__ \
# |___/\__\__,_|\__|_|\___| |_|_|_.__/|___/
FROM go-builder AS go-libs-builder
RUN make build-rbspy-static-library
RUN make build-pyspy-static-library
RUN make build-phpspy-static-library
FROM scratch AS lib-exporter
COPY --from=go-libs-builder /opt/pyroscope/out/libpyroscope.phpspy.a /
COPY --from=go-libs-builder /opt/pyroscope/third_party/phpspy/libphpspy.a /
COPY --from=go-libs-builder /opt/pyroscope/out/libpyroscope.phpspy.h /
COPY --from=go-libs-builder /opt/pyroscope/out/libpyroscope.pyspy.a /
COPY --from=go-libs-builder /opt/pyroscope/out/libpyroscope.pyspy.h /
COPY --from=go-libs-builder /opt/pyroscope/out/libpyroscope.rbspy.a /
COPY --from=go-libs-builder /opt/pyroscope/out/libpyroscope.rbspy.h /
COPY --from=rust-builder /opt/rustdeps/librustdeps.a /
# __ _ _ _
# / _(_) | | (_)
# | |_ _ _ __ __ _| | _ _ __ ___ __ _ __ _ ___
# | _| | '_ \ / _` | | | | '_ ` _ \ / _` |/ _` |/ _ \
# | | | | | | | (_| | | | | | | | | | (_| | (_| | __/
# |_| |_|_| |_|\__,_|_| |_|_| |_| |_|\__,_|\__, |\___|
# __/ |
# |___/
FROM alpine:3.12
LABEL maintainer="Pyroscope team <[email protected]>"
WORKDIR /var/lib/pyroscope
RUN apk add --no-cache ca-certificates bash tzdata openssl musl-utils
RUN apk add --no-cache bcc-tools python3
RUN ln -s $(which python3) /usr/bin/python
RUN addgroup -S pyroscope && adduser -S pyroscope -G pyroscope
RUN mkdir -p \
"/var/lib/pyroscope" \
"/var/log/pyroscope" \
"/etc/pyroscope" \
&& \
chown -R "pyroscope:pyroscope" \
"/var/lib/pyroscope" \
"/var/log/pyroscope" \
"/etc/pyroscope" \
&& \
chmod -R 777 \
"/var/lib/pyroscope" \
"/var/log/pyroscope" \
"/etc/pyroscope"
COPY scripts/packages/server.yml "/etc/pyroscope/server.yml"
COPY --from=go-builder --chmod=0777 /opt/pyroscope/bin/pyroscope /usr/bin/pyroscope
RUN apk add bash-completion
RUN pyroscope completion bash > /usr/share/bash-completion/completions/pyroscope
USER pyroscope
EXPOSE 4040/tcp
ENTRYPOINT [ "/usr/bin/pyroscope" ]