Skip to content

Commit

Permalink
Use gomod instead of glide (#6045)
Browse files Browse the repository at this point in the history
To build outside docker, run:
```
GO111MODULE=on go build -v ./cmd/...
```
  • Loading branch information
tdmanv authored and Ilya Kislenko committed Jul 16, 2019
1 parent b00b779 commit 9ef1611
Show file tree
Hide file tree
Showing 8 changed files with 729 additions and 681 deletions.
38 changes: 10 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ IMAGE_NAME := $(BIN)

IMAGE := $(REGISTRY)/$(IMAGE_NAME)

BUILD_IMAGE ?= kanisterio/build:0.13.2-go1.11
BUILD_IMAGE ?= kanisterio/build:v0.0.1
DOCS_BUILD_IMAGE ?= kanisterio/docker-sphinx

DEFAULT_PATH := /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

DOCS_RELEASE_BUCKET ?= s3://docs.kanister.io

GITHUB_TOKEN ?= ""
Expand All @@ -92,10 +90,10 @@ all-push: $(addprefix push-, $(ALL_ARCH))

build: bin/$(ARCH)/$(BIN)

bin/$(ARCH)/$(BIN): .vendor
bin/$(ARCH)/$(BIN):
@echo "building: $@"
@$(MAKE) run CMD='-c " \
ARCH=$(ARCH) \
GOARCH=$(ARCH) \
VERSION=$(VERSION) \
PKG=$(PKG) \
./build/build.sh \
Expand All @@ -107,24 +105,14 @@ shell: build-dirs
-ti \
--rm \
--privileged \
-e GOPATH=/go \
-e GOROOT=/usr/local/go \
-v "$(PWD)/.go:/go" \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH):/go/bin" \
-v "$(PWD)/bin/$(ARCH):/go/bin/$$(go env GOOS)_$(ARCH)" \
-v "$(PWD)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static" \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/bash -l

.vendor:
@$(MAKE) run CMD='-c " \
PATH=$$GOPATH/bin:$$GOROOT/bin::$${PATH} \
glide install --strip-vendor \
"'
@touch $@
/bin/sh

DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION))

Expand Down Expand Up @@ -168,7 +156,7 @@ deploy: release-controller .deploy-$(DOTFILE_IMAGE)
bundle.yaml.in > .deploy-$(DOTFILE_IMAGE)
@kubectl apply -f .deploy-$(DOTFILE_IMAGE)

test: .vendor build-dirs
test: build-dirs
@$(MAKE) run CMD='-c "./build/test.sh $(SRC_DIRS)"'

codegen:
Expand Down Expand Up @@ -205,33 +193,27 @@ ifeq ($(DOCKER_BUILD),"true")
@echo "running CMD in the containerized build environment"
@docker run \
--rm \
-e GOPATH=/go \
-e GOROOT=/usr/local/go \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-v "${HOME}/.kube:/root/.kube" \
-v "$(PWD)/.go:/go" \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH):/go/bin" \
-v "$(PWD)/bin/$(ARCH):/go/bin/$$(go env GOOS)_$(ARCH)" \
-v "$(PWD)/bin/$(ARCH)/$$(go env GOOS)_$(ARCH):/go/bin" \
-v "$(PWD)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static" \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/bash $(CMD)
/bin/sh $(CMD)
else
@/bin/bash $(CMD)
endif

clean: dotfile-clean bin-clean vendor-clean
clean: dotfile-clean bin-clean

dotfile-clean:
rm -rf .container-* .dockerfile-* .push-* .vendor .deploy-*

bin-clean:
rm -rf .go bin

vendor-clean:
rm -rf vendor

release-docs: docs
@if [ -z ${AWS_ACCESS_KEY_ID} ] || [ -z ${AWS_SECRET_ACCESS_KEY} ]; then\
echo "Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Exiting.";\
Expand Down
10 changes: 1 addition & 9 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@ if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
if [ -z "${ARCH}" ]; then
echo "ARCH must be set"
exit 1
fi
if [ -z "${VERSION}" ]; then
echo "VERSION must be set"
exit 1
fi

export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

export CGO_ENABLED=0
export GOARCH="${ARCH}"

go install -v \
-installsuffix "static" \
-ldflags "-X ${PKG}/pkg/version.VERSION=${VERSION}" \
./...
./cmd/...
1 change: 1 addition & 0 deletions build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set -o nounset
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

export CGO_ENABLED=0
export GO111MODULE=on

TARGETS=$(for d in "$@"; do echo ./$d/...; done)

Expand Down
16 changes: 16 additions & 0 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.12.4-alpine3.9
MAINTAINER Tom Manville <tom@kasten.io>

RUN apk add --update --no-cache ca-certificates bash git \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*

COPY --from=bitnami/kubectl:1.13.4 /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/

COPY --from=goreleaser/goreleaser:v0.112.2 /bin/goreleaser /usr/local/bin/

ENV CGO_ENABLED=0 \
GO111MODULE="on" \
GOROOT="/usr/local/go" \
GO_EXTLINK_ENABLED=0 \
PATH="/usr/local/go/bin:${PATH}"
Loading

0 comments on commit 9ef1611

Please sign in to comment.