-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
165 lines (134 loc) · 7.3 KB
/
Copy pathDockerfile
File metadata and controls
165 lines (134 loc) · 7.3 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
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
ARG GOLANG_VERSION=1.25.6
ARG ALPINE_VERSION=3.23
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS krakend_builder
RUN apk --no-cache --virtual .build-deps add git make gcc musl-dev binutils-gold
ARG KRAKEND_CE_VERSION
RUN git clone https://github.com/krakendio/krakend-ce.git /krakend && \
cd /krakend && \
git checkout v${KRAKEND_CE_VERSION} && \
make build && \
cp krakend /usr/bin
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} 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/simple-auth plugins/simple-auth
COPY plugins/registry plugins/registry
COPY plugins/blob plugins/blob
COPY plugins/pipeline-sse-streaming plugins/pipeline-sse-streaming
COPY plugins/model-sse-streaming plugins/model-sse-streaming
COPY plugins/http-no-pool plugins/http-no-pool
ARG TARGETARCH
ARG BUILDARCH
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
curl -fSL --retry 10 --retry-delay 5 --retry-all-errors \
-o /tmp/aarch64-linux-musl-cross.tgz \
https://artifacts.instill-ai.com/github-actions/aarch64-linux-musl-cross.tgz && \
tar -xzf /tmp/aarch64-linux-musl-cross.tgz && \
rm /tmp/aarch64-linux-musl-cross.tgz; \
fi
ENV PATH="$PATH:/${SERVICE_NAME}/aarch64-linux-musl-cross/bin"
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
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 \
cd /${SERVICE_NAME}/plugins/simple-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 simple-auth.so ./; \
else \
cd /${SERVICE_NAME}/plugins/simple-auth && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o simple-auth.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
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 \
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 \
cd /${SERVICE_NAME}/plugins/pipeline-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 pipeline-sse-streaming.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/pipeline-sse-streaming && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o pipeline-sse-streaming.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
cd /${SERVICE_NAME}/plugins/model-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 model-sse-streaming.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/model-sse-streaming && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o model-sse-streaming.so ./ ; fi
RUN if [[ "$BUILDARCH" = "amd64" && "$TARGETARCH" = "arm64" ]] ; \
then \
cd /${SERVICE_NAME}/plugins/http-no-pool && 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 http-no-pool.so ./ ; \
else \
cd /${SERVICE_NAME}/plugins/http-no-pool && go mod download && \
CGO_ENABLED=1 go build -buildmode=plugin -buildvcs=false -o http-no-pool.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 \
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 SERVICE_VERSION
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/simple-auth/simple-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/pipeline-sse-streaming/pipeline-sse-streaming.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/model-sse-streaming/model-sse-streaming.so /usr/local/lib/krakend/plugins
COPY --from=build --chown=krakend:nogroup /${SERVICE_NAME}/plugins/http-no-pool/http-no-pool.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
ENV SERVICE_NAME=${SERVICE_NAME}
ENV SERVICE_VERSION=${SERVICE_VERSION}