Skip to content

Commit

Permalink
Move development environment into docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuki committed Mar 17, 2020
1 parent 0d1779d commit 1f312fe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 52 deletions.
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ FROM golang:1.14.0

ENV PKG github.com/yuuki/transtracer
WORKDIR /go/src/$PKG

COPY . .

RUN make build
75 changes: 41 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export GO111MODULE=on
export GOFLAGS=-mod=vendor
export GOOS=linux

PROJECT = transtracer
Expand All @@ -9,45 +8,39 @@ DATE = $$(date -u '+%Y-%m-%d_%H:%M:%S')
BUILD_LDFLAGS = -X $(PKG)/version.commit=$(COMMIT) -X $(PKG)/version.date=$(DATE)
CREDITS = ./assets/CREDITS

.PHONY: build
build: build-deps
go generate ./...
go build -ldflags="$(BUILD_LDFLAGS)" ./cmd/ttracerd/
go build -ldflags="$(BUILD_LDFLAGS)" ./cmd/ttctl/
DOCKER_IMAGE_NAME="transtracer-test"
DOCKER_CONTAINER_NAME="transtracer-test-container"
DOCKER = docker run --rm -v $$(PWD):/go/src/github.com/yuuki/transtracer --name $(DOCKER_CONTAINER_NAME) $(DOCKER_IMAGE_NAME)
container = docker ps -a -q -f "name=$(DOCKER_CONTAINER_NAME)"

.PHONY: build-deps
build-deps: _build-deps tidy-module
all: init build

.PHONY: _build-deps
_build-deps:
go get github.com/rakyll/statik
.PHONY: clean
clean:
@if [ "$(container || true)" != "" ] ; then \
docker rm -f $(DOCKER_CONTAINER_NAME) 2>/dev/null; \
fi

.PHONY: tidy-module
tidy-module:
.PHONY: build
build: clean
go generate ./...
$(DOCKER) go build -ldflags="$(BUILD_LDFLAGS)" ./cmd/ttracerd/
$(DOCKER) go build -ldflags="$(BUILD_LDFLAGS)" ./cmd/ttctl/
go mod tidy
go mod vendor

.PHONY: install
install:
go install $(PKG)/cmd/...

.PHONY: test
test:
go test -v ./...

.PHONY: devel-deps
devel-deps: _devel-deps tidy-module

.PHONY: _devel-deps
_devel-deps:
go get \
golang.org/x/lint/golint \
golang.org/x/tools/cmd/cover \
github.com/mattn/goveralls \
github.com/x-motemen/gobump/cmd/gobump \
github.com/Songmu/ghch/cmd/ghch \
github.com/Songmu/gocredits/cmd/gocredits
$(DOCKER) go test -v ./...
go mod tidy

.PHONY: lint
lint:
# golangci-lint run ./... error: failed prerequisites:
$(DOCKER) golint -set_exit_status $$(go list -mod=vendor ./...)

.PHONY: credits
credits: devel-deps
Expand All @@ -56,11 +49,25 @@ ifneq (,$(git status -s $(CREDITS)))
go generate -x ./...
endif

.PHONY: lint
lint:
# golangci-lint run ./... error: failed prerequisites:
golint -set_exit_status $$(go list -mod=vendor ./...)

.PHONY: release
release: devel-deps credits
release: credits
_tools/release

init: deps docker-build

.PHONY: deps
deps:
sh -c '\
tmpdir=$$(mktemp -d); \
cd $$tmpdir; \
go get -u \
github.com/rakyll/statik \
golang.org/x/lint/golint \
github.com/x-motemen/gobump/cmd/gobump \
github.com/Songmu/ghch/cmd/ghch \
github.com/Songmu/gocredits/cmd/gocredits; \
rm -rf $$tmpdir'

.PHONY: docker-build
docker-build:
docker build -t $(DOCKER_IMAGE_NAME) .
14 changes: 0 additions & 14 deletions _tools/test_in_container

This file was deleted.

0 comments on commit 1f312fe

Please sign in to comment.