Skip to content

Commit

Permalink
Merge pull request kubevirt#634 from rmohr/dockerized
Browse files Browse the repository at this point in the history
Dockerized build
  • Loading branch information
rmohr authored Jan 11, 2018
2 parents 29d14ee + af145bd commit 6b3d4c6
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ cluster/local/certs
**.pem
**.crt
**.csr
_out
38 changes: 11 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,28 @@ go:
- 1.8
- 1.9

before_install:
- sudo add-apt-repository ppa:jacob/virtualisation -y
- sudo apt-get update -q
env:
- BUILDER_NAME="kubevirt/${TRAVIS_JOB_ID}builder"

install:
- git reset --hard # we are caching the vendor folder, make sure we see the new vendor.json file
- go get github.com/mattn/goveralls
- go get -u github.com/Masterminds/glide
- go get golang.org/x/tools/cmd/goimports
- go get -u mvdan.cc/sh/cmd/shfmt
- go get -u github.com/golang/mock/gomock
- go get -u github.com/rmohr/mock/mockgen
- go get -u github.com/rmohr/go-swagger-utils/swagger-doc
- go get -u github.com/onsi/ginkgo/ginkgo
- go get -u k8s.io/code-generator/cmd/deepcopy-gen
- go get -u k8s.io/code-generator/cmd/defaulter-gen
- sudo apt-get install libvirt-dev make
- make sync
- git reset --hard
- ./hack/dockerized make sync

script:
- make fmt fmt-bash
- ./hack/dockerized make fmt fmt-bash
- if git diff --name-only | grep '.*.go'; then echo "It seems like you did not run
`make fmt fmt-bash`. Please run it and commit the changes"; false; fi
- make generate
- make fmt
- ./hack/dockerized make generate fmt
- if git diff --name-only | grep 'generated.*.go'; then echo "Content of generated
files changed. Please regenerate and commit them."; false; fi
- if git diff --name-only | grep 'swagger.json' ; then echo "Content of generated
files changed. Please regenerate and commit them." ; false ; fi
- if diff <(git grep -c '') <(git grep -cI '') | egrep -v 'docs/.*\.png|swagger-ui'
| grep '^<'; then echo "Binary files are present in git repostory."; false; fi
- make check
- make build
- if [[ $TRAVIS_REPO_SLUG == "kubevirt/kubevirt" ]]; then $HOME/gopath/bin/goveralls
-service=travis-ci -package=./pkg/... -ignore=$(find -regextype posix-egrep -regex ".*generated_mock.*\.go|.*swagger_generated\.go" -printf
"%P\n" | paste -d, -s) ; else make test; fi
- make apidocs
- ./hack/dockerized make check
- ./hack/dockerized make build
- if [[ $TRAVIS_REPO_SLUG == "kubevirt/kubevirt" ]]; then ./hack/dockerized make goveralls TRAVIS_JOB_ID=${TRAVIS_JOB_ID} TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} TRAVIS_BRANCH=${TRAVIS_BRANCH}; else ./hack/dockerized make test; fi
- ./hack/dockerized make apidocs
- make manifests DOCKER_TAG=$TRAVIS_TAG # falls back to latest if not on a tag

