From 127c7682d59291519315ed402e853addedcb8fe8 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Mon, 23 Jun 2025 23:35:11 +0200 Subject: [PATCH] overwritable context --- Makefile | 4 +- docker-bake.hcl | 108 +++++++++++++++++++++++++----------------------- 2 files changed, 59 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 6308f5234f..6862166db8 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,10 @@ export CACHE_DIR ?= $(XDG_CACHE_HOME)/zitadel-make export LOGIN_DIR := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) -export LOGIN_BAKE_CLI ?= docker buildx bake +LOGIN_BAKE_CLI ?= docker buildx bake LOGIN_BAKE_CLI_WITH_COMMON_ARGS := $(LOGIN_BAKE_CLI) --file $(LOGIN_DIR)docker-bake.hcl --file $(LOGIN_DIR)apps/login-test-acceptance/docker-compose.yaml +LOGIN_BAKE_CLI_ADDITIONAL_ARGS ?= +LOGIN_BAKE_CLI_WITH_COMMON_ARGS += $(LOGIN_BAKE_CLI_ADDITIONAL_ARGS) export COMPOSE_BAKE=true export UID := $(id -u) diff --git a/docker-bake.hcl b/docker-bake.hcl index 76eab2fac1..348dd2f76c 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,52 +1,14 @@ -variable "LOGIN_DIR" { - default = "./" -} - variable "DOCKERFILES_DIR" { default = "dockerfiles/" } -target "login-pnpm" { - context = "${LOGIN_DIR}" - dockerfile = "${DOCKERFILES_DIR}login-pnpm.Dockerfile" -} - -target "login-dev-base" { - dockerfile = "${DOCKERFILES_DIR}login-dev-base.Dockerfile" - context = "${LOGIN_DIR}" - contexts = { - login-pnpm = "target:login-pnpm" - } -} - -target "login-lint" { - dockerfile = "${DOCKERFILES_DIR}login-lint.Dockerfile" - context = "${LOGIN_DIR}" - contexts = { - login-dev-base = "target:login-dev-base" - } -} - -target "login-test-unit" { - dockerfile = "${DOCKERFILES_DIR}login-test-unit.Dockerfile" - context = "${LOGIN_DIR}" - contexts = { - login-client = "target:login-client" - } -} - -target "login-client" { - dockerfile = "${DOCKERFILES_DIR}login-client.Dockerfile" - context = "${LOGIN_DIR}" - contexts = { - login-pnpm = "target:login-pnpm" - typescript-proto-client = "target:typescript-proto-client" - } -} - +# typescript-proto-client is used to generate the client code for the login service. +# It is not login-prefixed, so it is easily extendable. +# To extend this bake-file.hcl, set the context of all login-prefixed targets to a different directory. +# For example docker bake --file login/docker-bake.hcl --file docker-bake.hcl --set login-*.context=./login/ +# The zitadel repository uses this to generate the client and the mock server from local proto files. target "typescript-proto-client" { dockerfile = "${DOCKERFILES_DIR}typescript-proto-client.Dockerfile" - context = "${LOGIN_DIR}" contexts = { # We directly generate and download the client server-side with buf, so we don't need the proto files login-pnpm = "target:login-pnpm" @@ -56,24 +18,69 @@ target "typescript-proto-client" { # proto-files is only used to build core-mock against which the integration tests run. # To build the proto-client, we use buf to generate and download the client code directly. +# It is not login-prefixed, so it is easily extendable. +# To extend this bake-file.hcl, set the context of all login-prefixed targets to a different directory. +# For example docker bake --file login/docker-bake.hcl --file docker-bake.hcl --set login-*.context=./login/ +# The zitadel repository uses this to generate the client and the mock server from local proto files. target "proto-files" { dockerfile = "${DOCKERFILES_DIR}proto-files.Dockerfile" - context = "${LOGIN_DIR}" contexts = { login-pnpm = "target:login-pnpm" } } -variable "CORE_MOCK_TAG" { - default = "core-mock:local" +target "login-pnpm" { + dockerfile = "${DOCKERFILES_DIR}login-pnpm.Dockerfile" } -target "core-mock" { - context = "${LOGIN_DIR}apps/login-test-integration/core-mock" +target "login-dev-base" { + dockerfile = "${DOCKERFILES_DIR}login-dev-base.Dockerfile" + contexts = { + login-pnpm = "target:login-pnpm" + } +} + +target "login-lint" { + dockerfile = "${DOCKERFILES_DIR}login-lint.Dockerfile" + contexts = { + login-dev-base = "target:login-dev-base" + } +} + +target "login-test-unit" { + dockerfile = "${DOCKERFILES_DIR}login-test-unit.Dockerfile" + contexts = { + login-client = "target:login-client" + } +} + +target "login-client" { + dockerfile = "${DOCKERFILES_DIR}login-client.Dockerfile" + contexts = { + login-pnpm = "target:login-pnpm" + typescript-proto-client = "target:typescript-proto-client" + } +} + +target "typescript-proto-client" { + dockerfile = "${DOCKERFILES_DIR}typescript-proto-client.Dockerfile" + contexts = { + # We directly generate and download the client server-side with buf, so we don't need the proto files + login-pnpm = "target:login-pnpm" + } + output = ["type=docker"] +} + +variable "LOGIN_CORE_MOCK_TAG" { + default = "login-core-mock:local" +} + +target "login-core-mock" { + context = "/apps/login-test-integration/core-mock" contexts = { protos = "target:proto-files" } - tags = ["${CORE_MOCK_TAG}"] + tags = ["${LOGIN_CORE_MOCK_TAG}"] output = ["type=docker"] } @@ -83,7 +90,6 @@ variable "LOGIN_TEST_INTEGRATION_TAG" { target "login-test-integration" { dockerfile = "${DOCKERFILES_DIR}login-test-integration.Dockerfile" - context = "${LOGIN_DIR}" contexts = { login-pnpm = "target:login-pnpm" } @@ -97,7 +103,6 @@ variable "LOGIN_TEST_ACCEPTANCE_TAG" { target "login-test-acceptance" { dockerfile = "${DOCKERFILES_DIR}login-test-acceptance.Dockerfile" - context = "${LOGIN_DIR}" contexts = { login-pnpm = "target:login-pnpm" } @@ -115,7 +120,6 @@ target "docker-metadata-action" {} target "login-standalone" { inherits = ["docker-metadata-action"] dockerfile = "${DOCKERFILES_DIR}login-standalone.Dockerfile" - context = "${LOGIN_DIR}" contexts = { login-client = "target:login-client" }