This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathalpine.Dockerfile
135 lines (112 loc) · 5.32 KB
/
alpine.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
# syntax=docker/dockerfile:1.3-labs
ARG PG_VERSION=14
ARG TIMESCALEDB_VERSION_FULL=2.9.1
ARG PREVIOUS_IMAGE=timescaledev/promscale-extension:latest-ts2-pg${PG_VERSION}
FROM timescale/timescaledb:${TIMESCALEDB_VERSION_FULL}-pg${PG_VERSION} as builder
LABEL maintainer="Timescale https://www.timescale.com"
ARG RUST_VERSION=1.64.0
ARG PG_VERSION
RUN \
apk add --no-cache --virtual .build-deps \
curl \
coreutils \
gcc \
libgcc \
libc-dev \
clang-dev \
clang-libs \
make \
git \
linux-headers \
openssl-dev
RUN <<EOF
curl -L "https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz" | tar zxf -
chmod +x sccache-*/sccache
mv sccache-*/sccache /usr/local/bin/sccache
sccache --show-stats
EOF
ENV RUSTC_WRAPPER=sccache
ENV SCCACHE_BUCKET=promscale-extension-sccache
WORKDIR /home/promscale
ENV HOME=/home/promscale \
PATH=/home/promscale/.cargo/bin:$PATH
RUN chown postgres:postgres /home/promscale
# We must use a non-root user due to `pgx init` requirements
USER postgres
RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --component rustfmt --default-toolchain $RUST_VERSION && \
rustup --version && \
rustc --version && \
cargo --version
COPY install-cargo-pgx.sh /usr/local/bin
# Remove crt-static feature on musl target to allow building cdylibs
ENV RUSTFLAGS="-C target-feature=-crt-static"
RUN --mount=type=cache,uid=70,gid=70,target=/build/promscale/.cargo/registry \
--mount=type=secret,uid=70,gid=70,id=AWS_ACCESS_KEY_ID --mount=type=secret,uid=70,gid=70,id=AWS_SECRET_ACCESS_KEY \
[ -f "/run/secrets/AWS_ACCESS_KEY_ID" ] && export AWS_ACCESS_KEY_ID="$(cat /run/secrets/AWS_ACCESS_KEY_ID)" ; \
[ -f "/run/secrets/AWS_SECRET_ACCESS_KEY" ] && export AWS_SECRET_ACCESS_KEY="$(cat /run/secrets/AWS_SECRET_ACCESS_KEY)" ; \
sccache --show-stats && \
install-cargo-pgx.sh && \
cargo pgx init --pg${PG_VERSION} $(which pg_config) && \
sccache --show-stats
USER root
WORKDIR /build/promscale
RUN chown -R postgres:postgres /build
USER postgres
# Pre-build extension dependencies
RUN cd ../ && cargo pgx new promscale && cd promscale
COPY Cargo.* Makefile extract-extension-version.sh /build/promscale/
COPY test-common /build/promscale/test-common
COPY sql-tests /build/promscale/sql-tests
COPY pgtap-parse /build/promscale/pgtap-parse
COPY e2e /build/promscale/e2e
COPY gendoc/ /build/promscale/gendoc/
RUN --mount=type=secret,uid=70,gid=70,id=AWS_ACCESS_KEY_ID --mount=type=secret,uid=70,gid=70,id=AWS_SECRET_ACCESS_KEY \
--mount=type=cache,uid=70,gid=70,target=/build/promscale/.cargo/registry \
[ -f "/run/secrets/AWS_ACCESS_KEY_ID" ] && export AWS_ACCESS_KEY_ID="$(cat /run/secrets/AWS_ACCESS_KEY_ID)" ; \
[ -f "/run/secrets/AWS_SECRET_ACCESS_KEY" ] && export AWS_SECRET_ACCESS_KEY="$(cat /run/secrets/AWS_SECRET_ACCESS_KEY)" ; \
sccache --show-stats && \
make dependencies && \
sccache --show-stats
# Build extension
COPY --chown=postgres:postgres Cargo.* /build/promscale/
COPY --chown=postgres:postgres Makefile build.rs create-upgrade-symlinks.sh extract-extension-version.sh /build/promscale/
COPY --chown=postgres:postgres .cargo/ /build/promscale/.cargo/
COPY --chown=postgres:postgres e2e/ /build/promscale/e2e/
COPY --chown=postgres:postgres src/ /build/promscale/src/
COPY --chown=postgres:postgres sql/*.sql /build/promscale/sql/
COPY --chown=postgres:postgres migration/ /build/promscale/migration
COPY --chown=postgres:postgres templates/ /build/promscale/templates/
RUN --mount=type=secret,uid=70,gid=70,id=AWS_ACCESS_KEY_ID --mount=type=secret,uid=70,gid=70,id=AWS_SECRET_ACCESS_KEY \
--mount=type=cache,uid=70,gid=70,target=/build/promscale/.cargo/registry \
[ -f "/run/secrets/AWS_ACCESS_KEY_ID" ] && export AWS_ACCESS_KEY_ID="$(cat /run/secrets/AWS_ACCESS_KEY_ID)" ; \
[ -f "/run/secrets/AWS_SECRET_ACCESS_KEY" ] && export AWS_SECRET_ACCESS_KEY="$(cat /run/secrets/AWS_SECRET_ACCESS_KEY)" ; \
sccache --show-stats && \
make package && \
sccache --show-stats
RUN env
RUN sccache --show-stats
FROM timescale/timescaledb:${TIMESCALEDB_VERSION_FULL}-pg${PG_VERSION} as pgextwlist-builder
RUN \
apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
git \
clang \
llvm
RUN \
git clone --branch v1.15 --depth 1 https://github.com/dimitri/pgextwlist.git /pgextwlist && \
cd /pgextwlist && \
make
FROM ${PREVIOUS_IMAGE} as prev_img
# COPY over the new files to the image. Done as a seperate stage so we don't
# ship the build tools.
FROM timescale/timescaledb:${TIMESCALEDB_VERSION_FULL}-pg${PG_VERSION}
ARG PG_VERSION
COPY --from=prev_img /usr/local/lib/postgresql/promscale* /usr/local/lib/postgresql
COPY --from=prev_img /usr/local/share/postgresql/extension/promscale* /usr/local/share/postgresql/extension
COPY --from=builder /build/promscale/target/release/promscale-pg${PG_VERSION}/usr/local/lib/postgresql /usr/local/lib/postgresql
COPY --from=builder /build/promscale/target/release/promscale-pg${PG_VERSION}/usr/local/share/postgresql /usr/local/share/postgresql
RUN mkdir -p /usr/local/lib/postgresql/plugins
COPY --from=pgextwlist-builder /pgextwlist/pgextwlist.so /usr/local/lib/postgresql/plugins