From 805176bb5ea24addb0c9c1a97738918795f562c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orkun=20K=C3=BCl=C3=A7e?= Date: Wed, 29 Apr 2020 23:50:37 +0300 Subject: [PATCH] Improve iovns docker and travis builds (#30) --- .travis.yml | 1 + Dockerfile | 42 ++++++++++++++++++++--------------------- Makefile | 15 ++++++++++----- cmd/iovnscli/.gitignore | 1 + cmd/iovnsd/.gitignore | 1 + 5 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 cmd/iovnscli/.gitignore create mode 100644 cmd/iovnsd/.gitignore diff --git a/.travis.yml b/.travis.yml index 103bca47..fb3f8eae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,7 @@ script: release_tag=$( [[ "$TRAVIS_TAG" != "" ]] && echo "yes" || echo "no" ); if [[ $release_latest == "yes" || $release_tag == "yes" ]]; then + make build docker build --pull --tag ${IMAGE_NAME} . ; fi; diff --git a/Dockerfile b/Dockerfile index 26ac5b93..92290747 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,30 @@ -# Simple usage with a mounted data directory: -# > docker build -t iovns . -# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.iovnsd:/root/.iovnsd -v ~/.iovnscli:/root/.iovnscli iovns iovnsd init -# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.iovnsd:/root/.iovnsd -v ~/.iovnscli:/root/.iovnscli iovns iovnsd start -FROM golang:alpine AS build-env +FROM alpine:3.11 -# Set up dependencies -ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python +ENV NSDHOME /root +ENV NSCLIHOME /root -# Set working directory for the build -WORKDIR /go/src/github.com/iov-one/iovns +RUN apk update && \ + apk upgrade && \ + apk --no-cache add curl jq && \ + addgroup iovnsduser && \ + adduser -S -G iovnsduser iovnsduser -h "$NSDHOME" -# Add source files -COPY . . +# Run the container with iovnsduser by default. (UID=100, GID=1000) +USER iovnsduser -# Install minimum necessary dependencies, build Cosmos SDK, remove packages -RUN apk add --no-cache $PACKAGES && \ - make install +# p2p, rpc and prometheus port +EXPOSE 46656 46657 46660 -# Final image -FROM alpine:edge +ARG NSDBINARY=cmd/iovnsd/iovnsd +ARG NSDCLIBINARY=cmd/iovnscli/iovnscli -# Install ca-certificates -RUN apk add --update ca-certificates -WORKDIR /root +COPY $NSDBINARY /usr/bin/iovnsd +COPY $NSCLIBINARY /usr/bin/iovnscli -# Copy over binaries from the build-env -COPY --from=build-env /go/bin/iovnsd /usr/bin/iovnsd -COPY --from=build-env /go/bin/iovnscli /usr/bin/iovnscli +WORKDIR /root # Run iovnsd by default, omit entrypoint to ease using container with iovnscli CMD ["iovnsd"] +STOPSIGNAL SIGTERM + +VOLUME $NSDHOME $NSCLIHOME diff --git a/Makefile b/Makefile index 3ff1d19e..79879c64 100644 --- a/Makefile +++ b/Makefile @@ -9,18 +9,23 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=NewApp \ -X github.com/cosmos/cosmos-sdk/version.ClientName=appcli \ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) - BUILD_FLAGS := -ldflags '$(ldflags)' +export GO111MODULE := on + all: install install: go.sum - go install -mod=readonly $(BUILD_FLAGS) ./cmd/iovnsd - go install -mod=readonly $(BUILD_FLAGS) ./cmd/iovnscli + go install -mod=readonly $(BUILD_FLAGS) ./cmd/iovnsd + go install -mod=readonly $(BUILD_FLAGS) ./cmd/iovnscli + +build: go.sum + GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o ./cmd/iovnsd -mod=readonly $(BUILD_FLAGS) ./cmd/iovnsd + GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o ./cmd/iovnscli -mod=readonly $(BUILD_FLAGS) ./cmd/iovnscli go.sum: go.mod - @echo "--> Ensure dependencies have not been modified" - GO111MODULE=on go mod verify + @echo "--> Ensure dependencies have not been modified" + GO111MODULE=on go mod verify # Uncomment when you have some tests # test: diff --git a/cmd/iovnscli/.gitignore b/cmd/iovnscli/.gitignore new file mode 100644 index 00000000..2886cd64 --- /dev/null +++ b/cmd/iovnscli/.gitignore @@ -0,0 +1 @@ +iovnscli \ No newline at end of file diff --git a/cmd/iovnsd/.gitignore b/cmd/iovnsd/.gitignore new file mode 100644 index 00000000..b5b8de43 --- /dev/null +++ b/cmd/iovnsd/.gitignore @@ -0,0 +1 @@ +iovnsd \ No newline at end of file