From 40ad36f5fd76a929f0144334642e486c362e3324 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Fri, 17 Feb 2023 15:09:11 +0100 Subject: [PATCH] chore(console): buf stub build (#5215) * buf gen yaml * dep, buildcmd * deps * buf yml * buf work * gen yml * buf * buf mod update * path * chore: fix buf * npm package * build as prodbuild * trigger * temp rm basepath * base href * generate as prelint * proto proto * rm unused gitignore --------- Co-authored-by: Florian Forster Co-authored-by: Livio Spring --- .goreleaser.yaml | 85 +++++++++++------------ buf.work.yaml | 3 + build/console/Dockerfile | 14 +--- build/console/generate-grpc.sh | 17 ----- console/.gitignore | 1 + console/buf.gen.yaml | 14 ++++ console/package-lock.json | 120 +++++++++++++++++++++++++++++++++ console/package.json | 7 +- proto/buf.lock | 15 +++++ proto/buf.yaml | 12 ++++ 10 files changed, 212 insertions(+), 76 deletions(-) create mode 100644 buf.work.yaml delete mode 100755 build/console/generate-grpc.sh create mode 100644 console/buf.gen.yaml create mode 100644 proto/buf.lock create mode 100644 proto/buf.yaml diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f772c5da1a..87ecad547e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -19,7 +19,6 @@ before: - docker build -f build/zitadel/Dockerfile . -t zitadel-go-test --target go-codecov -o .artifacts/codecov - docker build -f build/zitadel/Dockerfile . -t zitadel-go-base --target go-copy -o .artifacts/grpc/go-client - sh -c "cp -r .artifacts/grpc/go-client/* ." - - docker build -f build/console/Dockerfile . -t zitadel-npm-base --target npm-copy -o .artifacts/grpc/js-client - docker build -f build/console/Dockerfile . -t zitadel-npm-console --target angular-export -o .artifacts/console - sh -c "cp -r .artifacts/console/* internal/api/ui/console/static/" @@ -33,46 +32,44 @@ builds: goarch: - amd64 - arm64 - ldflags: - -s -w -X github.com/zitadel/zitadel/cmd/build.version={{.Version}} -X github.com/zitadel/zitadel/cmd/build.commit={{.Commit}} -X github.com/zitadel/zitadel/cmd/build.date={{.Date}} - + ldflags: -s -w -X github.com/zitadel/zitadel/cmd/build.version={{.Version}} -X github.com/zitadel/zitadel/cmd/build.commit={{.Commit}} -X github.com/zitadel/zitadel/cmd/build.date={{.Date}} + dist: .artifacts/goreleaser dockers: -- image_templates: - - ghcr.io/zitadel/zitadel:{{ .Tag }}-amd64 - - europe-docker.pkg.dev/zitadel-common/zitadel-repo/zitadel:{{ .Tag }}-amd64 - goarch: amd64 - use: buildx - dockerfile: build/Dockerfile - build_flag_templates: - - "--platform=linux/amd64" -- image_templates: - - ghcr.io/zitadel/zitadel:{{ .Tag }}-arm64 - - ghcr.io/zitadel/zitadel:{{ .ShortCommit }}-arm64 - goarch: arm64 - use: buildx - dockerfile: build/Dockerfile - build_flag_templates: - - "--platform=linux/arm64" + - image_templates: + - ghcr.io/zitadel/zitadel:{{ .Tag }}-amd64 + - europe-docker.pkg.dev/zitadel-common/zitadel-repo/zitadel:{{ .Tag }}-amd64 + goarch: amd64 + use: buildx + dockerfile: build/Dockerfile + build_flag_templates: + - "--platform=linux/amd64" + - image_templates: + - ghcr.io/zitadel/zitadel:{{ .Tag }}-arm64 + - ghcr.io/zitadel/zitadel:{{ .ShortCommit }}-arm64 + goarch: arm64 + use: buildx + dockerfile: build/Dockerfile + build_flag_templates: + - "--platform=linux/arm64" docker_manifests: -- id: zitadel-latest - name_template: ghcr.io/zitadel/zitadel:latest - image_templates: - - ghcr.io/zitadel/zitadel:{{ .Tag }}-amd64 - - ghcr.io/zitadel/zitadel:{{ .Tag }}-arm64 - # Skips can and shall be set for individual manifests same as in dockers - skip_push: auto -- id: zitadel-Tag - name_template: ghcr.io/zitadel/zitadel:{{ .Tag }} - image_templates: - - ghcr.io/zitadel/zitadel:{{ .Tag }}-amd64 - - ghcr.io/zitadel/zitadel:{{ .Tag }}-arm64 - + - id: zitadel-latest + name_template: ghcr.io/zitadel/zitadel:latest + image_templates: + - ghcr.io/zitadel/zitadel:{{ .Tag }}-amd64 + - ghcr.io/zitadel/zitadel:{{ .Tag }}-arm64 + # Skips can and shall be set for individual manifests same as in dockers + skip_push: auto + - id: zitadel-Tag + name_template: ghcr.io/zitadel/zitadel:{{ .Tag }} + image_templates: + - ghcr.io/zitadel/zitadel:{{ .Tag }}-amd64 + - ghcr.io/zitadel/zitadel:{{ .Tag }}-arm64 archives: - - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" replacements: darwin: Darwin linux: Linux @@ -80,8 +77,8 @@ archives: 386: i386 amd64: x86_64 format_overrides: - - goos: windows - format: zip + - goos: windows + format: zip files: - README.md - LICENSE @@ -90,14 +87,14 @@ gomod: proxy: false checksum: - name_template: 'checksums.txt' + name_template: "checksums.txt" changelog: sort: asc filters: exclude: - - '^docs:' - - '^test:' + - "^docs:" + - "^test:" brews: - tap: @@ -106,15 +103,15 @@ brews: token: "{{ .Env.GORELEASER_TOKEN_TAP }}" folder: Formula goarm: "7" - homepage: https://zitadel.com + homepage: https://zitadel.com description: Open source identity solution built for the container and cloud era license: Apache 2.0 test: | system "#{bin}/zitadel -v" dependencies: - - name: go - type: optional - - name: git + - name: go + type: optional + - name: git install: |- bin.install "zitadel" # If set to auto, the release will not be uploaded to the homebrew tap @@ -125,4 +122,4 @@ brews: announce: discord: enabled: true - message_template: 'ZITADEL {{ .Tag }} is ready! Check the notes: https://github.com/zitadel/zitadel/releases/tag/{{ .Tag }}' + message_template: "ZITADEL {{ .Tag }} is ready! Check the notes: https://github.com/zitadel/zitadel/releases/tag/{{ .Tag }}" diff --git a/buf.work.yaml b/buf.work.yaml new file mode 100644 index 0000000000..1878b341be --- /dev/null +++ b/buf.work.yaml @@ -0,0 +1,3 @@ +version: v1 +directories: + - proto diff --git a/build/console/Dockerfile b/build/console/Dockerfile index a0245a9a9b..9249ce368e 100644 --- a/build/console/Dockerfile +++ b/build/console/Dockerfile @@ -14,24 +14,14 @@ RUN npm ci # Sources COPY console . -COPY --from=zitadel-base:local /proto /proto -COPY --from=zitadel-base:local /usr/local/bin /usr/local/bin/. -COPY build/console build/console/ -RUN build/console/generate-grpc.sh - -####################### -## copy for local dev -####################### -FROM scratch as npm-copy -COPY --from=npm-base /console/src/app/proto/generated /console/src/app/proto/generated +COPY proto/ /proto/ ####################### ## angular lint workspace and prod build ####################### FROM npm-base as angular-build - RUN npm run lint -RUN npm run prodbuild +RUN npm run build ####################### ## Only Copy Assets diff --git a/build/console/generate-grpc.sh b/build/console/generate-grpc.sh deleted file mode 100755 index edf98a5d2a..0000000000 --- a/build/console/generate-grpc.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -set -eux - -GEN_PATH=src/app/proto/generated - -echo "Create folders" -mkdir -p $GEN_PATH - -echo "Generate grpc" - -protoc \ - -I=/proto/include \ - -I=node_modules/google-proto-files \ - --js_out=import_style=commonjs,binary:$GEN_PATH \ - --grpc-web_out=import_style=typescript,mode=grpcweb:$GEN_PATH \ - $(find /proto/include -iname "*.proto") \ No newline at end of file diff --git a/console/.gitignore b/console/.gitignore index d62651d00a..6616a44530 100644 --- a/console/.gitignore +++ b/console/.gitignore @@ -48,3 +48,4 @@ Thumbs.db # Proto generated js files src/app/proto + diff --git a/console/buf.gen.yaml b/console/buf.gen.yaml new file mode 100644 index 0000000000..1737c2dedb --- /dev/null +++ b/console/buf.gen.yaml @@ -0,0 +1,14 @@ +# buf.gen.yaml +version: v1 +managed: + enabled: true +plugins: + - plugin: buf.build/protocolbuffers/js + out: src/app/proto/generated + opt: import_style=commonjs,binary + - plugin: buf.build/grpc/web + out: src/app/proto/generated + opt: import_style=typescript,mode=grpcweb + - plugin: buf.build/grpc-ecosystem/openapiv2 + out: src/app/proto/generated + opt: allow_delete_body \ No newline at end of file diff --git a/console/package-lock.json b/console/package-lock.json index 086b3de455..e7c5620380 100644 --- a/console/package-lock.json +++ b/console/package-lock.json @@ -57,6 +57,7 @@ "@angular/cli": "^15.0.2", "@angular/compiler-cli": "^15.0.2", "@angular/language-service": "^15.0.4", + "@bufbuild/buf": "^1.14.0", "@types/jasmine": "~4.3.0", "@types/jasminewd2": "~2.0.10", "@types/jsonwebtoken": "^9.0.0", @@ -2473,6 +2474,125 @@ "node": ">=6.9.0" } }, + "node_modules/@bufbuild/buf": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf/-/buf-1.14.0.tgz", + "integrity": "sha512-hW6wua/V+goxF99TSoQ/ps/gLdLkyuMjUs6zm15rpNvYOqB5UNg3t4N29SOWqfGhwVU5eeAC2XubT24eVOCcRQ==", + "dev": true, + "hasInstallScript": true, + "bin": { + "buf": "bin/buf", + "protoc-gen-buf-breaking": "bin/protoc-gen-buf-breaking", + "protoc-gen-buf-lint": "bin/protoc-gen-buf-lint" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@bufbuild/buf-darwin-arm64": "1.14.0", + "@bufbuild/buf-darwin-x64": "1.14.0", + "@bufbuild/buf-linux-aarch64": "1.14.0", + "@bufbuild/buf-linux-x64": "1.14.0", + "@bufbuild/buf-win32-arm64": "1.14.0", + "@bufbuild/buf-win32-x64": "1.14.0" + } + }, + "node_modules/@bufbuild/buf-darwin-arm64": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-darwin-arm64/-/buf-darwin-arm64-1.14.0.tgz", + "integrity": "sha512-V6WonyHSLtrCd+xl5XAqzpDXUMLhJF3seVD6ap4yJW6nigHw49+Oz38oE0DgwOlkIOoNgS8TWsRZFUyBXfV9vQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-darwin-x64": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-darwin-x64/-/buf-darwin-x64-1.14.0.tgz", + "integrity": "sha512-ZhPc0mN7K8E8IJGWzdCxb5CHqwmv3HSB25IgEjqTkwCDIUV7cPIUfb/56G6ir0shWCcVRoGPv2KbSG5rL0AYIw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-linux-aarch64": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-linux-aarch64/-/buf-linux-aarch64-1.14.0.tgz", + "integrity": "sha512-M7La4zzSXGgIwhKclZFgh5OXvKkx5/1fsGKTJWfDL25xPMYrvZI7y1i44iOK5H8ciKe24fatITZHE0ZQVRohoQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-linux-x64": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-linux-x64/-/buf-linux-x64-1.14.0.tgz", + "integrity": "sha512-/fqaKAUpFNbP6A2ROU/r35R2Fxig55MtseYtHNSLcQI6k9ubhdVsI3cM0MlOZ1VawclDYFiTpCd1urUL7spvsw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-win32-arm64": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-win32-arm64/-/buf-win32-arm64-1.14.0.tgz", + "integrity": "sha512-t7cd8MfqJ2ew6uXUYVbgq97OzN/ybnJ5Q5yKbEGexkyOBHQZsEhv0FkJWkAn1DN93j5iqHO6xlDkHpGMjAW1sg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-win32-x64": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-win32-x64/-/buf-win32-x64-1.14.0.tgz", + "integrity": "sha512-KD0T1rkX7yfykKZodnAj2WxhIZfkA/sox6VAY20F6X6ckLP96/3TSVWvDPfDN2DNkTcmokygNtA2/ir0KejDfQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", diff --git a/console/package.json b/console/package.json index d4b80636f6..715e1e6b24 100644 --- a/console/package.json +++ b/console/package.json @@ -4,11 +4,11 @@ "scripts": { "ng": "ng", "start": "ng serve", - "build": "ng build", - "prodbuild": "ng build --configuration production --base-href=/ui/console/", + "build": "ng build --configuration production --base-href=/ui/console/", + "prelint": "npm run generate", "lint": "ng lint && prettier --check src", "lint:fix": "prettier --write src", - "generate": "DOCKER_BUILDKIT=1 docker build -f ../build/grpc/Dockerfile -t zitadel-base:local .. && DOCKER_BUILDKIT=1 docker build -f ../build/console/Dockerfile .. --target npm-copy -o .." + "generate": "buf generate ../proto --include-imports --include-wkt" }, "private": true, "dependencies": { @@ -61,6 +61,7 @@ "@angular/cli": "^15.0.2", "@angular/compiler-cli": "^15.0.2", "@angular/language-service": "^15.0.4", + "@bufbuild/buf": "^1.14.0", "@types/jasmine": "~4.3.0", "@types/jasminewd2": "~2.0.10", "@types/jsonwebtoken": "^9.0.0", diff --git a/proto/buf.lock b/proto/buf.lock new file mode 100644 index 0000000000..99e2d27c7f --- /dev/null +++ b/proto/buf.lock @@ -0,0 +1,15 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: envoyproxy + repository: protoc-gen-validate + commit: 6607b10f00ed4a3d98f906807131c44a + - remote: buf.build + owner: googleapis + repository: googleapis + commit: 75b4300737fb4efca0831636be94e517 + - remote: buf.build + owner: grpc-ecosystem + repository: grpc-gateway + commit: a1ecdc58eccd49aa8bea2a7a9022dc27 diff --git a/proto/buf.yaml b/proto/buf.yaml new file mode 100644 index 0000000000..6069b76c7f --- /dev/null +++ b/proto/buf.yaml @@ -0,0 +1,12 @@ +version: v1 +name: buf.build/zitadel/zitadel +deps: + - buf.build/grpc-ecosystem/grpc-gateway + - buf.build/envoyproxy/protoc-gen-validate + - buf.build/googleapis/googleapis +breaking: + use: + - FILE +lint: + use: + - MINIMAL