-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
136 lines (112 loc) · 5.97 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
FROM golang:1.22.6-alpine3.20 as krakend_builder
RUN apk --no-cache --virtual .build-deps add git make gcc musl-dev binutils-gold
RUN git clone -b v2.7.0 https://github.com/krakendio/krakend-ce.git /krakend && cd /krakend && make build && cp krakend /usr/bin
FROM --platform=$BUILDPLATFORM golang:1.22.6-alpine3.20 AS build
ARG SERVICE_NAME
RUN apk --no-cache --virtual .build-deps add tar make gcc musl-dev binutils-gold build-base curl git bash
WORKDIR /${SERVICE_NAME}
COPY plugins/grpc-proxy plugins/grpc-proxy
COPY plugins/multi-auth plugins/multi-auth
COPY plugins/registry plugins/registry
COPY plugins/blob plugins/blob
COPY plugins/sse-streaming plugins/sse-streaming
ARG TARGETARCH
ARG BUILDARCH
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -sL http://musl.cc/aarch64-linux-musl-cross.tgz | \
tar zx && \
export PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin" && \
cd /${SERVICE_NAME}/plugins/grpc-proxy && go mod download && \
CGO_ENABLED=1 ARCH=$TARGETARCH GOARCH=$TARGETARCH GOHOSTARCH=$BUILDARCH \
CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc' \
go build -buildmode=plugin -buildvcs=false -o grpc-proxy.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/grpc-proxy && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o grpc-proxy.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -sL http://musl.cc/aarch64-linux-musl-cross.tgz | \
tar zx && \
export PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin" && \
cd /${SERVICE_NAME}/plugins/multi-auth && go mod download && \
CGO_ENABLED=1 ARCH=$TARGETARCH GOARCH=$TARGETARCH GOHOSTARCH=$BUILDARCH \
CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc' \
go build -buildmode=plugin -buildvcs=false -o multi-auth.so ./; \
else \
cd /${SERVICE_NAME}/plugins/multi-auth && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o multi-auth.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -sL http://musl.cc/aarch64-linux-musl-cross.tgz | \
tar zx && \
export PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin" && \
cd /${SERVICE_NAME}/plugins/registry && go mod download && \
CGO_ENABLED=1 ARCH=$TARGETARCH GOARCH=$TARGETARCH GOHOSTARCH=$BUILDARCH \
CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc' \
go build -buildmode=plugin -buildvcs=false -o registry.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/registry && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o registry.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -sL http://musl.cc/aarch64-linux-musl-cross.tgz | \
tar zx && \
export PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin" && \
cd /${SERVICE_NAME}/plugins/blob && go mod download && \
CGO_ENABLED=1 ARCH=$TARGETARCH GOARCH=$TARGETARCH GOHOSTARCH=$BUILDARCH \
CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc' \
go build -buildmode=plugin -buildvcs=false -o blob.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/blob && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o blob.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -sL http://musl.cc/aarch64-linux-musl-cross.tgz | \
tar zx && \
export PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin" && \
cd /${SERVICE_NAME}/plugins/sse-streaming && go mod download && \
CGO_ENABLED=1 ARCH=$TARGETARCH GOARCH=$TARGETARCH GOHOSTARCH=$BUILDARCH \
CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc' \
go build -buildmode=plugin -buildvcs=false -o sse-streaming.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/sse-streaming && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o sse-streaming.so ./ ; fi
RUN cd /${SERVICE_NAME} && \
git clone -b v2.0.12 https://github.com/lestrrat-go/jwx.git && \
if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -sL http://musl.cc/aarch64-linux-musl-cross.tgz | \
tar zx && \
export PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin" && \
cd /${SERVICE_NAME}/jwx/cmd/jwx && go mod download && \
CGO_ENABLED=1 ARCH=$TARGETARCH GOARCH=$TARGETARCH GOHOSTARCH=$BUILDARCH \
CC=aarch64-linux-musl-gcc EXTRA_LDFLAGS='-extld=aarch64-linux-musl-gcc' \
go build -o /go/bin/jwx . ; \
else \
cd /${SERVICE_NAME}/jwx/cmd/jwx && go mod download && \
go build -o /go/bin/jwx . ; \
fi
FROM alpine:3.20
RUN apk update && apk add make bash gettext jq curl
RUN apk add --no-cache ca-certificates tzdata && \
adduser -u 1000 -S -D -H krakend && \
mkdir /etc/krakend && \
echo '{ "version": 3 }' > /etc/krakend/krakend.json
COPY --from=krakend_builder /usr/bin/krakend /usr/bin/krakend
ARG SERVICE_NAME
WORKDIR /${SERVICE_NAME}
RUN mkdir -p /usr/local/lib/krakend/plugins && chmod 777 /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/grpc-proxy/grpc-proxy.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/multi-auth/multi-auth.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/registry/registry.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/blob/blob.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/sse-streaming/sse-streaming.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /go/bin/jwx /go/bin/jwx
RUN mkdir -p /instill && chmod 777 /instill
COPY .env .env
COPY Makefile Makefile
COPY config config
COPY scripts scripts
RUN chown krakend:nogroup -R .
USER krakend