cache:
Expand All @@ -74,9 +59,8 @@ deploy:
secure: dy3AlSki7p9sRjItOiWoPv4s28+hZ9wMcuvtZv0bWHbEZ7y/EvzXcwWmn+/Tjjk4Np59LImUjJw1E5Yv2Q16ViuNwKbX7TA7fu+wAcTz4DF4wFLIrJBcCRetiud4175aJ1ylOvmtHOuWHfo6Wx5HRxRT0fLcMFdSoagpe4Dh7BJYfI4Sgu/jghMMJ4wcDsMLZqi6RRM6jywFXQXMmBY87E57/ZLlXZ5Nud5RoWXJxfFfc/vTn/frCBu7r+JW8ayGeGVPEkEMtWX1huWnIvVjNu1twuZnL3zWmLNmpFXfk3j/gLbdIwLn3jgtariNz/Rvigqaj18F0Fa/QNL6VcruqgXd6ryWxmGm9sD6MYC3kk0HoqwSI7WBf88tlfz27FR+cHFZtjTBXnZHBtM5skuzUpT4kUKhLkwcfgA5PmoW/7NcmnN0eKvOQuQYq/8pREwdmYAvYsGPWJZjNYHBCv9KRT1lDRN5jRLMi5wn7NWFMR1p+mbdHyd7i43zM8gnumqvGF/chZ9PEH38hnm835RZAwnzdJ3EQ4YFAaOE2AaUBe9Yw1FP6f22MOC8+N9CY+a1AlGQBmovPjaf+x4f+Jx6y9jjxahJpoXxEKgeFvfSVUoKbkMPMOHxMAb0UL9Rqq3BhlLnPQIjcwdCZU/+wTcV/sFHdcnIqdl9/wb/L+mMjOs=
file_glob: true
file:
- cmd/virtctl/virtctl-*
- _out/cmd/virtctl/virtctl-*
- manifests/release/kubevirt.yaml
- manifests/release/spice-proxy.yaml
prerelease: true
on:
tags: true
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ generate: sync
tools/openapispec/openapispec --dump-api-spec-path api/openapi-spec/swagger.json

apidocs: generate
docker run -u `stat -c "%u" hack/gen-swagger-doc/` --rm \
-v ${PWD}:/home/gradle/kubevirt:rw,z \
-w /home/gradle/kubevirt \
gradle \
bash hack/gen-swagger-doc/gen-swagger-docs.sh v1 html
./hack/gen-swagger-doc/gen-swagger-docs.sh v1 html

build: checksync fmt vet compile

goveralls:
./hack/goveralls.sh

compile:
./hack/build-go.sh install ${WHAT}

Expand All @@ -42,11 +41,11 @@ test: build
./hack/build-go.sh test ${WHAT}

functest:
./hack/build-go.sh functest ${WHAT}
./hack/functests.sh

clean:
./hack/build-go.sh clean ${WHAT}
rm ./bin -rf
rm _out/ -rf
rm tools/openapispec/openapispec -rf

distclean: clean
Expand All @@ -56,8 +55,8 @@ distclean: clean
glide cc

checksync:
test -f .glide.yaml.hash || ${HASH} glide.yaml > .glide.yaml.hash
if [ "`${HASH} glide.yaml`" != "`cat .glide.yaml.hash`" ]; then \
@test -f .glide.yaml.hash || ${HASH} glide.yaml > .glide.yaml.hash
@if [ "`${HASH} glide.yaml`" != "`cat .glide.yaml.hash`" ]; then \
glide cc; \
glide update --strip-vendor; \
${HASH} glide.yaml > .glide.yaml.hash; \
Expand All @@ -70,7 +69,8 @@ sync:
glide install --strip-vendor
${HASH} glide.lock > .glide.lock.hash

docker: build
docker:
hack/dockerized make build
./hack/build-docker.sh build ${WHAT}

publish: docker
Expand Down
1 change: 1 addition & 0 deletions automation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set -e
# Build kubevirt
go get golang.org/x/tools/cmd/goimports
go get -u github.com/Masterminds/glide
go get -u github.com/onsi/ginkgo/ginkgo
make

# Make sure we can connect to kubernetes
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Copyright 2017 Red Hat, Inc.
#

FROM fedora:26
FROM fedora:27

MAINTAINER "The KubeVirt Project" <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-dhcp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Copyright 2017 Red Hat, Inc.
#

FROM fedora:26
FROM fedora:27

MAINTAINER "The KubeVirt Project" <[email protected]>

Expand Down
6 changes: 4 additions & 2 deletions cmd/virt-handler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
# Copyright 2017 Red Hat, Inc.
#

