Skip to content

Commit

Permalink
Run all CI commands inside the build container #209
Browse files Browse the repository at this point in the history
## Change Overview
* Performance improvements
  * Use simple travis VM since all commands are containerized
  * Use https://docs.travis-ci.com/user/caching/
    * go mod source files
    * go build cache
  * Parallel jobs for docs and go tests
  * Add binaries to build image
    * kind, docker, jq
* travis config simplificiations
  * uses start/stop-kind instead of directly invoking local_kube.sh 
* Makefile updates
  * Use tabs consistently
  * add go-mod-download
  * add release-snapshot

## Pull request type

Please check the type of change your PR introduces:
- [ ] Work in Progress
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Trival/Minor
- [ ] Bugfix
- [x] Feature
- [ ] Documentation
  • Loading branch information
tdmanv committed Aug 15, 2019
2 parents 0041a02 + f76bfa0 commit 77cbb4b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dockers:
- binaries:
- controller
image_templates:
- 'kanisterio/kanister-controller:{{ .Tag }}'
- 'kanisterio/controller:{{ .Tag }}'
dockerfile: 'docker/controller/Dockerfile'
- binaries:
- kando
Expand Down
50 changes: 27 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
sudo: required
services:
- docker

language: go
services:
- docker

go:
- "1.12.x"
# Selecting C as the language keeps the container to a minimum footprint. All
# go-specifc code is run in build container.
language: c

branches:
only:
- master

# This moves Kubernetes specific config files.
env:
- CHANGE_MINIKUBE_NONE_USER=true GO111MODULE=on

before_install:
- wget --progress=dot:mega https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/amd64/kubectl
- sudo chmod +x kubectl
- sudo mv kubectl /usr/local/bin/kubectl

script:
- go mod download
- sudo make build
- make docs
- docker run -ti --rm --net host -e GOPATH=/go -v ${GOPATH}:/go -v /var/run/docker.sock:/var/run/docker.sock -v ${HOME}/.kube:/root/.kube -v $(pwd):/data -w /data --entrypoint="bash" kanisterio/build:v0.0.1 -c "bash build/local_kubernetes.sh start_localkube"
- sudo make test

after_script:
- docker run -ti --rm --net host -e GOPATH=/go -v ${GOPATH}:/go -v /var/run/docker.sock:/var/run/docker.sock -v ${HOME}/.kube:/root/.kube -v $(pwd):/data -w /data --entrypoint="bash" kanisterio/build:v0.0.1 -c "bash build/local_kubernetes.sh stop_localkube"
cache:
directories:
- .go/pkg/mod/cache
- .go/cache

jobs:
include:
- stage: test
script:
- make docs
- stage: test
install:
- make go-mod-download
before_script:
- make start-kind
script:
- make build
- make test
before_cache:
- sudo chown -R travis:travis ./.go
after_script:
- make stop-kind

97 changes: 52 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ IMAGE_NAME := $(BIN)

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

BUILD_IMAGE ?= kanisterio/build:v0.0.1
BUILD_IMAGE ?= kanisterio/build:v0.0.4
DOCS_BUILD_IMAGE ?= kanisterio/docker-sphinx

DOCS_RELEASE_BUCKET ?= s3://docs.kanister.io
Expand Down Expand Up @@ -101,18 +101,19 @@ bin/$(ARCH)/$(BIN):
# Example: make shell CMD="-c 'date > datefile'"
shell: build-dirs
@echo "launching a shell in the containerized build environment"
@docker run \
-ti \
--rm \
--privileged \
--net host \
-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 /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
@docker run \
-ti \
--rm \
--privileged \
--net host \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD)/.go/cache:/go/.cache" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH):/go/bin" \
-v "$(PWD)/bin/$(ARCH):/go/bin/$$(go env GOOS)_$(ARCH)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh

DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION))
Expand Down Expand Up @@ -147,23 +148,21 @@ push-name:
version:
@echo $(VERSION)

.PHONY: deploy test codegen build-dirs run clean container-clean bin-clean vendor-clean docs start-kind stop-kind
.PHONY: deploy test codegen build-dirs run clean container-clean bin-clean docs start-kind stop-kind release-snapshot go-mod-download

