You simply need 
docker run <...>
which will invoke smth like 
go build
at the end.

PS: The above Makefile is garbage.


пятница, 1 февраля 2019 г., 21:59:53 UTC+3 пользователь Bojan Delić написал:
>
> I have Makefile that supports build in docker image, part of it looks 
> something like this:
>
> NAME := <name>
> PACKAGE := github.com/username/repo
>
>
> .PHONY: build
> build: clean gobuild ## Build application
>
> .PHONY: gobuild
> gobuild: LDFLAGS=$(shell ./scripts/gen-ldflags.sh $(VERSION))
> gobuild:
>    @echo "Building '$(NAME)'"
>    @env go generate -mod=vendor
>    @CGO_ENABLED=0 go build -mod=vendor --ldflags "$(LDFLAGS)" -tags netgo .
>
> .PHONY: clean
> clean: ## Remove build artifacts
>    @echo "==> Cleaning build artifacts..."
>    @rm -fv coverage.txt
>    @find . -name '*.test' | xargs rm -fv
>    @rm -fv $(NAME)
>
> .PHONY: build-in-docker
> build-in-docker:
>    @docker run --rm \
>       -v $(shell pwd):/go/src/$(PACKAGE) \
>       -w /go/src/$(PACKAGE) \
>       -e GO111MODULE=on \
>       golang:latest \
>       make build
>
>
> As you can see, there are some external scripts called (like 
> gen-ldflags.sh) and docker build is just invoking "make build" inside 
> docker container. I do not use this for CI (GitLab CI is already setup to 
> use docker images), so that is why I use latest tag (in CI I use explicit 
> version of Go). 
>
>
> There are some leftovers from earlier times, like mounting working dir to 
> GOPATH, which is not needed if GO111MODULE is set.
>
>
> On Friday, February 1, 2019 at 4:48:01 AM UTC+1, Keith Brown wrote:
>>
>> does anyone use docker golang image to compile? if so,how is your setup?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to