FROM fedora:26
FROM fedora:27

MAINTAINER "The KubeVirt Project" <[email protected]>

RUN dnf -y install libvirt-client genisoimage && \
ENV LIBVIRT_VERSION 3.7.0

RUN dnf -y install libvirt-client-${LIBVIRT_VERSION} genisoimage && \
groupadd --gid 107 qemu && \
useradd --uid 107 --gid 107 qemu && \
dnf -y clean all
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-launcher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Copyright 2017 Red Hat, Inc.
#

FROM fedora:26
FROM fedora:27

MAINTAINER "The KubeVirt Project" <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-migrator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Copyright 2017 Red Hat, Inc.
#

FROM fedora:26
FROM fedora:27

MAINTAINER "The KubeVirt Project" <[email protected]>

Expand Down
18 changes: 17 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ A quick start guide to get KubeVirt up and running inside Vagrant.

**Note:** Fedora 24 is known to have a bug which affects our vagrant setup.


## Building

### Dockerized building and code generating

All go-related make targets can be invoked in an included container. To build
the project within the builder-container, run

```bash
./hack/dockerized make fmt fmt-bash build
```

To generate code, run

```bash
./hack/dockerized make generate
```

If you want to build KubeVirt without docker, read on.

### Go (1.8 or higher)

[Go](https://golang.org) needs to be setup to be able to compile the sources.
Expand Down
18 changes: 12 additions & 6 deletions hack/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
set -e

source hack/config.sh
KUBEVIRT_DIR="$(
cd "$(dirname "$0")/../"
pwd
)"
OUT_DIR=$KUBEVIRT_DIR/_out/cmd/

if [ -z "$1" ]; then
target="build"
Expand All @@ -38,21 +43,22 @@ fi

for arg in $args; do
if [ "${target}" = "build" ]; then
BIN_NAME=$(basename $arg)
rsync -avz --exclude "**/*.md" --exclude "**/*.go" --exclude "**/.*" $arg/ ${OUT_DIR}/${BIN_NAME}/
# TODO the version of docker we're using in our vagrant dev environment
# does not support using ARGS in FROM field.
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
# Because of this we have to manipulate the Dockerfile for kubevirt containers
# that depend on other kubevirt containers.
cat $arg/Dockerfile | sed s/registry-disk-v1alpha/registry-disk-v1alpha\:$docker_tag/g >$arg/.GeneratedDockerfile
cat $arg/Dockerfile | sed s/registry-disk-v1alpha/registry-disk-v1alpha\:$docker_tag/g >${OUT_DIR}/${BIN_NAME}/Dockerfile
(
cd $arg
docker $target -t ${docker_prefix}/$(basename $arg):${docker_tag} -f .GeneratedDockerfile .
cd ${OUT_DIR}/${BIN_NAME}/
docker $target -t ${docker_prefix}/${BIN_NAME}:${docker_tag} .
)
rm $arg/.GeneratedDockerfile
elif [ "${target}" = "push" ]; then
(
cd $arg
docker $target ${docker_prefix}/$(basename $arg):${docker_tag}
cd ${OUT_DIR}/${BIN_NAME}/
docker $target ${docker_prefix}/${BIN_NAME}:${docker_tag}
)
fi
done
35 changes: 22 additions & 13 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
set -e

source hack/config.sh
KUBEVIRT_DIR="$(
cd "$(dirname "$0")/../"
pwd
)"
OUT_DIR=$KUBEVIRT_DIR/_out/cmd

if [ -z "$1" ]; then
target="install"
Expand All @@ -30,6 +35,7 @@ fi

