Skip to content

Commit 5522857

Browse files
committed
adding pkger support for makefile & Dockerfile
1 parent a098263 commit 5522857

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ WORKDIR /src
3333
COPY ./go.mod ./go.sum ./
3434
# Get dependancies - will also be cached if we won't change mod/sum
3535
RUN go mod download && \
36-
GO111MODULE=off go get github.com/ahmetb/govvv
36+
GO111MODULE=off go get github.com/ahmetb/govvv && \
37+
go install github.com/markbates/pkger/cmd/pkger
3738

3839
# COPY the source code as the last step
3940
COPY ./ ./
@@ -43,6 +44,7 @@ ARG VERSION=0.0.1
4344
ARG TYPE=srv
4445
ARG TARGET=account
4546

47+
RUN pkger -o $TYPE/$TARGET -include /deploy/bases/micros/$TARGET-$TYPE/config
4648
RUN go build -a \
4749
-ldflags="-w -s -linkmode external -extldflags '-static' $(govvv -flags -version ${VERSION} -pkg $(go list ./shared/config) )" \
4850
-o /app ./$TYPE/$TARGET/main.go ./$TYPE/$TARGET/plugin.go

Makefile

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ VERSION := $(shell git describe --tags || echo "HEAD")
1717
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1818
GOPATH := $(shell go env GOPATH)
1919
HAS_GOVVV := $(shell command -v govvv 2> /dev/null)
20+
HAS_PKGER := $(shell command -v pkger 2> /dev/null)
2021
GIT_DIRTY := $(shell git status --porcelain 2> /dev/null)
2122
HAS_KO := $(shell command -v ko 2> /dev/null)
2223
CODECOV_FILE := build/coverage.txt
@@ -38,6 +39,7 @@ BUILD_FLAGS = $(shell govvv -flags -version $(VERSION) -pkg $(VERSION_PACKAGE))
3839
.PHONY: all tools, check_dirty, clean, update_deps
3940
.PHONY: proto proto-%
4041
.PHONY: lint lint-%
42+
.PHONY: pkger pkger-%
4143
.PHONY: build build-%
4244
.PHONY: run run-%
4345
.PHONY: docker_clean docker docker-% docker_push
@@ -50,7 +52,7 @@ all: build
5052
tools:
5153
@echo "==> Installing dev tools"
5254
# go install github.com/ahmetb/govvv
53-
# go install github.com/google/ko/cmd/ko
55+
# go install github.com/markbates/pkger/cmd/pkger
5456

5557
check_dirty:
5658
ifdef GIT_DIRTY
@@ -103,7 +105,25 @@ lint lint-%:
103105
${GOPATH}/bin/golangci-lint run ./${TYPE}/${TARGET}/... ; \
104106
fi
105107

106-
build build-%:
108+
pkger pkger-%:
109+
ifndef HAS_PKGER
110+
$(error "No pkger in PATH". Please install via 'go install github.com/markbates/pkger/cmd/pkger'")
111+
endif
112+
@if [ -z $(TARGET) ]; then \
113+
for type in $(TYPES); do \
114+
echo "Packaging config for Type: $${type}..."; \
115+
for _target in $${type}/*/; do \
116+
temp=$${_target%%/}; target=$${temp#*/}; \
117+
echo "\tPackaging config for $${target}-$${type}"; \
118+
${GOPATH}/bin/pkger -o $${type}/$${target} -include /deploy/bases/micros/$${target}-$${type}/config; \
119+
done \
120+
done \
121+
else \
122+
echo "Packaging config for ${TARGET}-${TYPE}..."; \
123+
${GOPATH}/bin/pkger -o ${TYPE}/${TARGET} -include /deploy/bases/micros/${TARGET}-${TYPE}/config ; \
124+
fi
125+
126+
build build-%: pkger-%
107127
ifndef HAS_GOVVV
108128
$(error "No govvv in PATH". Please install via 'go install github.com/ahmetb/govvv'")
109129
endif

docs/makefile.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ make lint-account
8686
make lint-account-srv
8787
```
8888

89+
### Packager
90+
91+
```bash
92+
make pkger TARGET=greeter
93+
make pkger-greeter
94+
make pkger
95+
```
96+
8997
### build
9098

9199
```bash

docs/prerequisites.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GO111MODULE=off go get github.com/google/ko/cmd/ko
3737
# other way to get latest kustomize
3838
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@v3.3.0
3939
# pkger cli
40-
go get github.com/markbates/pkger/cmd/pkger
40+
go install github.com/markbates/pkger/cmd/pkger
4141

4242
# fetch protoc plugins into $GOPATH
4343
GO111MODULE=off go get github.com/golang/protobuf/{proto,protoc-gen-go}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/infobloxopen/atlas-app-toolkit v0.19.0
1313
github.com/infobloxopen/protoc-gen-gorm v0.18.0
1414
github.com/jinzhu/gorm v1.9.11
15-
github.com/markbates/pkger v0.12.2
15+
github.com/markbates/pkger v0.12.3
1616
github.com/micro/cli v0.2.0
1717
github.com/micro/go-micro v1.16.0
1818
github.com/onrik/logrus v0.4.1

go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
190190
github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA=
191191
github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ=
192192
github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s=
193-
github.com/markbates/pkger v0.12.2/go.mod h1:so/QD8FeTM0IilC3nRArkwOvUT+tsJsaXLFUAKmjzJk=
193+
github.com/markbates/pkger v0.12.3/go.mod h1:so/QD8FeTM0IilC3nRArkwOvUT+tsJsaXLFUAKmjzJk=
194194
github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI=
195195
github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
196196
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=

shared/micro/config/source/pkger/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
pkger plugin for `go-config`
44

5-
## Prerequisites
5+
### Prerequisites
66

77
> Install `pkger` cli
88
99
```bash
10-
go get github.com/markbates/pkger/cmd/pkger
10+
go install github.com/markbates/pkger/cmd/pkger
1111
pkger -h
1212
```
1313

14-
> generating `pkged.go` with all files in `/config` for production envelopment
14+
### Packager
15+
16+
> generating `pkged.go` with all files in `/config` for production build
1517
1618
```bash
1719
pkger -o srv/greeter -include /config
20+
# (or)
21+
make make pkger-greeter
22+
# (or)
23+
make pkger
1824
```

0 commit comments

Comments
 (0)