Skip to content

Commit

Permalink
refactor dockerfile, go modules with golang v1.14.2; "closes travisje…
Browse files Browse the repository at this point in the history
…ffery#163"

- removed dep-related comands and notes
- added two Dockerfiles (works with Podman, Buildah too)
  - "prod": for clean build, with tests, runnng with non-root user, from scratch container
  - "dev":  there is caching for golang deps, without tests, run as root, and result container can be not from scratch, for debug reasons.
- docker-compose file:
  - added shared context-build block, DRY.
  - removed command name `jocko` in line `command: jocko broker...` because of we using the same ENTRYPOINT in docker file.

- small fixes in module paths:
  - "github.com/hashicorp/consul/testutil/retry" -> "github.com/hashicorp/consul/sdk/testutil/retry"

- update go.mod to the lastest version for all transitive deps (exepts github.com/mitchellh/go-testing-interface v1.4.0)
  • Loading branch information
BOPOHA committed Apr 27, 2020
1 parent 0664792 commit 1d0448d
Show file tree
Hide file tree
Showing 12 changed files with 697 additions and 200 deletions.
13 changes: 9 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ When creating a pull-request you should:
```
- **Get the deps**:
Just get the deps from go.mod file
```shell script
go mod download
```
Get deps and [upgrade](https://github.com/golang/go/issues/28692) to the latest version for all transitive dependencies:
```shell script
go get -d -v all
```
dep ensure
```
(If you don't have dep, run: `go get -u github.com/golang/dep/cmd/dep`)
- **Check the tests pass**:
```
Expand All @@ -26,7 +31,7 @@ When creating a pull-request you should:
- **Make your change**
- **Write tests and check they pass**
- **Lint your code**: Use `gofmt`, `golint`, and `govet` to clean up your code
- **Lint your code**: Use `gofmt`, `golint`, `govet`, and `go mod tidy` to clean up your code
- **Start your commit message with a verb**: your commit message must start a lowercase verb such as: "add", "fix", "refactor", "remove"
- **Reference the issue**: Reference your issue N by including "closes #N" in the commit message
Expand Down
29 changes: 18 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
FROM golang:1.9-alpine as build-base
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh make && \
go get -u github.com/golang/dep/cmd/dep
ADD . /go/src/github.com/travisjeffery/jocko
WORKDIR /go/src/github.com/travisjeffery/jocko
RUN GOOS=linux GOARCH=amd64 make build
# The file using for build smallest conatiner for production
# And there are additionals: `go test` step and non-root user unlike the Dockerfile-dev.

FROM alpine:latest
COPY --from=build-base /go/src/github.com/travisjeffery/jocko/cmd/jocko/jocko /usr/local/bin/jocko
FROM golang:1.14-alpine as build-base
RUN install -g nobody -o nobody -m 0770 -d /tmp/empty-dir-owned-by-nobody
RUN echo 'nobody:x:65534:65534:nobody:/:/sbin/nologin' > /tmp/passwd

ADD . $GOPATH/src/github.com/travisjeffery/jocko/
WORKDIR $GOPATH/src/github.com/travisjeffery/jocko/
RUN go mod download && go mod verify
RUN CGO_ENABLED=0 go test -v ./...
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /jocko cmd/jocko/main.go

FROM scratch
COPY --chown=65534:65534 --from=build-base /tmp/empty-dir-owned-by-nobody /tmp
COPY --from=build-base /jocko /jocko
COPY --from=build-base /tmp/passwd /etc/passwd
EXPOSE 9092 9093 9094 9095
VOLUME "/tmp/jocko"
CMD ["jocko", "broker"]
USER nobody
ENTRYPOINT ["/jocko"]
16 changes: 16 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The file using for build conatiner for regular development,
# it skip downloading vedor files if `go.*` files was not edited

FROM golang:1.14-alpine as build-base
WORKDIR /build
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /jocko cmd/jocko/main.go

FROM scratch
COPY --from=build-base /jocko /jocko
EXPOSE 9092 9093 9094 9095
VOLUME "/tmp/jocko"
ENTRYPOINT ["/jocko"]
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ DOCKER_TAG := latest
all: test

deps:
@which dep 2>/dev/null || go get -u github.com/golang/dep/cmd/dep
@dep ensure -v
@go mod download

vet:
@go list ./... | grep -v vendor | xargs go vet
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ I’m writing a book for PragProg called Building Distributed Services with Go.
$ make build
```
(If you see an error about `dep` not being found, ensure that
`$GOPATH/bin` is in your `PATH`)
### Docker
`docker build -t travisjeffery/jocko:latest .`
Expand Down
5 changes: 5 additions & 0 deletions _examples/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ $ ./jocko broker \
## docker-compose cluster

To start a [docker compose](https://docs.docker.com/compose/) cluster use the provided `docker-compose.yml`.

```shell
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml up
```
17 changes: 11 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
version: '3'

x-context-build:
&context-build
context: .
dockerfile: Dockerfile-dev

services:
jocko_a:
build:
context: .
<<: *context-build
image: travisjeffery/jocko:latest
command: jocko broker --id 0 --raft-addr=jocko_a:9093 --bootstrap --bootstrap-expect=3
command: broker --id 0 --raft-addr=jocko_a:9093 --bootstrap --bootstrap-expect=3

jocko_b:
build:
context: .
<<: *context-build
image: travisjeffery/jocko:latest
command: jocko broker --join=jocko_a:9094 --id 1 --raft-addr=jocko_b:9093 --bootstrap-expect=3
command: broker --join=jocko_a:9094 --id 1 --raft-addr=jocko_b:9093 --bootstrap-expect=3

jocko_c:
build:
context: .
<<: *context-build
image: travisjeffery/jocko:latest
command: jocko broker --join=jocko_a:9094 --id 2 --raft-addr=jocko_c:9093 --bootstrap-expect=3
command: broker --join=jocko_a:9094 --id 2 --raft-addr=jocko_c:9093 --bootstrap-expect=3
106 changes: 53 additions & 53 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
module github.com/travisjeffery/jocko

go 1.12
go 1.14

require (
github.com/Shopify/sarama v1.13.0
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
github.com/boltdb/bolt v1.3.1
github.com/bsm/sarama-cluster v2.1.10+incompatible
github.com/cenkalti/backoff v2.0.0+incompatible
github.com/cespare/xxhash v1.0.0
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd
github.com/OneOfOne/xxhash v1.2.7 // indirect
github.com/Shopify/sarama v1.26.1
github.com/armon/go-metrics v0.3.3 // indirect
github.com/bsm/sarama-cluster v2.1.15+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cespare/xxhash v1.1.0
github.com/davecgh/go-spew v1.1.1
github.com/eapache/go-resiliency v1.0.0
github.com/eapache/go-xerial-snappy v0.0.0-20160609142408-bb955e01b934
github.com/eapache/queue v1.0.2
github.com/go-kit/kit v0.6.0
github.com/golang/protobuf v1.2.0
github.com/golang/snappy v0.0.0-20170215233205-553a64147049
github.com/hashicorp/consul v1.0.3
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-immutable-radix v1.0.0
github.com/hashicorp/go-memdb v0.0.0-20171005030753-75ff99613d28
github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-sockaddr v1.0.0
github.com/hashicorp/golang-lru v0.5.0
github.com/hashicorp/memberlist v0.1.3
github.com/hashicorp/raft v1.1.1
github.com/frankban/quicktest v1.9.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-kit/kit v0.10.0
github.com/golang/protobuf v1.4.0 // indirect
github.com/hashicorp/consul/sdk v0.4.0
github.com/hashicorp/go-hclog v0.12.2 // indirect
github.com/hashicorp/go-memdb v1.2.1
github.com/hashicorp/go-msgpack v1.1.5 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/memberlist v0.2.0
github.com/hashicorp/raft v1.1.2
github.com/hashicorp/raft-boltdb v0.0.0-20191021154308-4207f1bf0617
github.com/hashicorp/serf v0.8.5
github.com/inconshreveable/mousetrap v1.0.0
github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/miekg/dns v1.0.14
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77
github.com/opentracing/opentracing-go v1.0.2
github.com/pierrec/lz4 v1.0.1
github.com/pierrec/xxHash v0.1.1
github.com/pkg/errors v0.8.1
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a
github.com/rcrowley/go-metrics v0.0.0-20161128210544-1f30fe9094a5
github.com/hashicorp/serf v0.9.0
github.com/klauspost/compress v1.10.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/miekg/dns v1.1.29 // indirect
github.com/mitchellh/go-testing-interface v1.14.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/opentracing/opentracing-go v1.1.0
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/procfs v0.0.11 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/satori/go.uuid v1.2.0
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529
github.com/spf13/cobra v0.0.1
github.com/spf13/pflag v1.0.0
github.com/stretchr/testify v1.3.0
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.5.1
github.com/tj/go-gracefully v0.0.0-20141227061038-005c1d102f1b
github.com/travisjeffery/go-dynaport v0.0.0-20171203090423-24009f4f2f49
github.com/tysontate/gommap v0.0.0-20131202084435-e87a6e482c2c
github.com/uber/jaeger-client-go v2.11.2+incompatible
github.com/uber/jaeger-lib v1.3.1
github.com/ugorji/go v0.0.0-20180112141927-9831f2c3ac10
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5
upspin.io v0.0.0-20180517055408-63f1073c7a3a
github.com/travisjeffery/go-dynaport v1.0.0
github.com/tysontate/gommap v0.0.0-20190103205956-899e1273fb5c
github.com/uber/jaeger-client-go v2.23.0+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible
github.com/ugorji/go/codec v1.1.7
go.uber.org/atomic v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f // indirect
golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
upspin.io v0.0.0-20200124224713-5ddde7b8e6ff
)
Loading

0 comments on commit 1d0448d

Please sign in to comment.