1- FROM golang:1.20-alpine3.18 AS builder
2-
3- RUN apk -U --no-cache --upgrade --latest add build-base git gcc bash
1+ FROM golang:1.20 AS builder
42
53WORKDIR /go/src/github.com/ory/hydra
6- RUN mkdir -p ./internal/httpclient
4+
5+ RUN apt-get update && apt-get upgrade -y &&\
6+ mkdir -p /var/lib/sqlite &&\
7+ mkdir -p ./internal/httpclient
78
89COPY go.mod go.sum ./
910COPY internal/httpclient/go.* ./internal/httpclient
@@ -12,26 +13,36 @@ ENV GO111MODULE on
1213ENV CGO_ENABLED 1
1314
1415RUN go mod download
15-
1616COPY . .
1717
18+ ###############################
19+
1820FROM builder as build-hydra
1921RUN go build -tags sqlite,json1,hsm -o /usr/bin/hydra
2022
23+ ###############################
24+
2125FROM builder as test-hsm
2226ENV HSM_ENABLED=true
2327ENV HSM_LIBRARY=/usr/lib/softhsm/libsofthsm2.so
2428ENV HSM_TOKEN_LABEL=hydra
2529ENV HSM_PIN=1234
2630
27- RUN apk --no-cache --upgrade --latest add softhsm opensc; \
28- pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 0 --init-token --so-pin 0000 --init-pin --pin 1234 --label hydra; \
31+ RUN apt-get -y install softhsm opensc && \
32+ pkcs11-tool --module "$HSM_LIBRARY" --slot 0 --init-token --so-pin 0000 --init-pin --pin "$HSM_PIN" --label "$HSM_TOKEN_LABEL" && \
2933 go test -p 1 -v -failfast -short -tags=sqlite,hsm ./...
3034
31- FROM alpine:3.18
35+ ###############################
36+
37+ FROM gcr.io/distroless/base-nossl-debian11:debug-nonroot AS runner
38+
39+ ENV HSM_ENABLED=true
40+ ENV HSM_LIBRARY=/usr/lib/softhsm/libsofthsm2.so
41+ ENV HSM_TOKEN_LABEL=hydra
42+ ENV HSM_PIN=1234
3243
33- RUN apk --no-cache --upgrade --latest add softhsm opensc; \
34- pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 0 --init-token --so-pin 0000 --init-pin --pin 1234 --label hydra
44+ RUN apt-get -y install softhsm opensc && \
45+ pkcs11-tool --module "$HSM_LIBRARY" --slot 0 --init-token --so-pin 0000 --init-pin --pin "$HSM_PIN" --label "$HSM_TOKEN_LABEL"
3546
3647RUN addgroup -S ory; \
3748 adduser -S ory -G ory -D -h /home/ory -s /bin/nologin; \
0 commit comments