Skip to content

Commit

Permalink
Add docker build and push to travis (#569)
Browse files Browse the repository at this point in the history
* Add docker build and push to travis
  • Loading branch information
Isaac Beckman authored and y0sher committed Feb 21, 2019
1 parent f9290a0 commit c5ff047
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,9 @@ go: 1.11.x

env: GO111MODULE=on

services:
- docker

# for some reason /usr/local is owned by a different user in travis, so we transfer ownership to the current user:
before_install: sudo chown -R $(whoami) /usr/local

Expand All @@ -28,6 +31,10 @@ jobs:
- make genproto
- make test-tidy
- make test-fmt
- stage: docker-push
name: "Push to dockerHub"
script:
- make dockerpush

cache:
directories:
Expand Down
23 changes: 22 additions & 1 deletion Makefile
@@ -1,12 +1,19 @@
BINARY := go-spacemesh
VERSION := 0.0.1
COMMIT = $(shell git rev-parse HEAD)
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
SHA = $(shell git rev-parse --short HEAD)
# BRANCH = $(shell git symbolic-ref --short HEAD)
BIN_DIR = $(shell pwd)/build
CURR_DIR = $(shell pwd)
CURR_DIR_WIN = $(shell cd)
export GO111MODULE = on

ifndef TRAVIS_PULL_REQUEST_BRANCH
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
else
BRANCH := $(TRAVIS_PULL_REQUEST_BRANCH)
endif

# Setup the -ldflags option to pass vars defined here to app vars
LDFLAGS = -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.branch=${BRANCH}"

Expand All @@ -15,6 +22,8 @@ PKGS = $(shell go list ./...)
PLATFORMS := windows linux darwin
os = $(word 1, $@)

DOCKER_IMAGE_NAME=go-spacemesh

all: install build
.PHONY: all

Expand Down Expand Up @@ -88,3 +97,15 @@ cover:
tail -n +2 cover.out >> cover-all.out;)
go tool cover -html=cover-all.out
.PHONY: cover

dockerbuild:
docker build -t $(DOCKER_IMAGE_NAME):latest .
.PHONY: dockerbuild

dockerpush: dockerbuild
echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
docker tag $(DOCKER_IMAGE_NAME) spacemeshos/$(DOCKER_IMAGE_NAME):$(BRANCH)
docker tag $(DOCKER_IMAGE_NAME) spacemeshos/$(DOCKER_IMAGE_NAME):$(SHA)
docker push spacemeshos/$(DOCKER_IMAGE_NAME):$(BRANCH)
docker push spacemeshos/$(DOCKER_IMAGE_NAME):$(SHA)
.PHONY: dockerpush

0 comments on commit c5ff047

Please sign in to comment.