Skip to content

Commit 73e7c57

Browse files
committed
Upgrade protoc-gen-gorm to v0.20.4, add GHCR build workflow
Minimal change from v21.8: - Pin protoc-gen-gorm to v0.20.4 (v0.20.0 + deterministic composite primary key fix) - Pin protoc-gen-jsonschema in glide to avoid fetching incompatible latest version - Add GitHub Actions workflow to build and push to GHCR Keeps Go 1.17, glide, protoc 3.5.1, all other plugins unchanged.
1 parent 71a9ce5 commit 73e7c57

5 files changed

Lines changed: 279 additions & 97 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Push
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
branches: [fix/update-protoc-gen-gorm]
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Log in to GHCR
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ${{ env.REGISTRY }}
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Compute tags
33+
id: tags
34+
run: |
35+
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
36+
IMAGE_LC=$(echo "$IMAGE" | tr '[:upper:]' '[:lower:]')
37+
38+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
39+
TAG="${{ github.ref_name }}"
40+
TAGS="${IMAGE_LC}:${TAG},${IMAGE_LC}:latest"
41+
else
42+
TAGS="${IMAGE_LC}:${{ github.sha }}"
43+
fi
44+
45+
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
46+
47+
- name: Build and push
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.tags.outputs.tags }}
53+
provenance: false
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
56+
57+
- name: Test image
58+
if: success()
59+
run: |
60+
TAG=$(echo "${{ steps.tags.outputs.tags }}" | cut -d',' -f1)
61+
docker run --rm -v ${{ github.workspace }}:/go/src/github.com/infobloxopen/atlas-gentool \
62+
${TAG} \
63+
--go_out=plugins=grpc:. \
64+
--grpc-gateway_out=logtostderr=true:. \
65+
--validate_out="lang=go:." \
66+
--gorm_out=. \
67+
--atlas-query-validate_out=. \
68+
--atlas-validate_out=. \
69+
--preprocess_out=. \
70+
--swagger_out=:. \
71+
github.com/infobloxopen/atlas-gentool/testdata/test.proto
72+
test -e testdata/test.pb.go
73+
test -e testdata/test.pb.gw.go
74+
test -e testdata/test.pb.gorm.go
75+
echo "All tests passed"

Dockerfile

Lines changed: 106 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,129 @@
1-
# The docker image to generate Golang code from Protocol Buffers.
2-
FROM golang:1.21-alpine3.19 AS builder
1+
# The docker image to generate Golang code from Protol Buffer.
2+
FROM golang:1.17.0-alpine3.14 as builder
33
LABEL intermediate=true
4+
MAINTAINER DL NGP-App-Infra-API <ngp-app-infra-api@infoblox.com>
45

6+
ARG AAT_VERSION=master
7+
ARG PGG_VERSION=v0.20.4
8+
ARG PGAQV_VERSION=master
9+
ARG PGAV_VERSION=master
10+
ARG PGP_VERSION=master
11+
12+
# Set up mandatory Go environmental variables.
513
ENV CGO_ENABLED=0
6-
ENV GOPATH=/go
14+
ENV GO111MODULE=off
715

816
RUN apk update \
917
&& apk add --no-cache --purge git curl upx
1018

