Skip to content

Commit

Permalink
Merge pull request #247 from ahpook/further_docker
Browse files Browse the repository at this point in the history
Support docker-based builds in the Makefile
  • Loading branch information
Eric Sorenson authored May 7, 2019
2 parents a0afb1e + 0b065b6 commit b3ebeae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ COPY go.mod .
COPY go.sum .
RUN GO111MODULE=on go mod download
COPY . .
RUN make lyra plugins
RUN make docker-build
# Copy binaries over to a new container
FROM golang:latest
FROM alpine
WORKDIR /src/lyra/
ENV PATH /src/lyra/build/bin:$PATH
COPY --from=builder /src/lyra/build/bin/lyra /src/lyra/build/bin/lyra
RUN apk add ca-certificates
RUN mkdir /src/lyra/local
COPY --from=builder /src/lyra/build/goplugins /src/lyra/build/goplugins
COPY --from=builder /src/lyra/workflows /src/lyra/workflows
COPY --from=builder /src/lyra/examples /src/lyra/examples
COPY --from=builder /src/lyra/docs /src/lyra/docs
COPY --from=builder /src/lyra/types /src/lyra/types
COPY --from=builder /src/lyra/data.yaml /src/lyra
CMD lyra apply foobernetes
CMD lyra apply foobernetes
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ PACKAGE_NAME = github.com/lyraproj/lyra
LDFLAGS += -X "$(PACKAGE_NAME)/pkg/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "$(PACKAGE_NAME)/pkg/version.BuildTag=$(shell git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///')"
LDFLAGS += -X "$(PACKAGE_NAME)/pkg/version.BuildSHA=$(shell git rev-parse --short HEAD)"
BUILDARGS = GO111MODULE=on

GO_PLUGINS := $(subst cmd/,,$(wildcard cmd/goplugin-*))
TERRAFORM_PLUGINS := \
Expand All @@ -35,6 +36,11 @@ all: everything
PHONY+= everything
everything: check-mods clean lint test lyra plugins smoke-test

PHONY+= docker-build
docker-build: BUILDARGS += CGO_ENABLED=0 GOOS=linux
docker-build: LDFLAGS += -extldflags "-static"
docker-build: lyra plugins

PHONY+= shrink
shrink:
for f in build/*; do \
Expand Down Expand Up @@ -67,7 +73,7 @@ lyra: check-mods
PHONY+= test
test:
@echo "🔘 Running unit tests... (`date '+%H:%M:%S'`)"
GO111MODULE=on go test $(TESTFLAGS) github.com/lyraproj/lyra/...
$(BUILDARGS) go test $(TESTFLAGS) github.com/lyraproj/lyra/...

PHONY+= clean
clean:
Expand Down Expand Up @@ -111,6 +117,8 @@ dist-release:
sha256sum $$f.tar.gz | awk '{ print $1 }' > $$f.tar.gz.sha256 ; \
done;

# Recursion note: this target is to build a container on a host OS.
# The Dockerfile will then run `make docker-build` *inside* the container
PHONY+= docker
docker:
@echo "🔘 Building docker container (`date '+%H:%M:%S'`)"
Expand Down Expand Up @@ -166,13 +174,13 @@ generate-ts:
define build
echo "🔘 Building - $(1) (`date '+%H:%M:%S'`)"
mkdir -p build/
GO111MODULE=on go build -ldflags '$(LDFLAGS)' -o build/$(1) $(2)
$(BUILDARGS) go build -ldflags '$(LDFLAGS)' -o build/$(1) $(2)
echo "✅ Build complete - $(1) (`date '+%H:%M:%S'`)"
endef

define checklint
echo "🔘 Linting $(1) (`date '+%H:%M:%S'`)"
lint=`GO111MODULE=on golangci-lint run $(LINTFLAGS) $(1)`; \
lint=`$(BUILDARGS) golangci-lint run $(LINTFLAGS) $(1)`; \
if [ "$$lint" != "" ]; \
then echo "🔴 Lint found"; echo "$$lint"; exit 1;\
else echo "✅ Lint-free (`date '+%H:%M:%S'`)"; \
Expand Down

0 comments on commit b3ebeae

Please sign in to comment.