| 1 |
# |
| 2 |
# Copyright 2022 The Sigstore Authors. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
PROTOC_IMAGE = protoc-base |
| 17 |
PROTOC_GO_IMAGE = protoc-go |
| 18 |
PROTOC_PYTHON_IMAGE = protoc-python |
| 19 |
PROTOC_RUBY_IMAGE = protoc-ruby |
| 20 |
PROTOC_RUST_IMAGE = protoc-rust |
| 21 |
# the container release action depends on the name being "protoc-services" |
| 22 |
# so change it there too if you change it here. |
| 23 |
PROTOC_SERVICES_IMAGE = protoc-services |
| 24 |
PROTOC_TYPESCRIPT_IMAGE = protoc-typescript |
| 25 |
|
| 26 |
RUST_ACTION ?= run -p sigstore-protobuf-specs-codegen |
| 27 |
|
| 28 |
PLATFORM ?= linux/amd64 |
| 29 |
UID ?= $(shell id -u) |
| 30 |
GID ?= $(shell id -g) |
| 31 |
DOCKER_BUILD = docker build --platform ${PLATFORM} --build-arg UID=${UID} |
| 32 |
DOCKER_RUN = docker run --platform ${PLATFORM} --user ${UID}:${GID} |
| 33 |
|
| 34 |
# base protos for clients that do not want to include service-protos |
| 35 |
BASE_PROTOS = $(shell find protos/ -iname "*.proto" | sed 's|^|/defs/|' | sort) |
| 36 |
BASE_PROTO_INCLUDES=-I/opt/include -I/googleapis -I/defs/protos |
| 37 |
|
| 38 |
PROTOS = $(shell find protos/ service-protos/ -iname "*.proto" | sed 's|^|/defs/|' | sort) |
| 39 |
PROTO_INCLUDES=${BASE_PROTO_INCLUDES} -I/defs/service-protos |
| 40 |
|
| 41 |
include protoc-builder/versions.mk |
| 42 |
|
| 43 |
# generate all language protobuf code |
| 44 |
all: go python typescript ruby rust |
| 45 |
|
| 46 |
# generate Go protobuf code |
| 47 |
# ignore service-protos, go clients should grab those from the service directly |
| 48 |
go: base-image-go |
| 49 |
@echo "Generating go proto Docker image" |
| 50 |
cd protoc-builder && ${DOCKER_BUILD} -t ${PROTOC_GO_IMAGE} -f Dockerfile.go . |
| 51 |
@echo "Generating go protobuf files" |
| 52 |
${DOCKER_RUN} -v ${PWD}:/defs ${PROTOC_GO_IMAGE} ${BASE_PROTO_INCLUDES}\ |
| 53 |
--go_opt=module=github.com/sigstore/protobuf-specs/gen/pb-go --go_out=/defs/gen/pb-go ${BASE_PROTOS} |
| 54 |
|
| 55 |
# an image on ghcr for generating defintions for sigstore services |
| 56 |
services-image: base-image-go |
| 57 |
@echo "Generating go proto base image" |
| 58 |
cd protoc-builder && ${DOCKER_BUILD} -t ${PROTOC_GO_IMAGE} -f Dockerfile.go . |
| 59 |
@echo "Generating services Docker image" |
| 60 |
# build from root directory so we can inject ./protos/ into the image |
| 61 |
${DOCKER_BUILD} -t ${PROTOC_SERVICES_IMAGE} --build-arg GO_BASE=${PROTOC_GO_IMAGE} -f protoc-builder/Dockerfile.services . |
| 62 |
|
| 63 |
python: base-image-python |
| 64 |
@echo "Generating python proto Docker image" |
| 65 |
cd protoc-builder && ${DOCKER_BUILD} -t ${PROTOC_PYTHON_IMAGE} -f Dockerfile.python . |
| 66 |
@echo "Generating python protobuf files" |
| 67 |
${DOCKER_RUN} -v ${PWD}:/defs ${PROTOC_PYTHON_IMAGE} ${PROTO_INCLUDES}\ |
| 68 |
--python_betterproto_opt=pydantic_dataclasses --python_betterproto_out=/defs/gen/pb-python/sigstore_protobuf_specs ${PROTOS} |
| 69 |
|
| 70 |
typescript: base-image-typescript |
| 71 |
@echo "Generating typescript proto Docker image" |
| 72 |
cd protoc-builder && ${DOCKER_BUILD} -t ${PROTOC_TYPESCRIPT_IMAGE} -f Dockerfile.typescript . |
| 73 |
@echo "Generating javascript protobuf files" |
| 74 |
${DOCKER_RUN} -v ${PWD}:/defs ${PROTOC_TYPESCRIPT_IMAGE} ${PROTO_INCLUDES}\ |
| 75 |
--ts_proto_out=/defs/gen/pb-typescript/src/__generated__ --ts_proto_opt=oneof=unions,forceLong=string,env=node,exportCommonSymbols=false,outputPartialMethods=false,outputEncodeMethods=false,unrecognizedEnum=false ${PROTOS} |
| 76 |
|
| 77 |
ruby: base-image-ruby |
| 78 |
@echo "Generating ruby proto Docker image" |
| 79 |
cd protoc-builder && ${DOCKER_BUILD} -t ${PROTOC_RUBY_IMAGE} -f Dockerfile.ruby . |
| 80 |
@echo "Generating ruby protobuf files" |
| 81 |
${DOCKER_RUN} -v ${PWD}:/defs ${PROTOC_RUBY_IMAGE} ${PROTO_INCLUDES}\ |
| 82 |
--ruby_out=/defs/gen/pb-ruby/lib ${PROTOS} |
| 83 |
|
| 84 |
rust: base-image-rust |
| 85 |
@echo "Generating rust proto Docker image" |
| 86 |
cd protoc-builder && ${DOCKER_BUILD} -t ${PROTOC_RUST_IMAGE} -f Dockerfile.rust . |
| 87 |
${DOCKER_RUN} -v ${PWD}:/defs \ |
| 88 |
-e "RUST_BACKTRACE=1" -e "CARGO_REGISTRY_TOKEN" ${PROTOC_RUST_IMAGE} \ |
| 89 |
-c "cd /defs/gen/pb-rust && cargo ${RUST_ACTION}" |
| 90 |
|
| 91 |
.PHONY: base-image-go |
| 92 |
base-image-go: |
| 93 |
@echo "Building base docker image for Go" |
| 94 |
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:go -f Dockerfile.protoc \ |
| 95 |
--build-arg PROTOC_VERSION=${GO_PROTOC_VERSION} \ |
| 96 |
--build-arg PROTOC_CHECKSUM=${GO_PROTOC_CHECKSUM} \ |
| 97 |
--build-arg GOOGLEAPIS_COMMIT=${GO_GOOGLEAPIS_COMMIT} \ |
| 98 |
--build-arg GRPC_GATEWAY_COMMIT=${GO_GRPC_GATEWAY_COMMIT} . |
| 99 |
|
| 100 |
.PHONY: base-image-python |
| 101 |
base-image-python: |
| 102 |
@echo "Building base docker image for Python" |
| 103 |
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:python -f Dockerfile.protoc \ |
| 104 |
--build-arg PROTOC_VERSION=${PYTHON_PROTOC_VERSION} \ |
| 105 |
--build-arg PROTOC_CHECKSUM=${PYTHON_PROTOC_CHECKSUM} \ |
| 106 |
--build-arg GOOGLEAPIS_COMMIT=${PYTHON_GOOGLEAPIS_COMMIT} \ |
| 107 |
--build-arg GRPC_GATEWAY_COMMIT=${PYTHON_GRPC_GATEWAY_COMMIT} . |
| 108 |
|
| 109 |
.PHONY: base-image-ruby |
| 110 |
base-image-ruby: |
| 111 |
@echo "Building base docker image for Ruby" |
| 112 |
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:ruby -f Dockerfile.protoc \ |
| 113 |
--build-arg PROTOC_VERSION=${RUBY_PROTOC_VERSION} \ |
| 114 |
--build-arg PROTOC_CHECKSUM=${RUBY_PROTOC_CHECKSUM} \ |
| 115 |
--build-arg GOOGLEAPIS_COMMIT=${RUBY_GOOGLEAPIS_COMMIT} \ |
| 116 |
--build-arg GRPC_GATEWAY_COMMIT=${RUBY_GRPC_GATEWAY_COMMIT} . |
| 117 |
|
| 118 |
.PHONY: base-image-rust |
| 119 |
base-image-rust: |
| 120 |
@echo "Building base docker image for Rust" |
| 121 |
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:rust -f Dockerfile.protoc \ |
| 122 |
--build-arg PROTOC_VERSION=${RUST_PROTOC_VERSION} \ |
| 123 |
--build-arg PROTOC_CHECKSUM=${RUST_PROTOC_CHECKSUM} \ |
| 124 |
--build-arg GOOGLEAPIS_COMMIT=${RUST_GOOGLEAPIS_COMMIT} \ |
| 125 |
--build-arg GRPC_GATEWAY_COMMIT=${RUST_GRPC_GATEWAY_COMMIT} . |
| 126 |
|
| 127 |
.PHONY: base-image-typescript |
| 128 |
base-image-typescript: |
| 129 |
@echo "Building base docker image for Typescript" |
| 130 |
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:typescript -f Dockerfile.protoc \ |
| 131 |
--build-arg PROTOC_VERSION=${TYPESCRIPT_PROTOC_VERSION} \ |
| 132 |
--build-arg PROTOC_CHECKSUM=${TYPESCRIPT_PROTOC_CHECKSUM} \ |
| 133 |
--build-arg GOOGLEAPIS_COMMIT=${TYPESCRIPT_GOOGLEAPIS_COMMIT} \ |
| 134 |
--build-arg GRPC_GATEWAY_COMMIT=${TYPESCRIPT_GRPC_GATEWAY_COMMIT} . |
| 135 |
|
| 136 |
# to recover from a situation where a stale layer exist, just purging the |
| 137 |
# docker image via `make clean` is not enough. Re-building without layer |
| 138 |
# cache is the only solution. |
| 139 |
.PHONY: base-image-no-cache |
| 140 |
base-image-no-cache: |
| 141 |
@echo "Building development docker images with disabled cache" |
| 142 |
@DOCKER_CACHE="--no-cache" make base-image-go |
| 143 |
@DOCKER_CACHE="--no-cache" make base-image-python |
| 144 |
@DOCKER_CACHE="--no-cache" make base-image-ruby |
| 145 |
@DOCKER_CACHE="--no-cache" make base-image-rust |
| 146 |
@DOCKER_CACHE="--no-cache" make base-image-typescript |
| 147 |
|
| 148 |
# clean up generated files (not working? try sudo make clean) |
| 149 |
clean: |
| 150 |
rm -rf gen/pb-go/* \ |
| 151 |
gen/pb-typescript/src/__generated__/* \ |
| 152 |
gen/pb-python/sigstore_protobuf_specs/dev \ |
| 153 |
gen/pb-python/sigstore_protobuf_specs/io \ |
| 154 |
gen/pb-rust/target |
| 155 |
find gen/pb-ruby/ -type f -name '*_pb.rb' -delete |
| 156 |
docker rmi -f ${PROTOC_IMAGE}:go ${PROTOC_GO_IMAGE} \ |
| 157 |
${PROTOC_IMAGE}:python ${PROTOC_PYTHON_IMAGE} \ |
| 158 |
${PROTOC_IMAGE}:ruby ${PROTOC_RUBY_IMAGE} \ |
| 159 |
${PROTOC_IMAGE}:rust ${PROTOC_RUST_IMAGE} \ |
| 160 |
${PROTOC_IMAGE}:typescript ${PROTOC_TYPESCRIPT_IMAGE} |