11-
# Clone all dependencies into GOPATH/src (replicating the old glide layout)
12-
# This ensures proto files end up in the right place for protoc -I paths.
13-
WORKDIR ${GOPATH}/src
14-
15-
# Standard proto / gogo
16-
RUN git clone --depth 1 --branch v1.3.1 https://github.com/golang/protobuf.git github.com/golang/protobuf && \
17-
git clone --depth 1 --branch v1.0.0 https://github.com/gogo/protobuf.git github.com/gogo/protobuf && \
18-
git clone --depth 1 https://github.com/google/protobuf.git github.com/google/protobuf
19-
20-
# grpc-gateway (upstream for protoc-gen-grpc-gateway)
21-
RUN git clone --depth 1 --branch v1.14.8 https://github.com/grpc-ecosystem/grpc-gateway.git github.com/grpc-ecosystem/grpc-gateway
22-
23-
# googleapis
24-
RUN git clone --depth 1 --branch master https://github.com/googleapis/googleapis.git github.com/googleapis/googleapis
25-
26-
# Validators
27-
RUN git clone --depth 1 --branch v0.1.0 https://github.com/envoyproxy/protoc-gen-validate.git github.com/envoyproxy/protoc-gen-validate && \
28-
git clone --depth 1 https://github.com/mwitkow/go-proto-validators.git github.com/mwitkow/go-proto-validators
29-
30-
# Documentation generator
31-
RUN git clone --depth 1 --branch v1.0.0 https://github.com/pseudomuto/protoc-gen-doc.git github.com/pseudomuto/protoc-gen-doc
32-
33-
# JSON schema generator
34-
RUN git clone --depth 1 https://github.com/chrusty/protoc-gen-jsonschema.git github.com/chrusty/protoc-gen-jsonschema
35-
36-
# Infoblox plugins
37-
RUN git clone --depth 1 --branch v0.20.3 https://github.com/infobloxopen/protoc-gen-gorm.git github.com/infobloxopen/protoc-gen-gorm && \
38-
git clone --depth 1 --branch v0.19.6 https://github.com/infobloxopen/atlas-app-toolkit.git github.com/infobloxopen/atlas-app-toolkit && \
39-
git clone --depth 1 --branch v0.5.1 https://github.com/infobloxopen/protoc-gen-atlas-query-validate.git github.com/infobloxopen/protoc-gen-atlas-query-validate && \
40-
git clone --depth 1 --branch v0.4.1 https://github.com/infobloxopen/protoc-gen-atlas-validate.git github.com/infobloxopen/protoc-gen-atlas-validate && \
41-
git clone --depth 1 --branch v0.3.3 https://github.com/infobloxopen/protoc-gen-preprocess.git github.com/infobloxopen/protoc-gen-preprocess
42-
43-
# gorm / inflection (runtime deps for protoc-gen-gorm)
44-
RUN git clone --depth 1 --branch v1.9.1 https://github.com/jinzhu/gorm.git github.com/jinzhu/gorm && \
45-
git clone --depth 1 https://github.com/jinzhu/inflection.git github.com/jinzhu/inflection
46-
47-
# Misc deps needed by the above
48-
RUN git clone --depth 1 https://github.com/ghodss/yaml.git github.com/ghodss/yaml && \
49-
git clone --depth 1 https://github.com/go-openapi/spec.git github.com/go-openapi/spec && \
50-
git clone --depth 1 https://github.com/golang/glog.git github.com/golang/glog
51-
52-
# Build all protoc plugins in GOPATH mode
53-
ENV GO111MODULE=off
54-
55-
RUN go install github.com/golang/protobuf/protoc-gen-go && \
56-
go install github.com/gogo/protobuf/protoc-gen-combo && \
57-
go install github.com/gogo/protobuf/protoc-gen-gofast && \
58-
go install github.com/gogo/protobuf/protoc-gen-gogo && \
59-
go install github.com/gogo/protobuf/protoc-gen-gogofast && \
60-
go install github.com/gogo/protobuf/protoc-gen-gogofaster && \
61-
go install github.com/gogo/protobuf/protoc-gen-gogoslick && \
62-
go install github.com/gogo/protobuf/protoc-gen-gogotypes && \
63-
go install github.com/gogo/protobuf/protoc-gen-gostring && \
64-
go install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema && \
65-
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway && \
66-
go install github.com/envoyproxy/protoc-gen-validate && \
67-
go install github.com/mwitkow/go-proto-validators/protoc-gen-govalidators && \
68-
go install github.com/pseudomuto/protoc-gen-doc/cmd/... && \
69-
go install github.com/infobloxopen/protoc-gen-preprocess && \
70-
go install github.com/infobloxopen/protoc-gen-gorm
71-
72-
# These two use dep for their own deps
73-
RUN cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-query-validate && \
74-
go install . && \
75-
cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-validate && \
76-
go install .
77-
78-
# Build protoc-gen-swagger with atlas_patch fork
79-
RUN rm -rf ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
80-
git clone --single-branch -b atlas-patch https://github.com/infobloxopen/grpc-gateway.git \
81-
${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
82-
cd ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger && \
83-
go build -o ${GOPATH}/bin/protoc-gen-swagger .
84-
85-
RUN mkdir -p /out/usr/bin && \
86-
install -c ${GOPATH}/bin/protoc-gen* /out/usr/bin/
87-
88-
# Collect proto files
89-
RUN mkdir -p /out/go/src && \
90-
find ${GOPATH}/src -name "*.proto" -exec cp --parents {} /out/ \;
91-
92-
RUN upx --lzma /out/usr/bin/protoc-gen-*
93-
94-
FROM alpine:3.19
19+
# The version and the binaries checksum for the glide package manager.
20+
ENV GLIDE_VERSION 0.12.3
21+
ENV GLIDE_DOWNLOAD_URL https://github.com/Masterminds/glide/releases/download/v${GLIDE_VERSION}/glide-v${GLIDE_VERSION}-linux-amd64.tar.gz
22+
ENV GLIDE_DOWNLOAD_SHA256 0e2be5e863464610ebc420443ccfab15cdfdf1c4ab63b5eb25d1216900a75109
23+
24+
# Download and install the glide package manager.
25+
RUN curl -fsSL ${GLIDE_DOWNLOAD_URL} -o glide.tar.gz \
26+
&& echo "${GLIDE_DOWNLOAD_SHA256} glide.tar.gz" | sha256sum -c - \
27+
&& tar -xzf glide.tar.gz --strip-components=1 -C /usr/local/bin \
28+
&& rm -rf glide.tar.gz
29+
30+
# Download and install dep.
31+
ENV INSTALL_DIRECTORY /usr/local/bin
32+
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
33+
34+
# Install as the protoc plugins as build-time dependecies.
35+
COPY glide.yaml.tmpl .
36+
37+
# glide is unable to resolve correctly these deps requiring
38+
# to import all the dependencies in ghodss/yaml
39+
RUN go get github.com/ghodss/yaml
40+
41+
# Compile binaries for the protocol buffer plugins. We need specific
42+
# versions of these tools, this is why we at first step install glide,
43+
# download required versions and then installing them.
44+
RUN sed -e "s/@AATVersion/$AAT_VERSION/" \
45+
-e "s/@PGGVersion/$PGG_VERSION/" \
46+
-e "s/@PGAQVVersion/$PGAQV_VERSION/" \
47+
-e "s/@PGAVVersion/$PGAV_VERSION/" \
48+
-e "s/@PGPVersion/$PGP_VERSION/" \
49+
glide.yaml.tmpl > glide.yaml
50+
RUN glide up --skip-test
51+
RUN cp -r vendor/* ${GOPATH}/src/
52+
53+
RUN go install github.com/golang/protobuf/protoc-gen-go
54+
RUN go install github.com/gogo/protobuf/protoc-gen-combo
55+
RUN go install github.com/gogo/protobuf/protoc-gen-gofast
56+
RUN go install github.com/gogo/protobuf/protoc-gen-gogo
57+
RUN go install github.com/gogo/protobuf/protoc-gen-gogofast
58+
RUN go install github.com/gogo/protobuf/protoc-gen-gogofaster
59+
RUN go install github.com/gogo/protobuf/protoc-gen-gogoslick
60+
RUN go install github.com/gogo/protobuf/protoc-gen-gogotypes
61+
RUN go install github.com/gogo/protobuf/protoc-gen-gostring
62+
# Pin logrus to Go 1.17 compatible version before go get pulls latest
63+
RUN rm -rf ${GOPATH}/src/github.com/sirupsen/logrus && \
64+
git clone --depth 1 --branch v1.9.3 https://github.com/sirupsen/logrus.git ${GOPATH}/src/github.com/sirupsen/logrus
65+
RUN go get github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema
66+
RUN go install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema
67+
RUN go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
68+
RUN go install github.com/envoyproxy/protoc-gen-validate
69+
RUN go install github.com/mwitkow/go-proto-validators/protoc-gen-govalidators
70+
RUN go install github.com/pseudomuto/protoc-gen-doc/cmd/...
71+
RUN go install github.com/infobloxopen/protoc-gen-preprocess
72+
RUN go install \
73+
-ldflags "-X github.com/infobloxopen/protoc-gen-gorm/plugin.ProtocGenGormVersion=$PGG_VERSION -X github.com/infobloxopen/protoc-gen-gorm/plugin.AtlasAppToolkitVersion=$AAT_VERSION" \
74+
github.com/infobloxopen/protoc-gen-gorm
75+
# Download all dependencies of protoc-gen-atlas-query-validate
76+
RUN cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-query-validate && dep ensure -vendor-only
77+
RUN go install github.com/infobloxopen/protoc-gen-atlas-query-validate
78+
79+
# Download all dependencies of protoc-gen-atlas-validate
80+
RUN cd ${GOPATH}/src/github.com/infobloxopen/protoc-gen-atlas-validate && dep ensure -vendor-only
81+
RUN go install github.com/infobloxopen/protoc-gen-atlas-validate
82+
83+
RUN mkdir -p /out/usr/bin
84+
85+
RUN rm -rf vendor/* ${GOPATH}/pkg/* \
86+
&& install -c ${GOPATH}/bin/protoc-gen* /out/usr/bin/
87+
88+
# build protoc-gen-swagger separately with atlas_patch
89+
RUN go get github.com/go-openapi/spec && \
90+
rm -rf ${GOPATH}/src/github.com/grpc-ecosystem/ \
91+
&& mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/ && \
92+
cd ${GOPATH}/src/github.com/grpc-ecosystem && \
93+
git clone --single-branch -b atlas-patch https://github.com/infobloxopen/grpc-gateway.git && \
94+
cd grpc-gateway/protoc-gen-swagger && go build -o /out/usr/bin/protoc-gen-swagger main.go
95+
96+
RUN mkdir -p /out/protos && \
97+
find ${GOPATH}/src -name "*.proto" -exec cp --parents {} /out/protos \;
98+
99+
RUN upx --lzma \
100+
/out/usr/bin/protoc-gen-*
101+
102+
FROM alpine:3.8
95103
RUN apk add --no-cache libstdc++ protobuf-dev
96104
COPY --from=builder /out/usr /usr
97-
COPY --from=builder /out/go/src /go/src
105+
COPY --from=builder /out/protos /
98106

99107
WORKDIR /go/src
100108

109+
# protoc as an entry point for all plugins with import paths set
101110
ENTRYPOINT ["protoc", "-I.", \
111+
# required import paths for protoc-gen-grpc-gateway plugin
102112
"-Igithub.com/grpc-ecosystem/grpc-gateway/third_party/googleapis", \
113+
# required import paths for protoc-gen-swagger plugin
103114
"-Igithub.com/grpc-ecosystem/grpc-gateway", "-Igithub.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options", \
115+
# required import paths for protoc-gen-validate plugin
104116
"-Igithub.com/envoyproxy/protoc-gen-validate/validate", \
117+
# required import paths for go-proto-validators plugin
105118
"-Igithub.com/mwitkow/go-proto-validators", \
119+
# googleapis proto files
106120
"-Igithub.com/googleapis/googleapis", \
121+
# required import paths for protoc-gen-gorm plugin
107122
"-Igithub.com/infobloxopen/protoc-gen-gorm", \
123+
# required import paths for protoc-gen-atlas-query-validate plugin
108124
"-Igithub.com/infobloxopen/protoc-gen-atlas-query-validate", \
125+
# required import paths for protoc-gen-preprocess plugin
109126
"-Igithub.com/infobloxopen/protoc-gen-preprocess", \
127+
# required import paths for protoc-gen-atlas-validate plugin
110128
"-Igithub.com/infobloxopen/protoc-gen-atlas-validate" \
111129
]

Makefile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,48 @@
22
# https://github.com/infobloxopen/atlas-gentool
33
IMAGE_NAME := infoblox/atlas-gentool
44

5-
SRCROOT_ON_HOST := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
6-
SRCROOT_IN_CONTAINER := /go/src/github.com/infobloxopen/atlas-gentool
7-
IMAGE_VERSION ?= $(shell git tag --points-at HEAD | sort -n -r | head -1)
5+
GO_PATH := /go
6+
SRCROOT_ON_HOST := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
7+
SRCROOT_IN_CONTAINER := $(GO_PATH)/src/github.com/infobloxopen/atlas-gentool
8+
IMAGE_VERSION ?= $(shell git tag --points-at HEAD | sort -n -r | head -1)
9+
10+
get_version = sed -n 's/^$(1)=//p' plugin.version
11+
12+
AATVersion ?= $(shell $(call get_version,atlas-app-toolkit))
13+
PGGVersion ?= $(shell $(call get_version,protoc-gen-gorm))
14+
PGAQVVersion ?= $(shell $(call get_version,protoc-gen-atlas-query-validate))
15+
PGAVVersion ?= $(shell $(call get_version,protoc-gen-atlas-validate))
16+
PGPVersion ?= $(shell $(call get_version,protoc-gen-preprocess))
817

918
.PHONY: all
10-
all: build
19+
all: latest
1120

12-
.PHONY: build
13-
build:
21+
# Create the Docker image with the latest tag.
22+
.PHONY: latest
23+
latest:
1424
docker build -f Dockerfile -t $(IMAGE_NAME):latest .
1525

1626
.PHONY: versioned
1727
versioned:
18-
docker build -f Dockerfile -t $(IMAGE_NAME):$(IMAGE_VERSION) .
28+
docker build -f Dockerfile \
29+
--build-arg AAT_VERSION=$(AATVersion) \
30+
--build-arg PGG_VERSION=$(PGGVersion) \
31+
--build-arg PGAQV_VERSION=$(PGAQVVersion) \
32+
--build-arg PGAV_VERSION=$(PGAVVersion) \
33+
--build-arg PGP_VERSION=$(PGPVersion) \
34+
-t $(IMAGE_NAME):$(IMAGE_VERSION) .
1935

2036
.PHONY: clean
2137
clean:
2238
docker rmi -f $(IMAGE_NAME)
39+
docker rmi `docker images --filter "label=intermediate=true" -q`
2340

2441
.PHONY: test test-gen test-check test-clean
2542
test: test-gen test-check test-clean
2643

2744
test-gen:
2845
docker run --rm -v $(SRCROOT_ON_HOST):$(SRCROOT_IN_CONTAINER) \
29-
$(IMAGE_NAME):latest \
46+
infoblox/atlas-gentool:$(IMAGE_VERSION) \
3047
--go_out=plugins=grpc:. \
3148
--grpc-gateway_out=logtostderr=true:. \
3249
--validate_out="lang=go:." \

0 commit comments

Comments
 (0)