Skip to content

Commit 56e109e

Browse files
authored
grpc service (#82)
1 parent 9d82af9 commit 56e109e

31 files changed

+3347
-127
lines changed

.github/release-drafter.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
4+
template: |
5+
## General Changes
6+
7+
$CHANGES
8+
9+
categories:
10+
- title: '🚀 Features'
11+
labels:
12+
- 'feature'
13+
- 'enhancement'
14+
- title: '🐛 Bug Fixes'
15+
labels:
16+
- 'fix'
17+
- 'bugfix'
18+
- 'bug'
19+
20+
version-resolver:
21+
major:
22+
labels:
23+
- 'major'
24+
minor:
25+
labels:
26+
- 'minor'
27+
patch:
28+
labels:
29+
- 'patch'
30+
default: patch

.github/workflows/docker.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Docker Build Action
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
release:
7+
types:
8+
- published
9+
push:
10+
branches:
11+
- master
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
19+
build:
20+
name: Build
21+
runs-on: ubuntu-latest
22+
steps:
23+
24+
- name: Set up Go 1.18
25+
uses: actions/setup-go@v2
26+
with:
27+
go-version: 1.18
28+
id: go
29+
30+
- name: Check out code into the Go module directory
31+
uses: actions/checkout@v2
32+
33+
- name: Lint
34+
uses: golangci/golangci-lint-action@v2
35+
with:
36+
args: -p bugs -p unused --timeout=3m
37+
38+
- name: build and test
39+
run: |
40+
make test
41+
make bench
42+
43+
- name: Publish Codecoverage report
44+
run: bash <(curl -s https://codecov.io/bash)
45+
46+
- name: Log in to the Container registry
47+
uses: docker/login-action@v1
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Make tag
54+
run: |
55+
[ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true
56+
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
57+
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true
58+
59+
- name: Build and push image
60+
uses: docker/build-push-action@v2
61+
with:
62+
context: .
63+
push: true
64+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }}

.github/workflows/main.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: Release Drafter Action
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: release-drafter/release-drafter@v5
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode
22
.idea
33
coverage.out
4+
bin

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM bufbuild/buf:1.6.0 as buf
2+
FROM golang:1.18-alpine as builder
3+
4+
RUN apk add \
5+
binutils \
6+
gcc \
7+
git \
8+
libc-dev \
9+
make
10+
11+
WORKDIR /work
12+
COPY --from=buf /usr/local/bin/buf /usr/local/bin/buf
13+
COPY . .
14+
RUN make server client
15+
16+
FROM alpine:3.16
17+
COPY --from=builder /work/bin/* /
18+
ENTRYPOINT [ "/server" ]

Makefile

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
.ONESHELL:
2+
SHA := $(shell git rev-parse --short=8 HEAD)
3+
GITVERSION := $(shell git describe --long --all)
4+
BUILDDATE := $(shell date -Iseconds)
5+
VERSION := $(or ${VERSION},devel)
6+
27
CGO_ENABLED := $(or ${CGO_ENABLED},0)
38
GO := go
49
GO111MODULE := on
510
PG_VERSION := $(or ${PG_VERSION},14-alpine)
6-
COCKROACH_VERSION := $(or ${COCKROACH_VERSION},v22.1.0)
11+
COCKROACH_VERSION := $(or ${COCKROACH_VERSION},latest-v22.1)
12+
LINKMODE := -extldflags '-static -s -w'
13+
714

815
.EXPORT_ALL_VARIABLES:
916

10-
all: test bench
17+
all: proto server client test bench
1118

1219
.PHONY: bench
1320
bench:
14-
CGO_ENABLED=1 $(GO) test -bench . -run=- -count 5 -benchmem -timeout 20m
21+
CGO_ENABLED=1 $(GO) test -bench ./... -run=- -benchmem -timeout 20m
1522

1623
.PHONY: benchstat
1724
benchstat:
@@ -33,6 +40,30 @@ golangcicheck:
3340
lint: golangcicheck
3441
golangci-lint run -p bugs -p unused
3542

43+
.PHONY: proto
44+
proto:
45+
$(MAKE) -C proto protoc
46+
47+
.PHONY: server
48+
server:
49+
go build -tags netgo,osusergo,urfave_cli_no_docs \
50+
-ldflags "$(LINKMODE) -X 'github.com/metal-stack/v.Version=$(VERSION)' \
51+
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
52+
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
53+
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
54+
-o bin/server github.com/metal-stack/go-ipam/cmd/server
55+
strip bin/server
56+
57+
.PHONY: client
58+
client:
59+
go build -tags netgo,osusergo,urfave_cli_no_docs \
60+
-ldflags "$(LINKMODE) -X 'github.com/metal-stack/v.Version=$(VERSION)' \
61+
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
62+
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
63+
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
64+
-o bin/cli github.com/metal-stack/go-ipam/cmd/client
65+
strip bin/cli
66+
3667
.PHONY: postgres-up
3768
postgres-up: postgres-rm
3869
docker run -d --name ipamdb -p 5433:5432 -e POSTGRES_PASSWORD="password" postgres:$(PG_VERSION) -c 'max_connections=200'
@@ -60,3 +91,11 @@ cockroach-up-cluster: cockroach-rm
6091
cockroach-rm:
6192
docker rm -f roach1 roach2 roach3 || true
6293
docker network rm roachnet || true
94+
95+
.PHONY: redis-up
96+
redis-up: redis-rm
97+
docker run -d --name ipamredis -p 6379:6379 redis
98+
99+
.PHONY: redis-rm
100+
redis-rm:
101+
docker rm -f ipamredis || true

0 commit comments

Comments
 (0)