Skip to content

Commit

Permalink
Improve iovns docker and travis builds (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
orkunkl authored Apr 29, 2020
1 parent d611e82 commit 805176b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
42 changes: 20 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions cmd/iovnscli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iovnscli
1 change: 1 addition & 0 deletions cmd/iovnsd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iovnsd

0 comments on commit 805176b

Please sign in to comment.