Skip to content

Commit

Permalink
Merge pull request #270 from utlemming/makefile
Browse files Browse the repository at this point in the history
Makefile: enable build via make and create local container
  • Loading branch information
mauricio authored Oct 31, 2017
2 parents df75d61 + e4abc96 commit ab54ea4
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

10 changes: 10 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.9-alpine

ENV MAKE_TARGET linux_amd64

RUN apk update && \
apk add bash && \
apk add curl && \
apk add git && \
apk add make && \
apk add libc6-compat
27 changes: 27 additions & 0 deletions Dockerfile.cntr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM doctl_builder

ENV CGO=0
ENV OUT_D /out

RUN mkdir -p /out
RUN mkdir -p /go/src/github.com/digitalocean/doctl
ADD . /go/src/github.com/digitalocean/doctl/

RUN cd /go/src/github.com/digitalocean/doctl && \
make build_linux_amd64 OUT=/out && \
make build_linux_386 OUT=/out && \
make build_mac OUT=/out

RUN find /out

FROM alpine:latest

VOLUME ["/copy"]

RUN apk update && \
apk add rsync && \
apk add libc6-compat

COPY --from=0 /out/* /app/

ENTRYPOINT ["/app/doctl_linux_amd64"]
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.PHONE: build
export CGO=0

my_d=$(shell pwd)
OUT_D = $(shell echo $${OUT_D:-$(my_d)/builds})

GOOS = linux
UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_S),Darwin)
NATIVE = darwin
GOARCH = 386
endif

GOARCH = amd64
ifneq ($(UNAME_P), x86_64)
GOARCH = 386
endif

native: _build
native:
@mv $(OUT_D)/doctl_$(GOOS)_$(GOARCH) $(OUT_D)/doctl
@echo "built $(OUT_D)/doctl"

_build:
@mkdir -p builds
@echo "building doctl"
@cd cmd/doctl && env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(OUT_D)/doctl_$(GOOS)_$(GOARCH)
@echo "built $(OUT_D)/doctl_$(GOOS)_$(GOARCH)"


build_mac: GOOS = darwin
build_mac: GOARCH = 386
build_mac: _build

build_linux_386: GOARCH = 386
build_linux_386: _build

build_linux_amd64: GOARCH = amd64
build_linux_amd64: _build

clean:
@rm -rf builds

_base_docker_cntr:
docker build -f Dockerfile.build . -t doctl_builder

docker_build: _base_docker_cntr
docker_build:
@mkdir -p $(OUT_D)
@docker build -f Dockerfile.cntr . -t doctl_local
@docker run --rm \
-v $(OUT_D):/copy \
-it --entrypoint /usr/bin/rsync \
doctl_local -av /app/ /copy/
@docker run --rm \
-v $(OUT_D):/copy \
-it --entrypoint /bin/chown \
alpine -R $(shell whoami | id -u): /copy
@echo "Built binaries to $(OUT_D)"
@echo "Created a local Docker container. To use, run: docker run --rm -it doctl_local"

0 comments on commit ab54ea4

Please sign in to comment.