deploy: release-controller .deploy-$(DOTFILE_IMAGE)
.deploy-$(DOTFILE_IMAGE):
@sed \
-e 's|IMAGE|$(IMAGE)|g' \
-e 's|TAG|$(VERSION)|g' \
bundle.yaml.in > .deploy-$(DOTFILE_IMAGE)
-e 's|IMAGE|$(IMAGE)|g' \
-e 's|TAG|$(VERSION)|g' \
bundle.yaml.in > .deploy-$(DOTFILE_IMAGE)
@kubectl apply -f .deploy-$(DOTFILE_IMAGE)

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

codegen:
@$(MAKE) run CMD='-c " \
./build/codegen.sh \
"'
@$(MAKE) run CMD='-c "./build/codegen.sh"'

DOCS_CMD = "cd docs && make clean && \
doc8 --max-line-length 90 --ignore D000 . && \
Expand All @@ -173,12 +172,12 @@ DOCS_CMD = "cd docs && make clean && \
docs:
ifeq ($(DOCKER_BUILD),"true")
@echo "running DOCS_CMD in the containerized build environment"
@docker run \
--entrypoint '' \
--rm \
-v "$(PWD):/repo" \
-w /repo \
$(DOCS_BUILD_IMAGE) \
@docker run \
--entrypoint '' \
--rm \
-v "$(PWD):/repo" \
-w /repo \
$(DOCS_BUILD_IMAGE) \
/bin/bash -c $(DOCS_CMD)
else
@/bin/bash -c $(DOCS_CMD)
Expand All @@ -191,18 +190,19 @@ build-dirs:
run: build-dirs
ifeq ($(DOCKER_BUILD),"true")
@echo "running CMD in the containerized build environment"
@docker run \
--rm \
--net host \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-v "${HOME}/.kube:/root/.kube" \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH)/$$(go env GOOS)_$(ARCH):/go/bin" \
-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) \
@docker run \
--rm \
--net host \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-v "${HOME}/.kube:/root/.kube" \
-v "$(PWD)/.go/pkg:/go/pkg" \
-v "$(PWD)/.go/cache:/go/.cache" \
-v "$(PWD):/go/src/$(PKG)" \
-v "$(PWD)/bin/$(ARCH)/$$(go env GOOS)_$(ARCH):/go/bin" \
-v "$(PWD)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh $(CMD)
else
@/bin/bash $(CMD)
Expand All @@ -211,23 +211,23 @@ endif
clean: dotfile-clean bin-clean

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

bin-clean:
rm -rf .go bin

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.";\
exit 1;\
echo "Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Exiting.";\
exit 1;\
fi;\

@if [ -f "docs/_build/html/index.html" ]; then\
aws s3 sync docs/_build/html $(DOCS_RELEASE_BUCKET) --delete;\
echo "Success";\
aws s3 sync docs/_build/html $(DOCS_RELEASE_BUCKET) --delete;\
echo "Success";\
else\
echo "No built docs found";\
exit 1;\
echo "No built docs found";\
exit 1;\
fi;\

release-helm:
Expand All @@ -236,8 +236,15 @@ release-helm:
release-kanctl:
@$(MAKE) run CMD='-c "./build/release_kanctl.sh"'

release-snapshot:
@$(MAKE) run CMD='-c "goreleaser --debug release --rm-dist --snapshot"'

go-mod-download:
@$(MAKE) run CMD='-c "go mod download"'

start-kind:
@$(MAKE) run CMD='-c "./build/local_kubernetes.sh start_localkube"'

stop-kind:
@$(MAKE) run CMD='-c "./build/local_kubernetes.sh stop_localkube"'

2 changes: 1 addition & 1 deletion build/release_kanctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ then
echo "You can generate a token here: https://github.com/settings/tokens/new"
exit 1
fi
goreleaser --rm-dist
goreleaser release --parallelism=1 --rm-dist
14 changes: 9 additions & 5 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM golang:1.12.4-alpine3.9
FROM golang:1.12-alpine3.10
MAINTAINER Tom Manville <tom@kasten.io>

RUN apk add --update --no-cache ca-certificates bash git \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*
RUN apk add --update --no-cache ca-certificates bash git docker jq \
&& 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/
COPY --from=goreleaser/goreleaser:v0.115.0 /bin/goreleaser /usr/local/bin/

RUN wget -O /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.4.0/kind-linux-amd64 \
&& chmod +x /usr/local/bin/kind

ENV CGO_ENABLED=0 \
GO111MODULE="on" \
GOROOT="/usr/local/go" \
GOCACHE=/go/.cache/go-build \
GO_EXTLINK_ENABLED=0 \
PATH="/usr/local/go/bin:${PATH}"

0 comments on commit 77cbb4b

Please sign in to comment.