Skip to content

Commit

Permalink
Fix building iso issues and rectify documents
Browse files Browse the repository at this point in the history
Correct readme for building iso since docker is required now.

Use PKGMGR as var name for tdnf and yum to keep consistence
with other scripts in build-image.sh and docker-iso-build.sh.

Use docker info to determine if docker-iso-build.sh is running
in a container or not.

Move defining environment variable TERM to Dockerfile.

Add comments in Dockerfile to show what are these images used
for and how to use them and list packages for detail usages.

Change base yum os to centos:6.9 which is more close to rehl
6.9.

Remove duplicated steps of package installation in
Dockerfile.yum.

Remove bootstrap-debug and bootstrap-staging-debug since it
is not maintained.

Remove hard coding on entropy configure path.

Remove a debug scrip that was not being used or maintained.

Add necessary packages and checks to the Dockerfiles for the build
images and checks for packages in related scripts.

Go 1.8.7 generates binaries that are incompatible with the 2.6.32
kernel. We see "FATAL: kernel too old" to execute tether. Use
go 1.8.6 instead.

Sets the expected build context to be infra/build-image so that we don't
send a huge build context to build a tiny image.

Restores the function that allows specification of branches and pull
requests but in such a way that current usage is preserved.

Because make iso and unit test use different image, separate
them to different step in drone configuration.

Remove using CI repo and use photon-2.0 directly for CI build.
  • Loading branch information
DanielXiao committed Nov 6, 2018
1 parent a0a1753 commit f9a0c67
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 188 deletions.
8 changes: 3 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pipeline:
when:
status: success

vic-engine-isos:
vic-engine:
image: 'gcr.io/eminent-nation-87317/vic-build-image:tdnf'
pull: true
environment:
Expand All @@ -71,11 +71,11 @@ pipeline:
- codecov_token
commands:
- export BUILD_NUMBER=${DRONE_BUILD_NUMBER}
- make isos
- make all
when:
status: success

vic-engine:
vic-unit-test:
image: 'wdc-harbor-ci.eng.vmware.com/default-project/vic-integration-test:1.48'
pull: true
environment:
Expand All @@ -88,8 +88,6 @@ pipeline:
- github_automation_api_key
- codecov_token
commands:
- export BUILD_NUMBER=${DRONE_BUILD_NUMBER}
- make all
- tests/unit-test-check.sh
when:
status: success
Expand Down
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ bootstrap := $(BIN)/bootstrap.iso
bootstrap-custom := $(BIN)/bootstrap-$(REPO).iso
bootstrap-staging := $(BIN)/.bootstrap-staging.tgz
bootstrap-staging-custom := $(BIN)/.bootstrap-staging-$(REPO).tgz
bootstrap-staging-debug := $(BIN)/.bootstrap-staging-debug.tgz
bootstrap-debug := $(BIN)/bootstrap-debug.iso
iso-base := $(BIN)/.iso-base-photon-2.0.tgz
iso-base-custom := $(BIN)/.iso-base-$(REPO).tgz

Expand Down Expand Up @@ -143,8 +141,6 @@ bootstrap: $(bootstrap)
bootstrap-custom: $(bootstrap-custom)
bootstrap-staging: $(bootstrap-staging)
bootstrap-staging-custom: $(bootstrap-staging-custom)
bootstrap-debug: $(bootstrap-debug)
bootstrap-staging-debug: $(bootstrap-staging-debug)
iso-base: $(iso-base)
iso-base-custom: $(iso-base-custom)

