Skip to content

Commit 683e34a

Browse files
author
jackie muzakki
committed
Merge remote-tracking branch 'origin/master' into pr-134
2 parents 04a2171 + d8d6b95 commit 683e34a

73 files changed

Lines changed: 3481 additions & 1507 deletions

Some content is hidden

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

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
assets
2+
.git
3+
.github
4+
*.pb.go

.github/workflows/integration-test.yml

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,57 @@ on:
44
branches:
55
master
66

7-
87
jobs:
98
build:
109
name: Run example
1110
runs-on: ubuntu-latest
1211
steps:
1312
- name: Checkout
1413
uses: actions/checkout@master
14+
15+
- name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v3
17+
18+
- name: Login to GitHub Container Registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Build and cache
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
push: false
30+
load: true
31+
tags: gripmock:test
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max
34+
1535
- name: Run Simple Example
16-
uses: ./
17-
with:
18-
entrypoint: example/simple/entrypoint.sh
19-
args: simple
36+
run: docker run --rm --entrypoint example/simple/entrypoint.sh gripmock:test
37+
38+
- name: Run Advanced Example
39+
run: docker run --rm --entrypoint example/advanced/entrypoint.sh gripmock:test
40+
2041
- name: Run Stream Example
21-
uses: ./
22-
with:
23-
entrypoint: example/stream/entrypoint.sh
24-
args: stream
42+
run: docker run --rm --entrypoint example/stream/entrypoint.sh gripmock:test
43+
2544
- name: Run WKT Example
26-
uses: ./
27-
with:
28-
entrypoint: example/well_known_types/entrypoint.sh
45+
run: docker run --rm --entrypoint example/well_known_types/entrypoint.sh gripmock:test
46+
2947
- name: Run Multi Package Example
30-
uses: ./
31-
with:
32-
entrypoint: example/multi-package/entrypoint.sh
48+
run: docker run --rm --entrypoint example/multi-package/entrypoint.sh gripmock:test
49+
3350
- name: Run Multi Files Example
34-
uses: ./
35-
with:
36-
entrypoint: example/multi-files/entrypoint.sh
51+
run: docker run --rm --entrypoint example/multi-files/entrypoint.sh gripmock:test
52+
3753
- name: Run one-of Example
38-
uses: ./
39-
with:
40-
entrypoint: example/one-of/entrypoint.sh
54+
run: docker run --rm --entrypoint example/one-of/entrypoint.sh gripmock:test
55+
4156
- name: Run stub subfolders example
42-
uses: ./
43-
with:
44-
entrypoint: example/stub-subfolders/entrypoint.sh
57+
run: docker run --rm --entrypoint example/stub-subfolders/entrypoint.sh gripmock:test
4558
- name: Run gzip example
4659
uses: ./
4760
with:

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pkged.go
22
gripmock
33
.idea
4+
.cursor
45
.DS_Store
5-
protogen/*
6-
!protogen/go.mod
7-
!protogen/example/
8-
temp
6+
temp
7+
8+
# protogen/example/ is not ignored for the sake of go mod tidy

Dockerfile

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
FROM golang:alpine
1+
FROM golang:1.23-alpine
22

3-
RUN mkdir /proto
4-
5-
RUN mkdir /stubs
6-
7-
RUN apk -U --no-cache add git protobuf bash
8-
9-
RUN go install -v github.com/golang/protobuf/protoc-gen-go@latest
10-
11-
RUN go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
12-
13-
RUN go install github.com/markbates/pkger/cmd/pkger@latest
3+
# install tools (bash, git, protobuf, protoc-gen-go, protoc-grn-go-grpc, pkger)
4+
RUN apk -U --no-cache add bash git protobuf &&\
5+
go install -v github.com/golang/protobuf/protoc-gen-go@latest &&\
6+
go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0 &&\
7+
go install github.com/markbates/pkger/cmd/pkger@latest
148

159
# cloning well-known-types
16-
RUN git clone --depth=1 https://github.com/google/protobuf.git /protobuf-repo
17-
18-
RUN mkdir protobuf
19-
2010
# only use needed files
21-
RUN mv /protobuf-repo/src/ /protobuf/
22-
23-
RUN rm -rf /protobuf-repo
24-
25-
RUN mkdir -p /go/src/github.com/tokopedia/gripmock
11+
RUN git clone --depth=1 https://github.com/google/protobuf.git /protobuf-repo &&\
12+
mv /protobuf-repo/src/ /protobuf/ &&\
13+
rm -rf /protobuf-repo
2614

2715
COPY . /go/src/github.com/tokopedia/gripmock
2816

29-
RUN ln -s /go/src/github.com/tokopedia/gripmock/fix_gopackage.sh /bin/
17+
# create necessary dirs and export scripts
18+
RUN mkdir -p /proto /stubs /protogen &&\
19+
chmod +x /go/src/github.com/tokopedia/gripmock/scripts/*.sh &&\
20+
ln -s /go/src/github.com/tokopedia/gripmock/scripts/fix_gopackage.sh /bin/ &&\
21+
ln -s /go/src/github.com/tokopedia/gripmock/scripts/start_server.sh /bin/ &&\
22+
ln -s /go/src/github.com/tokopedia/gripmock/scripts/wait_for_gripmock.sh /bin/
3023

31-
WORKDIR /go/src/github.com/tokopedia/gripmock/protoc-gen-gripmock
24+
# Copy server.go and go.mod to /go/src/grpc
25+
# to build go module
26+
RUN mkdir -p /go/src/grpc &&\
27+
cp /go/src/github.com/tokopedia/gripmock/scripts/server/server.go /go/src/grpc/ &&\
28+
cp /go/src/github.com/tokopedia/gripmock/scripts/server/go.mod /go/src/grpc/
3229

33-
RUN pkger
30+
# install plugin protoc-gen-go-grpc
31+
WORKDIR /go/src/github.com/tokopedia/gripmock/protoc-gen-gripmock
3432

3533
# install generator plugin
36-
RUN go install -v
34+
RUN rm -f pkged.go && pkger && go install -v
3735

3836
WORKDIR /go/src/github.com/tokopedia/gripmock
3937

4038
# install gripmock
4139
RUN go install -v
4240

43-
# to cache necessary imports
44-
RUN go build ./example/simple/client
41+
# cache the dependencies then clean up
42+
RUN ./scripts/setup_examples.sh && \
43+
go build example/simple/client/*.go && \
44+
find . -name "*.pb.go" -type f -delete
4545

46-
# remove all .pb.go generated files
47-
# since generating go file is part of the test
48-
RUN find . -name "*.pb.go" -delete -type f
46+
# run server for caching purposes
47+
RUN start_server.sh
4948

5049
EXPOSE 4770 4771
5150

5251
ENTRYPOINT ["gripmock"]
52+
CMD ["--help"]

Makefile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Gripmock Makefile
2+
3+
# Variables
4+
BINARY_NAME=gripmock
5+
DOCKER_IMAGE=tkpd/gripmock
6+
PLATFORMS=linux/amd64,linux/arm64
7+
GOPATH:=$(shell go env GOPATH)
8+
9+
# Include test makefile
10+
include Makefile.test
11+
12+
.PHONY: all build clean test push help
13+
14+
# Default target
15+
all: build
16+
17+
# Build the Go binary
18+
build:
19+
@echo "Building Go binary..."
20+
go build -o $(BINARY_NAME) .
21+
22+
# Build Docker image
23+
docker-build:
24+
@if [ "$(VERSION)" = "" ]; then \
25+
echo "Error: VERSION is required. Usage: make docker-build VERSION=x.y.z"; \
26+
exit 1; \
27+
fi
28+
@echo "Building Docker image..."
29+
docker buildx build --load -t $(DOCKER_IMAGE):$(VERSION) --platform linux/amd64 .
30+
31+
# Push Docker image
32+
docker-push:
33+
@if [ "$(VERSION)" = "" ]; then \
34+
echo "Error: VERSION is required. Usage: make docker-push VERSION=x.y.z"; \
35+
exit 1; \
36+
fi
37+
@echo "Pushing Docker image..."
38+
docker buildx build --push -t $(DOCKER_IMAGE):$(VERSION) --platform $(PLATFORMS) .
39+
40+
# Run tests
41+
test:
42+
@echo "Running tests..."
43+
go test -v ./...
44+
45+
# Clean build artifacts
46+
clean:
47+
@echo "Cleaning..."
48+
rm -f $(BINARY_NAME)
49+
go clean
50+
docker rm -f gripmock-test || true
51+
52+
# Show help
53+
help:
54+
@echo "Available targets:"
55+
@echo " all - Build the project (default)"
56+
@echo " build - Build the Go binary"
57+
@echo " docker-build - Build Docker image (requires VERSION=x.y.z)"
58+
@echo " docker-push - Push Docker image (requires VERSION=x.y.z)"
59+
@echo " test - Run tests"
60+
@echo " clean - Clean build artifacts"
61+
@echo " help - Show this help message"
62+
@echo ""
63+
@echo "Test targets:"
64+
@echo " test-all - Run all test examples"
65+
@echo " test-simple - Run simple example test"
66+
@echo " test-advanced - Run advanced example test"
67+
@echo " test-well-known-types - Run well-known types example test"
68+
@echo " test-stub-subfolders - Run stub subfolders example test"
69+
@echo " test-stream - Run stream example test"
70+
@echo " test-one-of - Run one-of example test"
71+
@echo " test-multi-package - Run multi-package example test"
72+
@echo " test-multi-files - Run multi-files example test"
73+
@echo " build-test-image - Build test Docker image"

0 commit comments

Comments
 (0)