From db0d65edcd4e440630e404ce7222c2af7a8368d1 Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Sat, 28 Jan 2017 11:16:38 -0800 Subject: [PATCH] Build into local GOPATH (_output) Signed-off-by: Jonathan Yu --- .gitignore | 22 +++++++------ .tool/lint | 2 +- Makefile | 56 +++++++++++++++++--------------- README.md | 81 +++++++++++++++++++++++++++++++++++------------ test/helpers.bash | 8 +++-- 5 files changed, 111 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 59b6efe0..799fc6da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,16 @@ -.artifacts/ -conmon/conmon -conmon/conmon.o -pause/pause -pause/pause.o +/.artifacts/ +/.vscode +/conmon/conmon +/conmon/conmon.o +/pause/pause +/pause/pause.o /docs/*.[158] /docs/*.[158].gz -ocid.conf +/_output +/ocid.conf +/test/bin2img/bin2img +/test/copyimg/copyimg +/test/testdata/redis-image +/test/checkseccomp/checkseccomp *.orig *.rej -test/bin2img/bin2img -test/copyimg/copyimg -test/testdata/redis-image -test/checkseccomp/checkseccomp diff --git a/.tool/lint b/.tool/lint index e1a12ebd..c5fef18b 100755 --- a/.tool/lint +++ b/.tool/lint @@ -5,7 +5,7 @@ set -o nounset set -o pipefail for d in $(find . -type d -not -iwholename '*.git*' -a -not -iname '.tool' -a -not -iwholename '*vendor*'); do - ${GOPATH}/bin/gometalinter \ + gometalinter \ --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ --exclude='duplicate of.*_test.go.*\(dupl\)$' \ diff --git a/Makefile b/Makefile index 575d5e64..3ef186ef 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,11 @@ ETCDIR ?= ${DESTDIR}/etc ETCDIR_OCID ?= ${ETCDIR}/ocid BUILDTAGS := selinux seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh) BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions -GOBINDIR := $(word 1,$(subst :, ,$(GOPATH))) -PATH := $(GOBINDIR)/bin:$(PATH) +SYSTEM_GOPATH := ${GOPATH} +OUTDIR ?= _output +GOPATH := $(abspath $(OUTDIR))$(if $(GOPATH),:$(GOPATH)) +GOBIN := $(OUTDIR)/bin +PATH := $(GOBIN):$(PATH) all: binaries ocid.conf docs @@ -30,14 +33,15 @@ help: @echo " * 'lint' - Execute the source code linter" @echo " * 'gofmt' - Verify the source code gofmt" -.PHONY: check-gopath +$(OUTDIR): $(OUTDIR)/.ok -check-gopath: -ifndef GOPATH - $(error GOPATH is not set) -endif +$(OUTDIR)/.ok: + mkdir -p "$(dir $(OUTDIR)/src/$(PROJECT))" + ln -s ../../../.. "$(OUTDIR)/src/$(PROJECT)" + mkdir -p $(GOBIN) + touch $@ -lint: check-gopath +lint: $(OUTDIR) @echo "checking lint" @./.tool/lint @@ -56,18 +60,20 @@ bin2img: copyimg: $(MAKE) -C test/$@ BUILDTAGS="$(BUILDTAGS)" -checkseccomp: check-gopath - $(MAKE) -C test/$@ +checkseccomp: + $(GO) test \ + -tags "$(BUILDTAGS)" \ + $(PROJECT)/test/bin2img -ocid: check-gopath +ocid: $(OUTDIR) $(GO) install \ -tags "$(BUILDTAGS)" \ $(PROJECT)/cmd/ocid -ocic: check-gopath +ocic: $(OUTDIR) $(GO) install $(PROJECT)/cmd/ocic -kpod: check-gopath +kpod: $(OUTDIR) $(GO) install $(PROJECT)/cmd/kpod ocid.conf: ocid @@ -101,21 +107,21 @@ binaries: ocid ocic kpod conmon pause bin2img copyimg checkseccomp MANPAGES_MD := $(wildcard docs/*.md) MANPAGES := $(MANPAGES_MD:%.md=%) -docs/%.1: docs/%.1.md check-gopath +docs/%.1: docs/%.1.md $(OUTDIR) go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ -docs/%.5: docs/%.5.md check-gopath +docs/%.5: docs/%.5.md $(OUTDIR) go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ -docs/%.8: docs/%.8.md check-gopath +docs/%.8: docs/%.8.md $(OUTDIR) go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ docs: $(MANPAGES) -install: check-gopath - install -D -m 755 $(GOBINDIR)/bin/ocid $(BINDIR)/ocid - install -D -m 755 $(GOBINDIR)/bin/ocic $(BINDIR)/ocic - install -D -m 755 $(GOBINDIR)/bin/kpod $(BINDIR)/kpod +install: $(OUTDIR) + install -D -m 755 $(GOBIN)/ocid $(BINDIR)/ocid + install -D -m 755 $(GOBIN)/ocic $(BINDIR)/ocic + install -D -m 755 $(GOBIN)/kpod $(BINDIR)/kpod install -D -m 755 conmon/conmon $(LIBEXECDIR)/ocid/conmon install -D -m 755 pause/pause $(LIBEXECDIR)/ocid/pause install -d -m 755 $(MANDIR)/man1 @@ -153,7 +159,7 @@ uninstall: .PHONY: .gitvalidation # When this is running in travis, it will only check the travis commit range -.gitvalidation: check-gopath +.gitvalidation: $(OUTDIR) ifeq ($(TRAVIS),true) git-validation -q -run DCO,short-subject else @@ -165,14 +171,14 @@ endif install.tools: .install.gitvalidation .install.gometalinter .install.md2man .install.gitvalidation: - go get -u github.com/vbatts/git-validation + GOPATH=${SYSTEM_GOPATH} go get -u github.com/vbatts/git-validation .install.gometalinter: - go get -u github.com/alecthomas/gometalinter - gometalinter --install + GOPATH=${SYSTEM_GOPATH} go get -u github.com/alecthomas/gometalinter + GOPATH=${SYSTEM_GOPATH} gometalinter --install .install.md2man: - go get -u github.com/cpuguy83/go-md2man + GOPATH=${SYSTEM_GOPATH} go get -u github.com/cpuguy83/go-md2man .PHONY: \ bin2img \ diff --git a/README.md b/README.md index a70b2ff6..8e5ff78f 100644 --- a/README.md +++ b/README.md @@ -38,33 +38,74 @@ It is currently in active development in the Kubernetes community through the [d ## Getting started ### Prerequisites + `runc` version 1.0.0.rc1 or greater is expected to be installed on the system. It is picked up as the default runtime by ocid. +### Build Dependencies + +**Required** + +Fedora, CentOS, RHEL, and related distributions: + +```bash +yum install -y \ + runc \ + btrfs-progs-devel \ + device-mapper-devel \ + glib2-devel \ + glibc-devel \ + gpgme-devel \ + libassuan-devel \ + libgpg-error-devel +``` + +Debian, Ubuntu, and related distributions: + +```bash +apt install -y \ + runc \ + btrfs-tools \ + libassuan-dev \ + libdevmapper-dev \ + libglib2.0-dev \ + libc6-dev \ + libgpgme11-dev \ + libgpg-error-dev +``` + +If using an older release or a long-term support release, be careful to double-check that the version of `runc` is new enough, or else build your own. + +**Optional** + +Fedora, CentOS, RHEL, and related distributions: + +```bash +yum install -y \ + libseccomp-devel \ + libapparmor +``` + +Debian, Ubuntu, and related distributions: + +```bash +apt install -y \ + libseccomp-dev \ + libapparmor-dev +``` + ### Build -`btrfs-progs-devel`, `device-mapper-devel`, `glib2-devel`, `glibc-devel`, `gpgme-devel`, `libassuan-devel`, `libgpg-error-devel`, and `pkg-config` packages on CentOS/Fedora or `btrfs-tools`, `libassuan-dev`, `libc6-dev`, `libdevmapper-dev`, `libglib2.0-dev`, `libgpg-error-dev`, `libgpgme11-dev`, and `pkg-config` on Ubuntu or equivalent is required. -In order to enable seccomp support you will need to install development files for `libseccomp` on your platform. -> e.g. `libseccomp-devel` for CentOS/Fedora, or `libseccomp-dev` for Ubuntu -In order to enable apparmor support you will need to install development files for `libapparmor` on your platform. -> e.g. `libapparmor-dev` for Ubuntu - ```bash -$ GOPATH=/path/to/gopath -$ mkdir $GOPATH -$ go get -d github.com/kubernetes-incubator/cri-o -$ cd $GOPATH/src/github.com/kubernetes-incubator/cri-o -$ make install.tools -$ make -$ sudo make install -``` -Otherwise, if you do not want to build `cri-o` with seccomp support you can add `BUILDTAGS=""` when running make. - -```bash -# create a 'github.com/kubernetes-incubator' in your $GOPATH/src -cd github.com/kubernetes-incubator -git clone https://github.com/kubernetes-incubator/cri-o +git clone https://github.com/kubernetes-incubator/cri-o # or your fork cd cri-o +make install.tools +make +sudo make install +``` +To avoid building `cri-o` with seccomp support, add `BUILDTAGS=""` when running `make` instead: + +```bash make BUILDTAGS="" sudo make install ``` diff --git a/test/helpers.bash b/test/helpers.bash index 33d66d65..790c3c3b 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -9,10 +9,14 @@ TESTDATA="${INTEGRATION_ROOT}/testdata" # Root directory of the repository. OCID_ROOT=${OCID_ROOT:-$(cd "$INTEGRATION_ROOT/../.."; pwd -P)} +# Installation directory for Go binaries +GOPATH=${GOPATH:-${OCID_ROOT}/cri-o/_output} +GOBIN=${GOBIN:-${GOPATH}/bin} + # Path of the ocid binary. -OCID_BINARY=${OCID_BINARY:-${GOPATH}/bin/ocid} +OCID_BINARY=${OCID_BINARY:-${GOBIN}/ocid} # Path of the ocic binary. -OCIC_BINARY=${OCIC_BINARY:-${GOPATH}/bin/ocic} +OCIC_BINARY=${OCIC_BINARY:-${GOBIN}/ocic} # Path of the conmon binary. CONMON_BINARY=${CONMON_BINARY:-${OCID_ROOT}/cri-o/conmon/conmon} # Path of the pause binary.