if [ $# -eq 0 ]; then
args=$binaries
build_tests="true"
else
args=$@
fi
Expand All @@ -42,12 +48,6 @@ if [ $# -eq 0 ]; then
cd pkg
go ${target} -v ./...
)
elif [ "${target}" = "functest" ]; then
(
cd tests
go test -kubeconfig=${kubeconfig} -timeout 30m ${FUNC_TEST_ARGS}
)
exit
else
(
cd pkg
Expand All @@ -61,6 +61,11 @@ if [ $# -eq 0 ]; then
fi

# handle binaries

if [ "${target}" = "install" ]; then
rm -rf ${OUT_DIR}
fi

for arg in $args; do
if [ "${target}" = "test" ]; then
(
Expand All @@ -69,20 +74,24 @@ for arg in $args; do
)
elif [ "${target}" = "install" ]; then
eval "$(go env)"
ARCHBIN=$(basename $arg)-$(git describe --always)-$GOHOSTOS-$GOHOSTARCH
ALIASLNK=$(basename $arg)
rm $arg/$ALIASLNK $arg/$(basename $arg)-*-$GOHOSTOS-$GOHOSTARCH || :
BIN_NAME=$(basename $arg)
ARCHBIN=${BIN_NAME}-$(git describe --always)-${GOHOSTOS}-${GOHOSTARCH}
mkdir -p ${OUT_DIR}/${BIN_NAME}
(
cd $arg
GOBIN=$PWD go build -o $ARCHBIN
go build -o ${OUT_DIR}/${BIN_NAME}/${ARCHBIN}
(cd ${OUT_DIR}/${BIN_NAME} && ln -sf ${ARCHBIN} ${BIN_NAME})
)
mkdir -p bin
ln -sf $ARCHBIN $arg/$ALIASLNK
ln -sf ../$arg/$ARCHBIN bin/$ALIASLNK
else
(
cd $arg
go $target ./...
)
fi
done

if [[ "${target}" == "install" && "${build_tests}" == "true" ]]; then
mkdir -p ${KUBEVIRT_DIR}/_out/tests/
ginkgo build ${KUBEVIRT_DIR}/tests
mv ${KUBEVIRT_DIR}/tests/tests.test ${KUBEVIRT_DIR}/_out/tests/
fi
33 changes: 33 additions & 0 deletions hack/docker-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM fedora:27

ENV LIBVIRT_VERSION 3.7.0

RUN dnf -y install libvirt-devel-${LIBVIRT_VERSION} make git mercurial sudo gcc findutils gradle rsync-daemon rsync && \
dnf -y clean all

ENV GIMME_GO_VERSION=1.9.2

RUN mkdir -p /gimme && curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | HOME=/gimme bash >> /etc/profile.d/gimme.sh

ENV GOPATH="/go" GOBIN="/usr/bin"

ADD rsyncd.conf /etc/rsyncd.conf

RUN \
mkdir -p /go && \
source /etc/profile.d/gimme.sh && \
go get github.com/mattn/goveralls && \
go get -u github.com/Masterminds/glide && \
go get golang.org/x/tools/cmd/goimports && \
go get -u mvdan.cc/sh/cmd/shfmt && \
go get -u github.com/golang/mock/gomock && \
go get -u github.com/rmohr/mock/mockgen && \
go get -u github.com/rmohr/go-swagger-utils/swagger-doc && \
go get -u github.com/onsi/ginkgo/ginkgo && \
go get -u k8s.io/code-generator/cmd/deepcopy-gen && \
go get -u k8s.io/code-generator/cmd/defaulter-gen


ADD entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "/entrypoint.sh" ]
5 changes: 5 additions & 0 deletions hack/docker-builder/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

source /etc/profile.d/gimme.sh
export GOPATH="/root/go"
"$@"
14 changes: 14 additions & 0 deletions hack/docker-builder/rsyncd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
gid = 0
uid = 0
log file = /dev/stdout
reverse lookup = no
[build]
hosts allow = *
read only = false
path = /root/go/src/kubevirt.io/kubevirt/
comment = input sources
[out]
hosts allow = *
read only = false
path = /root/go/src/kubevirt.io/kubevirt/_out
comment = build output
Loading

0 comments on commit 6b3d4c6

Please sign in to comment.