Skip to content

Commit e75c08a

Browse files
authored
Merge pull request #2 from pquerna/pq/iterate
[WIP] Iteration to get functional protobuf generation
2 parents 4c59eab + 29100f5 commit e75c08a

File tree

302 files changed

+509283
-33390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+509283
-33390
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

.gitignore

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/build
2+
13
# If you prefer the allow list template instead of the deny list, see community template:
24
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
35
#
@@ -21,14 +23,3 @@
2123
go.work
2224

2325

24-
## Project
25-
# Ignore ocsf-tool directory
26-
ocsf-tool
27-
28-
# Ignore schema directory
29-
schema
30-
31-
# Ignore proto directory
32-
proto
33-
34-
schema.json

Makefile

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,22 @@
1+
.PHONY: build
2+
build:
13

2-
# prepare system for build
3-
prepare:
4-
@echo "Preparing system for build..."
4+
PROTOC_IMAGE=ocsf-schema-golang-protoc
5+
PROTOC_VERSION=0.1.2
56

6-
sudo apt-get update
7+
protocontainer:
8+
docker build --load -t $(PROTOC_IMAGE):$(PROTOC_VERSION) -f dev/protoc/protoc.Dockerfile dev/protoc/
79

8-
# install protobuf-compiler
9-
sudo apt-get install -y protobuf-compiler
10-
export PATH="$PATH:$(go env GOPATH)/bin"
11-
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
12-
protoc --version
10+
generate-proto: protocontainer
11+
docker run --rm \
12+
--mount type=bind,source="$(PWD)",target=/build \
13+
$(PROTOC_IMAGE):$(PROTOC_VERSION) \
14+
generate-proto.sh
1315

14-
# install jq
15-
sudo apt-get install -y jq
16+
generate-go: protocontainer
17+
docker run --rm \
18+
--mount type=bind,source="$(PWD)",target=/build \
19+
$(PROTOC_IMAGE):$(PROTOC_VERSION) \
20+
generate-go.sh
1621

17-
# install ocsf-tool
18-
make install-ocsf-tool
19-
20-
# install buf
21-
make install-buf
22-
23-
@echo "System is ready for build."
24-
25-
# install homebrew
26-
install-homebrew:
27-
@echo "Installing homebrew..."
28-
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
29-
30-
install-buf: install-homebrew
31-
@echo "Installing buf..."
32-
/home/linuxbrew/.linuxbrew/bin/brew install bufbuild/buf/buf
33-
34-
# install ocsf-tool
35-
install-ocsf-tool:
36-
@echo "Installing latest version of ocsf-tool..."
37-
curl -sfL https://raw.githubusercontent.com/valllabh/ocsf-tool/main/download/download.sh | bash
38-
39-
create-proto-files:
40-
@echo "Getting event list..."
41-
./ocsf-tool/ocsf-tool schema-class-list --output ./schema/schema-class-list.json
42-
43-
@echo "Creating proto files..."
44-
jq -r "[.[] | to_entries[] | .value] | join(\" \")" ./schema/schema-class-list.json | xargs ./ocsf-tool/ocsf-tool generate-proto --golang-root-package / --proto-output ./proto
45-
46-
compile-proto: clean-output
47-
@echo "Compiling proto files..."
48-
/home/linuxbrew/.linuxbrew/bin/buf generate
49-
50-
@echo "Preparing Enum Value Map..."
51-
bash ./enum-value/enum-value-map.sh
52-
53-
clean-output:
54-
@echo "Cleaning output directory..."
55-
rm -rf ./ocsf
56-
57-
generate-documentation:
58-
gomarkdoc ./ >> docs.md
59-
60-
build: create-proto-files compile-proto
61-
@echo "Building Finished."
22+
generate: generate-proto generate-go

build/.keep

Whitespace-only changes.

config.yaml renamed to dev/protoc/config-v1.0.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
extensions:
23
discovery:
34
paths: # no external extensions required
@@ -11,7 +12,7 @@ schema:
1112
branch:
1213
name: v1.0.0
1314
directory:
14-
path: $CWD/schema/git
15+
path: $CWD/build/schema-git
1516
url: https://github.com/ocsf/ocsf-schema
1617
strategy: repository
17-
path: $CWD/schema
18+
path: $CWD/schema