Expand Down Expand Up @@ -444,10 +440,6 @@ $(bootstrap-custom): isos/bootstrap.sh $(tether-linux) $(archive) $(bootstrap-st
@echo "Making custom bootstrap iso"
@$(TIME) $(DOCKER_BUILD) -d $(REPO) $< -p $(bootstrap-staging-custom) -b $(BIN) -o $(notdir $@)

$(bootstrap-debug): isos/bootstrap.sh $(tether-linux) $(archive) $(rpctool) $(bootstrap-staging-debug) isos/bootstrap/*
@echo "Making bootstrap-debug iso"
@$(TIME) $(DOCKER_BUILD) $< -p $(bootstrap-staging-debug) -b $(BIN) -d true

$(bootstrap-staging): isos/bootstrap-staging.sh $(iso-base) isos/base/repos/photon-2.0/*
@echo staging for bootstrap
@$(TIME) $(DOCKER_BUILD) $< -c $(BIN)/.yum-cache-photon-2.0.tgz -p $(iso-base) -o $@
Expand All @@ -456,11 +448,6 @@ $(bootstrap-staging-custom): isos/bootstrap-staging.sh $(iso-base-custom) isos/b
@echo custom staging for bootstrap
@$(TIME) $(DOCKER_BUILD) -d $(REPO) $< -c $(BIN)/.yum-cache-$(REPO).tgz -p $(iso-base-custom) -o $@

$(bootstrap-staging-debug): isos/bootstrap-staging.sh $(iso-base)
@echo staging debug for bootstrap
@$(TIME) $(DOCKER_BUILD) $< -c $(BIN)/.yum-cache-photon-2.0.tgz -p $(iso-base) -o $@ -d true


# vic-machine targets
$(vic-machine-linux): $$(call godeps,cmd/vic-machine/*.go)
@echo building vic-machine linux...
Expand Down
34 changes: 9 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ See [CONTRIBUTING](CONTRIBUTING.md) for details on submitting changes and the co

## Building

Building the project is done with a combination of make and containers, with golang:1.8 being the common container base. This is done so that it's possible to build directly, without a functional docker, if using a Debian based system with the Go 1.8 toolchain and Drone.io installed.
Building the project is done with a combination of make and containers, with gcr.io/eminent-nation-87317/vic-build-image:tdnf being the common container base. This requires Docker installed. If gcr.io is not accessible you can follow the steps in [Dockerfile](infra/build-image/Dockerfile.tdnf) to build this image.

To build as closely as possible to the formal build:
To build as closely as possible to the formal build, you need the Go 1.8 toolchain and Drone.io installed:
```shell
drone exec
```

To build inside a Docker container:
```shell
docker run -v $(pwd):/go/src/github.com/vmware/vic -w /go/src/github.com/vmware/vic golang:1.8 make all
docker run -v $(pwd):/go/src/github.com/vmware/vic gcr.io/eminent-nation-87317/vic-build-image:tdnf make all
```

To build directly:
To build directly, you also need the Go 1.8 toolchain installed:
```shell
make all
```
Expand Down Expand Up @@ -131,35 +131,19 @@ This will install the [gvt](https://github.com/FiloSottile/gvt) utility and retr
## Building the ISOs

The component binaries above are packaged into ISO files, appliance.iso and bootstrap.iso, that are used by the installer. The generation of the ISOs is split into the following targets:
iso-base, appliance-staging, bootstrap-staging, appliance, and bootstrap. Generation of the ISOs involves authoring a new root filesystem, meaning running a package manager (currently yum) and packing/unpacking archives. To install packages and preserve file permissions while unpacking these steps should be run as root, whether directly or in a container. To generate the ISOs:

```shell
make isos
```

The appliance and bootstrap ISOs are bootable CD images used to start the VMs that make up VIC Engine. To build the image using [docker](https://www.docker.com/), ensure `GOPATH` is set and `docker` is installed, then issue the following.
`iso-base, appliance-staging, bootstrap-staging, appliance, and bootstrap`

```shell
docker run -v $(pwd):/go/src/github.com/vmware/vic -w /go/src/github.com/vmware/vic golang:1.8 make isos
```

Alternatively, the iso image can be built locally. Again, ensure `GOPATH` is set, but also ensure the following packages are installed. This will attempt to install the following packages if not present using apt-get:
Generation of the ISOs involves authoring a new root filesystem, meaning running a package manager (currently tdnf) and packing/unpacking archives. This is done with gcr.io/eminent-nation-87317/vic-build-image:tdnf being the build container. This requires Docker installed. If gcr.io is not accessible you can follow the steps in [Dockerfile](infra/build-image/Dockerfile.tdnf) to build this image. To generate the ISOs:

```shell
apt-get install \
curl \
cpio \
tar \
xorriso \
rpm \
ca-certificates \
yum
make isos
```

Package names may vary depending on the distribution being used. Once installed, issue the following (the targets listed here are those executed when using the `iso` target.
The appliance and bootstrap ISOs are bootable CD images used to start the VMs that make up VIC Engine. To build the image, issue the following.

```shell
make iso-base appliance-staging appliance bootstrap-staging bootstrap
docker run -v $(pwd):/go/src/github.com/vmware/vic gcr.io/eminent-nation-87317/vic-build-image:tdnf make isos
```

The iso image will be created in `$BIN`
Expand Down
4 changes: 2 additions & 2 deletions cmd/tether/entropy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
"io/ioutil"
"os"
"os/exec"
"path"
"strings"

log "github.com/Sirupsen/logrus"

"github.com/vmware/vic/lib/tether"
)

// TODO(morris-jason): Not sure this is the best file path. Open to suggestions.
const entropyConfigPath = "/.tether/opt/config/entropy.txt"
var entropyConfigPath = path.Join(tether.BindSys.Root, "opt/config/entropy.txt")

// Entropy is a tether extension that wraps command
type Entropy struct {
Expand Down
44 changes: 28 additions & 16 deletions infra/build-image/Dockerfile.tdnf
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
# docker build -t vic-build-image-tdnf -f infra/build-image/Dockerfile.tdnf .
# This is an image used for building bootstrap.iso and application.iso with photon 2.0 operate system.
#
# To use this image:
# docker run -v $(pwd):/go/src/github.com/vmware/vic gcr.io/eminent-nation-87317/vic-build-image:tdnf make most
#
# To build this image:
# docker build -t vic-build-image-tdnf -f infra/build-image/Dockerfile.tdnf infra/build-image/
# docker tag vic-build-image-tdnf gcr.io/eminent-nation-87317/vic-build-image:tdnf
# gcloud auth login
# gcloud docker -- push gcr.io/eminent-nation-87317/vic-build-image:tdnf

FROM vmware/photon:2.0
FROM photon:2.0

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $PATH:${GOPATH}/bin:/${GOROOT}/bin
ENV SRCDIR ${GOPATH}/src/github.com/vmware/vic
ENV TERM linux
ENV VIC_CACHE_DEPS=1

WORKDIR ${SRCDIR}

# gawk added purely for tolower function used in Makefile
# rpm used for initialize_bundle - tdnf seems to require rpm -initdb to work
# kmod is needed for depmod command
# need the following for configure
# expr for xorriso configure which toybox doesn't have
# Go compilation step requires the following
# sed
# gcc
# binutils
# glibc-devel
# linux-api-headers - like kernel-headers but named this
# binutils
# glibc-devel
# linux-api-headers - like kernel-headers but named this
# findutils - for xargs for go-deps script (also in toybox if not using coreutils)
# cpio - this ensures that we don't need to change the vic scripts based on toybox or not-toybox
# it seems that erasing toybox automatically installs coreutils
RUN tdnf erase -y toybox && tdnf install -y jq cpio git tar gzip make xz gawk rpm kmod sed gcc binutils glibc-devel linux-api-headers findutils

ADD https://dl.google.com/go/go1.8.7.linux-amd64.tar.gz /tmp/go.tgz
# which is used to check for other utilities
# jq is used for parse repo-spec.json
# git is used for retrieving tag and commit information
# tar gzip xz are used for compression
# make for Makefile
# xorriso is used for building iso file
RUN tdnf erase -y toybox && \
tdnf install -y jq cpio git tar gzip make xz gawk rpm kmod sed which \
gcc binutils glibc-devel linux-api-headers findutils xorriso

ADD https://dl.google.com/go/go1.8.6.linux-amd64.tar.gz /tmp/go.tgz
RUN cd /usr/local && tar -zxf /tmp/go.tgz

ADD https://www.gnu.org/software/xorriso/xorriso-1.4.8.tar.gz /usr/local/src/xorriso.tgz
RUN cd /usr/local/src && tar -zxf xorriso.tgz
RUN cd /usr/local/src/xorriso-1.4.8 && ./configure && make && make install && make distclean

RUN mkdir -p ${SRCDIR}

COPY infra/build-image/setup-repo.sh /usr/local/bin
COPY setup-repo.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/setup-repo.sh

# ENTRYPOINT [ "/usr/local/bin/setup-repo.sh" ]
ENTRYPOINT [ "/usr/local/bin/setup-repo.sh" ]
50 changes: 32 additions & 18 deletions infra/build-image/Dockerfile.yum
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
# docker build -t vic-build-image-yum -f infra/build-image/Dockerfile.yum .
# This is an image used for building bootstrap.iso and application.iso with centos 6.9 operate system.
#
# To use this image:
# docker run -v $(pwd):/go/src/github.com/vmware/vic gcr.io/eminent-nation-87317/vic-build-image:yum make most
#
# To build this image:
# docker build -t vic-build-image-yum -f infra/build-image/Dockerfile.yum infra/build-image/
# docker tag vic-build-image-yum gcr.io/eminent-nation-87317/vic-build-image:yum
# gcloud auth login
# gcloud docker -- push gcr.io/eminent-nation-87317/vic-build-image:yum

FROM centos:7
FROM centos:6.9

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $PATH:${GOPATH}/bin:/${GOROOT}/bin
ENV SRCDIR ${GOPATH}/src/github.com/vmware/vic
ENV TERM linux
ENV VIC_CACHE_DEPS=1

WORKDIR ${SRCDIR}

# rpm used for initialize_bundle - yum seems to require rpm -initdb to work
# Go compilation step requires the following
# sed
# gcc
# binutils
# glibc-devel
# glibc-static
# cpio - this ensures that we don't need to change the vic scripts based on toybox or not-toybox
# it seems that erasing toybox automatically installs coreutils
# jq is used for parse repo-spec.json
# git is used for retrieving tag and commit information
# tar gzip xz are used for compression
# make for Makefile
# xorriso is used for building iso file
# epel-release allow yum to install packages and dependencies
RUN set -ex; \
yum install -y epel-release; \
yum install -y \
jq cpio git tar gzip make rpm kmod sed gcc \
binutils glibc-devel wget;

RUN set -ex; \
yum install -y epel-release;

RUN set -ex; \
yum install -y xorriso;

RUN set -ex; \
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64; \
mv jq-linux64 jq; \
install -t /usr/local/bin jq;
jq cpio git tar gzip make rpm sed gcc \
binutils glibc-devel xorriso glibc-static;

ADD https://dl.google.com/go/go1.8.7.linux-amd64.tar.gz /tmp/go.tgz
ADD https://dl.google.com/go/go1.8.6.linux-amd64.tar.gz /tmp/go.tgz
RUN cd /usr/local && tar -zxf /tmp/go.tgz

RUN mkdir -p ${SRCDIR}

COPY infra/build-image/setup-repo.sh /usr/local/bin
COPY setup-repo.sh /usr/local/bin
RUN chmod a+x /usr/local/bin/setup-repo.sh

# ENTRYPOINT [ "/usr/local/bin/setup-repo.sh" ]
ENTRYPOINT [ "/usr/local/bin/setup-repo.sh" ]
17 changes: 10 additions & 7 deletions infra/build-image/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file builds the docker images vic-build-image.tdnf vic-build-image.yum
# when there are changes to the dockerfiles that warrant an image update in gcr.
set -ex;

REV=$(git rev-parse --verify --short=8 HEAD)
REPO="gcr.io/eminent-nation-87317"
REGISTRY="gcr.io/eminent-nation-87317"
IMAGE="vic-build-image"

for DEP in yum tdnf; do
docker build -t "$IMAGE-$DEP:$REV" -f ./infra/build-image/Dockerfile.$DEP .
docker tag "$IMAGE-$DEP:$REV" "$REPO/$IMAGE:$DEP"
docker tag "$IMAGE-$DEP:$REV" "$REPO/$IMAGE:$DEP-$REV"
# gcloud docker -- push "$REPO/$IMAGE:$DEP"
# gcloud docker -- push "$REPO/$IMAGE:$DEP-$REV"
for PKGMGR in yum tdnf; do
docker build -t "$IMAGE-$PKGMGR:$REV" -f ./infra/build-image/Dockerfile.$PKGMGR ./infra/build-image
docker tag "$IMAGE-$PKGMGR:$REV" "$REGISTRY/$IMAGE:$PKGMGR"
docker tag "$IMAGE-$PKGMGR:$REV" "$REGISTRY/$IMAGE:$PKGMGR-$REV"
# gcloud docker -- push "$REGISTRY/$IMAGE:$PKGMGR"
# gcloud docker -- push "$REGISTRY/$IMAGE:$PKGMGR-$REV"
done
24 changes: 12 additions & 12 deletions infra/build-image/docker-iso-build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash
# Copyright 2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,11 +17,8 @@
# runs the given command in a container with iso build dependencies
set -e && [ -n "$DEBUG" ] && set -x

function main {
which jq >/dev/null 2>&1
[ ! $? -eq 0 ] && "Echo please install 'jq' to continue..." && exit 1

REPO=$(cat isos/base/repos/$1/repo-spec.json | jq -r '.packagemanager')
function main {
PKGMGR=$(cat isos/base/repos/$1/repo-spec.json | jq -r '.packagemanager')
shift

rmArg=""
Expand All @@ -35,11 +32,9 @@ function main {
-v $GOPATH/bin:/go/bin:ro \
-v $GOPATH/src/github.com/vmware/vic:/go/src/github.com/vmware/vic:ro \
-v $GOPATH/src/github.com/vmware/vic/bin:/go/src/github.com/vmware/vic/bin \
-w /go/src/github.com/vmware/vic \
-e TERM=linux \
-e DEBUG=${DEBUG} \
-e BUILD_NUMBER=${BUILD_NUMBER} \
gcr.io/eminent-nation-87317/vic-build-image:${REPO:-tdnf} /bin/bash -c "$*"
gcr.io/eminent-nation-87317/vic-build-image:${PKGMGR:-tdnf} /bin/bash -c "$*"
}

REPO="photon-2.0"
Expand All @@ -51,9 +46,14 @@ while getopts ':d:' flag; do
done
shift $((OPTIND-1))

# Check if jq is available - we need this on either path
which jq >/dev/null 2>&1
[ $? -ne 0 ] && "Echo please install 'jq' to continue..." && exit 1

echo "building $REPO"
if [[ -f "/proc/1/cgroup" && -n "$(grep docker /proc/1/cgroup)" ]]; then
/bin/bash -c "$*" # prevent docker in docker
# Check if docker installed
if ! docker info >/dev/null 2>&1; then
/bin/bash -c "$*" # prevent docker in docker
else
main "${REPO}" "$@"
main "${REPO}" "$@"
fi
Loading

0 comments on commit f9a0c67

Please sign in to comment.