Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Updated Dockerfiles #3052

Merged
merged 5 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .docker/Dockerfile-alpine
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM alpine:3.15.1
FROM alpine:3.15

RUN addgroup -S ory; \
adduser -S ory -G ory -D -H -s /bin/nologin
RUN apk --no-cache --update-cache --upgrade --latest add ca-certificates
RUN apk --no-cache --upgrade --latest add ca-certificates

COPY hydra /usr/bin/hydra

Expand Down
17 changes: 9 additions & 8 deletions .docker/Dockerfile-build
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
FROM golang:1.17-alpine3.15 AS builder

RUN apk -U --no-cache add build-base git gcc bash
RUN apk -U --no-cache --upgrade --latest add build-base git gcc bash

WORKDIR /go/src/github.com/ory/hydra

ADD go.mod go.mod
ADD go.sum go.sum

COPY go.mod go.sum ./
ENV GO111MODULE on
ENV CGO_ENABLED 1

RUN go mod download

ADD . .
COPY . .

RUN go build -tags sqlite -o /usr/bin/hydra

FROM alpine:3.15.1
FROM alpine:3.15

RUN addgroup -S ory; \
adduser -S ory -G ory -D -h /home/ory -s /bin/nologin; \
Expand All @@ -26,8 +24,9 @@ COPY --from=builder /usr/bin/hydra /usr/bin/hydra

# By creating the sqlite folder as the ory user, the mounted volume will be owned by ory:ory, which
# is required for read/write of SQLite.
RUN mkdir -p /var/lib/sqlite
RUN chown ory:ory /var/lib/sqlite
RUN mkdir -p /var/lib/sqlite && \
chown ory:ory /var/lib/sqlite

VOLUME /var/lib/sqlite

# Exposing the ory home directory
Expand All @@ -40,3 +39,5 @@ USER ory

ENTRYPOINT ["hydra"]
CMD ["serve"]


20 changes: 10 additions & 10 deletions .docker/Dockerfile-hsm
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM golang:1.16-alpine AS builder
FROM golang:1.18-alpine AS builder

RUN apk --no-cache --update-cache --upgrade --latest add build-base git gcc bash
RUN apk --no-cache add --upgrade --latest build-base git gcc bash

WORKDIR /go/src/github.com/ory/hydra

ADD go.mod go.mod
ADD go.sum go.sum
COPY go.mod go.sum ./

ENV GO111MODULE on
ENV CGO_ENABLED 1

RUN go mod download

ADD . .
COPY . .

FROM builder as build-hydra
RUN go build -tags=sqlite,hsm -o /usr/bin/hydra
Expand All @@ -23,13 +22,13 @@ ENV HSM_LIBRARY=/usr/lib/softhsm/libsofthsm2.so
ENV HSM_TOKEN_LABEL=hydra
ENV HSM_PIN=1234

RUN apk --no-cache --update-cache --upgrade --latest add softhsm opensc; \
RUN apk --no-cache --upgrade --latest add softhsm opensc; \
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 0 --init-token --so-pin 0000 --init-pin --pin 1234 --label hydra; \
go test -p 1 -v -failfast -short -tags=sqlite,hsm ./...

FROM alpine:3.15.1
FROM alpine:3.15

RUN apk --no-cache --update-cache --upgrade --latest add softhsm opensc; \
RUN apk --no-cache --upgrade --latest add softhsm opensc; \
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 0 --init-token --so-pin 0000 --init-pin --pin 1234 --label hydra

RUN addgroup -S ory; \
Expand All @@ -41,8 +40,9 @@ COPY --from=build-hydra /usr/bin/hydra /usr/bin/hydra

# By creating the sqlite folder as the ory user, the mounted volume will be owned by ory:ory, which
# is required for read/write of SQLite.
RUN mkdir -p /var/lib/sqlite
RUN chown ory:ory /var/lib/sqlite
RUN mkdir -p /var/lib/sqlite && \
chown ory:ory /var/lib/sqlite

