Skip to content

Commit 9378b07

Browse files
committed
fix: improve docker set up
1 parent b2f202c commit 9378b07

File tree

8 files changed

+59
-173
lines changed

8 files changed

+59
-173
lines changed

.docker/Dockerfile-alpine

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ HEREDOC
2424

2525
COPY hydra /usr/bin/hydra
2626

27+
USER ory
28+
2729
ENTRYPOINT ["hydra"]
2830
CMD ["serve", "all"]
29-
USER ory

.docker/Dockerfile-hsm

Lines changed: 0 additions & 88 deletions
This file was deleted.

.docker/Dockerfile-scratch

Lines changed: 0 additions & 41 deletions
This file was deleted.

.docker/Dockerfile-sqlite

Lines changed: 0 additions & 36 deletions
This file was deleted.

.docker/Dockerfile-test-hsm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file is only used for testing the HSM feature of Hydra. It is not used in production nor is it being
2+
# distributed.
3+
FROM golang:1.22-alpine3.21 AS builder
4+
5+
RUN apk -U --no-cache --upgrade --latest add build-base git gcc bash
6+
7+
WORKDIR /go/src/github.com/ory/hydra
8+
RUN mkdir -p ./internal/httpclient
9+
10+
COPY go.mod go.sum ./
11+
COPY internal/httpclient/go.* ./internal/httpclient
12+
13+
ENV CGO_ENABLED 1
14+
15+
RUN go mod download
16+
17+
COPY . .
18+
19+
FROM builder as build-hydra
20+
21+
ENV HSM_ENABLED=true
22+
ENV HSM_LIBRARY=/usr/lib/softhsm/libsofthsm2.so
23+
ENV HSM_TOKEN_LABEL=hydra
24+
ENV HSM_PIN=1234
25+
ENV UPDATE_SNAPSHOTS=true
26+
27+
RUN apt-get -y install softhsm opensc
28+
RUN pkcs11-tool --module "$HSM_LIBRARY" --slot 0 --init-token --so-pin 0000 --init-pin --pin "$HSM_PIN" --label "$HSM_TOKEN_LABEL"
29+
30+
FROM builder as test-hsm
31+
32+
RUN go test -p 1 -failfast -short -tags=sqlite,hsm ./...
33+
34+
FROM builder AS test-refresh-hsm
35+
36+
RUN go test -p 1 -failfast -short -tags=sqlite,hsm,refresh ./...

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test-resetdb: node_modules
7171
# Build local docker images
7272
.PHONY: docker
7373
docker:
74-
DOCKER_BUILDKIT=1 DOCKER_CONTENT_TRUST=1 docker build --progress=plain -f .docker/Dockerfile-build -t oryd/hydra:${IMAGE_TAG}-sqlite .
74+
DOCKER_BUILDKIT=1 DOCKER_CONTENT_TRUST=1 docker build --progress=plain -f .docker/Dockerfile-build -t oryd/hydra:${IMAGE_TAG} .
7575

7676
.PHONY: e2e
7777
e2e: node_modules test-resetdb
@@ -88,12 +88,12 @@ quicktest:
8888

8989
.PHONY: quicktest-hsm
9090
quicktest-hsm:
91-
DOCKER_BUILDKIT=1 DOCKER_CONTENT_TRUST=1 docker build --progress=plain -f .docker/Dockerfile-hsm --target test-hsm -t oryd/hydra:${IMAGE_TAG} --target test-hsm .
91+
DOCKER_BUILDKIT=1 DOCKER_CONTENT_TRUST=1 docker build --progress=plain -f .docker/Dockerfile-test-hsm --target test-hsm -t oryd/hydra:${IMAGE_TAG} --target test-hsm .
9292

9393
.PHONY: test-refresh
9494
test-refresh:
9595
UPDATE_SNAPSHOTS=true go test -failfast -short -tags sqlite,sqlite_omit_load_extension ./...
96-
DOCKER_BUILDKIT=1 DOCKER_CONTENT_TRUST=1 docker build --progress=plain -f .docker/Dockerfile-hsm --target test-refresh-hsm -t oryd/hydra:${IMAGE_TAG} --target test-refresh-hsm .
96+
DOCKER_BUILDKIT=1 DOCKER_CONTENT_TRUST=1 docker build --progress=plain -f .docker/Dockerfile-test-hsm --target test-refresh-hsm -t oryd/hydra:${IMAGE_TAG} --target test-refresh-hsm .
9797

9898
authors: # updates the AUTHORS file
9999
curl https://raw.githubusercontent.com/ory/ci/master/authors/authors.sh | env PRODUCT="Ory Hydra" bash

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ that your company deserves a spot here, reach out to
609609
</picture>
610610
</td>
611611
<td><a href="https://pinniped.dev/">pinniped.dev</a></td>
612-
</tr>
612+
</tr>
613613
<tr>
614614
<td>Adopter *</td>
615615
<td>Pvotal</td>
@@ -835,7 +835,9 @@ make quicktest
835835

836836
# regular tests
837837
make test
838-
test-resetdb
838+
839+
# updates all snapshots
840+
make test-refresh
839841

840842
# end-to-end tests
841843
make e2e
@@ -977,10 +979,12 @@ If you wish to check your code changes against any of the docker-compose
977979
quickstart files, run:
978980

979981
```shell script
980-
make docker
981-
docker compose -f quickstart.yml up # ....
982+
docker compose -f quickstart.yml up --build # ....
982983
```
983984

985+
Warning, this will override your local image tag with the latest build and can
986+
lead to unexpected or confusing behavior.
987+
984988
#### Add a new migration
985989

986990
1. `mkdir persistence/sql/src/YYYYMMDD000001_migration_name/`

quickstart.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
services:
1313
hydra:
1414
image: oryd/hydra:v2.2.0
15+
build:
16+
context: .
17+
dockerfile: .docker/Dockerfile-build
1518
ports:
1619
- "4444:4444" # Public port
1720
- "4445:4445" # Admin port
@@ -25,18 +28,25 @@ services:
2528
- type: bind
2629
source: ./contrib/quickstart/5-min
2730
target: /etc/config/hydra
31+
pull_policy: missing
2832
environment:
2933
- DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true
3034
restart: unless-stopped
35+
user: 500:500
3136
depends_on:
3237
- hydra-migrate
3338
networks:
3439
- intranet
3540
hydra-migrate:
3641
image: oryd/hydra:v2.2.0
42+
build:
43+
context: .
44+
dockerfile: .docker/Dockerfile-build
3745
environment:
3846
- DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true
3947
command: migrate -c /etc/config/hydra/hydra.yml sql -e --yes
48+
user: 500:500
49+
pull_policy: missing
4050
volumes:
4151
- type: volume
4252
source: hydra-sqlite

0 commit comments

Comments
 (0)