Skip to content

Commit

Permalink
adding pkger support for makefile & Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Nov 15, 2019
1 parent a098263 commit 5522857
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ WORKDIR /src
COPY ./go.mod ./go.sum ./
# Get dependancies - will also be cached if we won't change mod/sum
RUN go mod download && \
GO111MODULE=off go get github.com/ahmetb/govvv
GO111MODULE=off go get github.com/ahmetb/govvv && \
go install github.com/markbates/pkger/cmd/pkger

# COPY the source code as the last step
COPY ./ ./
Expand All @@ -43,6 +44,7 @@ ARG VERSION=0.0.1
ARG TYPE=srv
ARG TARGET=account

RUN pkger -o $TYPE/$TARGET -include /deploy/bases/micros/$TARGET-$TYPE/config
RUN go build -a \
-ldflags="-w -s -linkmode external -extldflags '-static' $(govvv -flags -version ${VERSION} -pkg $(go list ./shared/config) )" \
-o /app ./$TYPE/$TARGET/main.go ./$TYPE/$TARGET/plugin.go
Expand Down
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VERSION := $(shell git describe --tags || echo "HEAD")
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GOPATH := $(shell go env GOPATH)
HAS_GOVVV := $(shell command -v govvv 2> /dev/null)
HAS_PKGER := $(shell command -v pkger 2> /dev/null)
GIT_DIRTY := $(shell git status --porcelain 2> /dev/null)
HAS_KO := $(shell command -v ko 2> /dev/null)
CODECOV_FILE := build/coverage.txt
Expand All @@ -38,6 +39,7 @@ BUILD_FLAGS = $(shell govvv -flags -version $(VERSION) -pkg $(VERSION_PACKAGE))
.PHONY: all tools, check_dirty, clean, update_deps
.PHONY: proto proto-%
.PHONY: lint lint-%
.PHONY: pkger pkger-%
.PHONY: build build-%
.PHONY: run run-%
.PHONY: docker_clean docker docker-% docker_push
Expand All @@ -50,7 +52,7 @@ all: build
tools:
@echo "==> Installing dev tools"
# go install github.com/ahmetb/govvv
# go install github.com/google/ko/cmd/ko
# go install github.com/markbates/pkger/cmd/pkger

check_dirty:
ifdef GIT_DIRTY
Expand Down Expand Up @@ -103,7 +105,25 @@ lint lint-%:
${GOPATH}/bin/golangci-lint run ./${TYPE}/${TARGET}/... ; \
fi

build build-%:
pkger pkger-%:
ifndef HAS_PKGER
$(error "No pkger in PATH". Please install via 'go install github.com/markbates/pkger/cmd/pkger'")
endif
@if [ -z $(TARGET) ]; then \
for type in $(TYPES); do \
echo "Packaging config for Type: $${type}..."; \
for _target in $${type}/*/; do \
temp=$${_target%%/}; target=$${temp#*/}; \
echo "\tPackaging config for $${target}-$${type}"; \
${GOPATH}/bin/pkger -o $${type}/$${target} -include /deploy/bases/micros/$${target}-$${type}/config; \
done \
done \
else \
echo "Packaging config for ${TARGET}-${TYPE}..."; \
${GOPATH}/bin/pkger -o ${TYPE}/${TARGET} -include /deploy/bases/micros/${TARGET}-${TYPE}/config ; \
fi

build build-%: pkger-%
ifndef HAS_GOVVV
$(error "No govvv in PATH". Please install via 'go install github.com/ahmetb/govvv'")
endif
Expand Down
8 changes: 8 additions & 0 deletions docs/makefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ make lint-account
make lint-account-srv
```

### Packager

```bash
make pkger TARGET=greeter
make pkger-greeter
make pkger
```

### build

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GO111MODULE=off go get github.com/google/ko/cmd/ko
# other way to get latest kustomize
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/[email protected]
# pkger cli
go get github.com/markbates/pkger/cmd/pkger
go install github.com/markbates/pkger/cmd/pkger

# fetch protoc plugins into $GOPATH
GO111MODULE=off go get github.com/golang/protobuf/{proto,protoc-gen-go}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/infobloxopen/atlas-app-toolkit v0.19.0
github.com/infobloxopen/protoc-gen-gorm v0.18.0
github.com/jinzhu/gorm v1.9.11
github.com/markbates/pkger v0.12.2
github.com/markbates/pkger v0.12.3
github.com/micro/cli v0.2.0
github.com/micro/go-micro v1.16.0
github.com/onrik/logrus v0.4.1
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA=
github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ=
github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s=
github.com/markbates/pkger v0.12.2/go.mod h1:so/QD8FeTM0IilC3nRArkwOvUT+tsJsaXLFUAKmjzJk=
github.com/markbates/pkger v0.12.3/go.mod h1:so/QD8FeTM0IilC3nRArkwOvUT+tsJsaXLFUAKmjzJk=
github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI=
github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
Expand Down
12 changes: 9 additions & 3 deletions shared/micro/config/source/pkger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

pkger plugin for `go-config`

## Prerequisites
### Prerequisites

> Install `pkger` cli
```bash
go get github.com/markbates/pkger/cmd/pkger
go install github.com/markbates/pkger/cmd/pkger
pkger -h
```

> generating `pkged.go` with all files in `/config` for production envelopment
### Packager

> generating `pkged.go` with all files in `/config` for production build
```bash
pkger -o srv/greeter -include /config
# (or)
make make pkger-greeter
# (or)
make pkger
```

0 comments on commit 5522857

Please sign in to comment.