VOLUME /var/lib/sqlite

# Exposing the ory home directory
Expand Down
4 changes: 2 additions & 2 deletions .docker/Dockerfile-scratch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.15.1
FROM alpine:3.15

RUN apk --no-cache --update-cache --upgrade --latest add ca-certificates
RUN apk --no-cache --upgrade --latest add ca-certificates

# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
Expand Down
11 changes: 6 additions & 5 deletions .docker/Dockerfile-sqlite
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.15.1
FROM alpine:3.15

# Because this image is built for SQLite, we create /home/ory and /home/ory/sqlite which is owned by the ory user
# and declare /home/ory/sqlite a volume.
Expand All @@ -9,17 +9,18 @@ FROM alpine:3.15.1

RUN addgroup -S ory; \
adduser -S ory -G ory -D -h /home/ory -s /bin/nologin; \
chown -R ory:ory /home/ory
RUN apk --no-cache --update-cache --upgrade --latest add ca-certificates
chown -R ory:ory /home/ory && \
apk --no-cache --upgrade --latest add ca-certificates

WORKDIR /home/ory

COPY hydra /usr/bin/hydra

# By creating the sqlite folder as the ory user, the mounted volume will be owned by ory:ory, which
# is required for read/write of SQLite.
RUN mkdir -p /var/lib/sqlite
RUN chown ory:ory /var/lib/sqlite
RUN mkdir -p /var/lib/sqlite && \
chown ory:ory /var/lib/sqlite

VOLUME /var/lib/sqlite

# Exposing the ory home directory
Expand Down
5 changes: 3 additions & 2 deletions test/conformance/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ RUN wget https://gitlab.com/openid/conformance-suite/-/archive/release-v4.1.4/co
find conformance-suite-release-v4.1.4 -maxdepth 1 -mindepth 1 -exec mv {} . \; && \
rmdir conformance-suite-release-v4.1.4

RUN mvn -B clean package -DskipTests
RUN apt-get update && apt-get install -y redir ca-certificates
RUN mvn -B clean package -DskipTests && \
apt-get update && apt-get install -y \
redir ca-certificates && \

COPY ssl/ory-conformity.crt /etc/ssl/certs/
COPY ssl/ory-conformity.key /etc/ssl/private/
Expand Down
17 changes: 9 additions & 8 deletions test/conformance/hydra/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
FROM golang:1.17-buster AS builder

RUN apt-get update && \
apt-get install -y git gcc bash ssl-cert ca-certificates
apt-get install --no-install-recommends -y \
git gcc bash ssl-cert ca-certificates && \
rm -rf /var/lib/apt/lists/*

WORKDIR /go/src/github.com/ory/hydra

ADD go.mod go.mod
ADD go.sum go.sum
COPY go.mod go.sum ./

ENV GO111MODULE on
ENV CGO_ENABLED 1

RUN go mod download

ADD . .
COPY . .

RUN go build -tags sqlite -o /usr/bin/hydra

Expand All @@ -25,10 +26,10 @@ VOLUME /home/ory
# Declare the standard ports used by hydra (4444 for public service endpoint, 4445 for admin service endpoint)
EXPOSE 4444 4445

RUN mv test/conformance/ssl/ory-ca.* /etc/ssl/certs/
RUN mv test/conformance/ssl/ory-conformity.crt /etc/ssl/certs/
RUN mv test/conformance/ssl/ory-conformity.key /etc/ssl/private/
RUN update-ca-certificates
RUN mv test/conformance/ssl/ory-ca.* /etc/ssl/certs/ && \
mv test/conformance/ssl/ory-conformity.crt /etc/ssl/certs/ && \
mv test/conformance/ssl/ory-conformity.key /etc/ssl/private/ && \
update-ca-certificates

ENTRYPOINT ["hydra"]
CMD ["serve"]