dev/protoc/config-v1.1.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
extensions:
3+
discovery:
4+
paths: # no external extensions required
5+
selected: [] # blank to load all default extensions
6+
profiles:
7+
selected: [] # blank to load all default profiles
8+
schema:
9+
loading:
10+
strategies:
11+
repository:
12+
branch:
13+
name: v1.1.0
14+
directory:
15+
path: $CWD/build/schema-git
16+
url: https://github.com/ocsf/ocsf-schema
17+
strategy: repository
18+
path: $CWD/schema

dev/protoc/config-v1.2.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
extensions:
3+
discovery:
4+
paths: # no external extensions required
5+
selected: [] # blank to load all default extensions
6+
profiles:
7+
selected: [] # blank to load all default profiles
8+
schema:
9+
loading:
10+
strategies:
11+
repository:
12+
branch:
13+
name: v1.2.0
14+
directory:
15+
path: $CWD/build/schema-git
16+
url: https://github.com/ocsf/ocsf-schema
17+
strategy: repository
18+
path: $CWD/schema

dev/protoc/generate-go.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec /usr/local/bin/buf generate

dev/protoc/generate-proto.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
verions=("v1.0" "v1.1" "v1.2")
6+
for i in "${verions[@]}"
7+
do
8+
config_file="/configs/config-${i}.yaml"
9+
echo "${i}: Getting event list..."
10+
ocsf-tool schema-class-list --config "${config_file}" --output "./schema/tmp.json"
11+
12+
jq . "./schema/tmp.json" > "./schema/${i}-schema-class-list.json"
13+
rm -f ./schema/tmp.json
14+
15+
echo "${i}: Creating proto files..."
16+
jq -r "[.[] | to_entries[] | .value] | join(\" \")" "./schema/${i}-schema-class-list.json" | xargs ocsf-tool generate-proto --config "${config_file}" --golang-root-package / --proto-output ./proto
17+
18+
jq . schema.json > "schema/${i}-schema.json"
19+
rm -f schema.json
20+
echo "${i}: done"
21+
done
22+

dev/protoc/protoc.Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM golang:1.22-bookworm as build
2+
3+
FROM build as build-go
4+
# https://github.com/protocolbuffers/protobuf-go/releases
5+
ARG PROTOC_GEN_GO_VERSION=1.34.1
6+
ARG PROTOC_GEN_GO_HASH="8aff9ec0c28a926daeedb1ce1f87a284e22fc5a892e9e5f7c850881137c85000"
7+
8+
9+
RUN mkdir /xsrc && cd /xsrc && \
10+
curl -fLO https://github.com/protocolbuffers/protobuf-go/archive/refs/tags/v${PROTOC_GEN_GO_VERSION}.tar.gz && \
11+
echo "${PROTOC_GEN_GO_HASH} v${PROTOC_GEN_GO_VERSION}.tar.gz" | sha256sum -c - && \
12+
tar -xzf v${PROTOC_GEN_GO_VERSION}.tar.gz && \
13+
cd protobuf-go-${PROTOC_GEN_GO_VERSION}/cmd/protoc-gen-go && \
14+
go install -v . && \
15+
cd / && \
16+
rm -rf "/xsrc"
17+
18+
FROM build as build-ocsf-tool
19+
20+
ARG OCSF_TOOL_REPO=https://github.com/pquerna/ocsf-tool.git
21+
ARG OCSF_TOOL_COMMIT=ac25244eef1d5843933a670dc0c3ce181b3faafe
22+
23+
RUN mkdir /xsrc && cd /xsrc && \
24+
git clone ${OCSF_TOOL_REPO} && \
25+
cd ocsf-tool && \
26+
git checkout ${OCSF_TOOL_COMMIT} && \
27+
go install -v . && \
28+
cd / && \
29+
rm -rf "/xsrc"
30+
31+
# https://github.com/bufbuild/buf/releases
32+
FROM bufbuild/buf:1.31.0 as buf
33+
34+
FROM debian:bookworm as final
35+
36+
RUN mkdir /build && apt-get -y update && apt-get -y install \
37+
protobuf-compiler \
38+
jq \
39+
ca-certificates \
40+
rsync
41+
42+
COPY --from=buf /usr/local/bin/buf /usr/local/bin
43+
COPY --from=build-go /go/bin/protoc-gen-go /usr/local/bin
44+
COPY --from=build-ocsf-tool /go/bin/ocsf-tool /usr/local/bin
45+
COPY ./generate-proto.sh /usr/local/bin/generate-proto.sh
46+
COPY ./generate-go.sh /usr/local/bin/generate-go.sh
47+
COPY ./config-v*.yaml /configs/
48+
49+
WORKDIR /build

0 commit comments

Comments
 (0)