-
Notifications
You must be signed in to change notification settings - Fork 29
/
Makefile
103 lines (89 loc) · 3.69 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
# Copyright 2022 The Sigstore Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PROTOC_IMAGE = protobuf-specs-build
JSONSCHEMA_IMAGE = jsonschema-specs-build
RUST_ACTION ?= run -p sigstore-protobuf-specs-codegen
# generate all language protobuf code
all: go python typescript ruby jsonschema rust
# generate Go protobuf code
go: docker-image
@echo "Generating go protobuf files"
docker run --platform linux/amd64 -v ${PWD}:/defs ${PROTOC_IMAGE} -d protos -l go --go-module-prefix github.com/sigstore/protobuf-specs/gen/pb-go
python: docker-image
@echo "Generating python protobuf files"
# we need to manually fix the PYTHONPATH due to: https://github.com/namely/docker-protoc/pull/356
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
-e PYTHONPATH="/opt/mypy-protobuf/" \
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd ./gen/pb-python/sigstore_protobuf_specs && protoc -I/opt/include -I../../../protos/ --python_betterproto_out=. ../../../protos/*.proto"
typescript: docker-image
@echo "Generating javascript protobuf files"
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
${PROTOC_IMAGE} \
-d protos -l typescript -o ./gen/pb-typescript/src/__generated__ --ts_opt oneof=unions,forceLong=string,env=node,exportCommonSymbols=false,outputPartialMethods=false,outputEncodeMethods=false,unrecognizedEnum=false
ruby: docker-image
@echo "Generating ruby protobuf files"
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd ./gen/pb-ruby && protoc -I/opt/include -I../../protos/ --ruby_out=lib ../../protos/*.proto"
jsonschema: docker-image-jsonschema
@echo "Generating JSON schema files"
mkdir -p gen/jsonschema/schemas
docker run \
-v ${PWD}:/defs \
--entrypoint sh \
${JSONSCHEMA_IMAGE} \
-c "cd defs/gen/jsonschema && ./jsonschema.sh -I ../../protos -I /googleapis/ --jsonschema_out=schemas ../../protos/*.proto"
rust: docker-image
docker run \
--platform linux/amd64 \
-v ${PWD}:/defs \
-e "RUST_BACKTRACE=1" \
-e "CARGO_REGISTRY_TOKEN" \
--entrypoint bash ${PROTOC_IMAGE} \
-c "cd gen/pb-rust && cargo ${RUST_ACTION}"
# docker already does its own caching so we can attempt a build every time
.PHONY: docker-image
docker-image:
@echo "Building development docker image"
docker build -t ${PROTOC_IMAGE} .
# to recover from a situation where a stale layer exist, just purging the
# docker image via `make clean` is not enough. Re-building without layer
# cache is the only solution.
.PHONY: docker-image-no-cache
docker-image-no-cache:
@echo "Building development docker image with disabled cache"
docker build --no-cache -t ${PROTOC_IMAGE} .
.PHONY: docker-image-jsonschema
docker-image-jsonschema:
@echo "Building docker image for generating JSON schema files"
docker build -t ${JSONSCHEMA_IMAGE} -f Dockerfile.jsonschema .
# clean up generated files (not working? try sudo make clean)
clean:
rm -rf gen/pb-go \
gen/pb-typescript/src/__generated__ \
gen/pb-python/sigstore_protobuf_specs/dev \
gen/pb-python/sigstore_protobuf_specs/io \
gen/pb-rust/target \
gen/jsonschema/schemas
docker rmi -f ${PROTOC_IMAGE}
help:
docker run --pull always --platform linux/amd64 -v ${PWD}:/defs ${PROTOC_IMAGE}