Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit ac7a690

Browse files
author
Julio Montes
authored
Merge pull request #48 from jcvenegas/agent_os_versions
Install agent from sources
2 parents 1aff7fc + e8df94c commit ac7a690

File tree

4 files changed

+74
-16
lines changed

4 files changed

+74
-16
lines changed

Makefile

+27-5
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,23 @@ BUILD_PROXY += --build-arg https_proxy=$(https_proxy)
2626
RUN_PROXY += --env https_proxy=$(https_proxy)
2727
endif
2828

29+
RUN_OS_VERSION= --env OS_VERSION="$(OS_VERSION)"
30+
RUN_AGENT_VERSION= --env AGENT_VERSION="$(AGENT_VERSION)"
2931
RUN_EXTRA_PKGS = --env EXTRA_PKGS="$(EXTRA_PKGS)"
3032
RUN_IMG_SIZE = --env IMG_SIZE="$(IMG_SIZE)"
3133
RUN_REPO_URL = --env REPO_URL="$(REPO_URL)"
3234
RUN_DEBUG = --env DEBUG="$(DEBUG)"
35+
CONTAINER_GOPATH = /go_path
36+
RUN_GOPATH += --env GOPATH="$(CONTAINER_GOPATH)"
3337

3438
IMAGE_BUILDER = cc-osbuilder
3539
WORKDIR ?= $(CURDIR)/workdir
3640
MK_DIR :=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
3741
OS_BUILDER ?= $(MK_DIR)/scripts/osbuilder.sh
38-
42+
RUNTIME_VERSIONS = "https://raw.githubusercontent.com/clearcontainers/runtime/master/versions.txt"
43+
#get go_version=<version>
44+
GO_VERSION = $(shell curl -sL $(RUNTIME_VERSIONS) | grep '^go_version=' | cut -d= -f2)
45+
BUILD_GO_VERSION+= --build-arg GO_VERSION=$(GO_VERSION)
3946

4047
# Installation variables
4148
DESTDIR :=
@@ -69,13 +76,19 @@ OS_BUILDER = docker run \
6976
--privileged \
7077
-v /dev:/dev \
7178
$(RUN_PROXY) \
79+
$(RUN_OS_VERSION) \
80+
$(RUN_AGENT_VERSION) \
7281
$(RUN_EXTRA_PKGS) \
7382
$(RUN_IMG_SIZE) \
7483
$(RUN_REPO_URL) \
84+
$(RUN_GOPATH) \
7585
$(RUN_DEBUG) \
7686
-i \
77-
-v $(WORKDIR):/osbuilder \
78-
$(IMAGE_BUILDER)
87+
-v $(MK_DIR):/osbuilder \
88+
-v $(WORKDIR):/workdir \
89+
-v $(GOPATH):$(CONTAINER_GOPATH)\
90+
$(IMAGE_BUILDER) \
91+
/osbuilder/scripts/osbuilder.sh
7992
endif
8093
rootfs: $(WORKDIR) $(DOCKER_DEPS)
8194
cd $(WORKDIR) && $(OS_BUILDER) rootfs
@@ -99,10 +112,13 @@ kernel-src: $(WORKDIR) $(DOCKER_DEPS)
99112

100113
docker-build:
101114
cd scripts; \
102-
docker build $(BUILD_PROXY) -t $(IMAGE_BUILDER) .
115+
docker build $(BUILD_PROXY) $(BUILD_GO_VERSION) -t $(IMAGE_BUILDER) .
103116

104117
clean:
105-
rm -rf "$(WORKDIR)/rootfs" "$(WORKDIR)/linux" "$(WORKDIR)/img"
118+
sudo rm -rf "$(WORKDIR)/rootfs"
119+
rm -rf "$(WORKDIR)/linux"
120+
rm -rf "$(WORKDIR)/img"
121+
rm -f $(WORKDIR)/clear-dnf.conf $(WORKDIR)/container.img
106122

107123
$(WORKDIR):
108124
mkdir -p $(WORKDIR)
@@ -199,6 +215,9 @@ install-image:
199215

200216
Environment Variables:
201217

218+
- AGENT_VERSION:
219+
Agent tag/commit/branch to install when building rootfs.
220+
202221
- DEBUG
203222

204223
- EXTRA_PKGS:
@@ -209,6 +228,9 @@ Environment Variables:
209228
Change the image size of the image to generate (accepts any value
210229
recognised by qemu-img(1)).
211230

231+
- OS_VERSION:
232+
Clear Linux version to use as base rootfs.
233+
212234
- PKG_MANAGER
213235
Specify the path to dnf or yum.
214236

scripts/Dockerfile

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
From fedora:27
1919

20-
RUN dnf install -y qemu-img parted gdisk make gcc bc git e2fsprogs
20+
RUN dnf install -y qemu-img parted gdisk make gcc bc git e2fsprogs libudev-devel pkgconfig
2121

22-
ENV workdir /osbuilder
23-
WORKDIR ${workdir}
22+
ARG GO_VERSION
2423

25-
COPY osbuilder.sh /usr/bin
26-
COPY image_builder.sh /usr/bin
27-
COPY kernel_builder.sh /usr/bin
24+
RUN cd /tmp && curl -OL https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz
25+
RUN tar -C /usr/ -xzf /tmp/go${GO_VERSION}.linux-amd64.tar.gz
26+
ENV GOROOT=/usr/go
27+
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
2828

29-
ENTRYPOINT ["/usr/bin/osbuilder.sh"]
29+
ENV workdir /workdir
30+
WORKDIR ${workdir}

scripts/config.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Agent version/commit/tag to use.
2+
3+
AGENT_VERSION=${AGENT_VERSION:-master}

scripts/osbuilder.sh

+36-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ fi
2424

2525
SCRIPT_NAME="${0##*/}"
2626
SCRIPT_DIR="$(dirname $(realpath -s $0))"
27-
REPO_URL=${REPO_URL:-https://download.clearlinux.org/current/x86_64/os/}
28-
EXTRA_PKGS=${EXTRA_PKGS:-""}
27+
source "${SCRIPT_DIR}/config.txt"
28+
# This is defined in config.txt
29+
OS_VERSION=${OS_VERSION}
30+
VERSIONS_FILE="https://raw.githubusercontent.com/clearcontainers/runtime/master/versions.txt"
31+
32+
if [ -z "${OS_VERSION}" ]; then
33+
OS_VERSION="$(curl -Ls ${VERSIONS_FILE} | grep '^clear_vm_image_version=' | cut -d= -f 2)"
34+
fi
35+
36+
REPO_URL=${REPO_URL:-https://download.clearlinux.org/releases/${OS_VERSION}/clear/x86_64/os/}
37+
AGENT_REPOSITORY="github.com/clearcontainers/agent"
2938

3039

3140
IMAGE_BUILDER_SH="image_builder.sh"
@@ -39,6 +48,7 @@ if ! type ${KERNEL_BUILDER_SH} >/dev/null 2>&1; then
3948
fi
4049

4150
ROOTFS_DIR="$(pwd)/rootfs"
51+
IMAGE_INFO_FILE="$(pwd)/image_info"
4252

4353
die()
4454
{
@@ -124,14 +134,35 @@ build_rootfs()
124134
${EXTRA_PKGS} \
125135
systemd \
126136
coreutils-bin \
127-
systemd-bootchart \
128137
iptables-bin \
129-
clear-containers-agent \
138+
clr-power-tweaks \
130139
procps-ng-bin
131140

141+
cat > ${IMAGE_INFO_FILE} << EOT
142+
[packages]
143+
$(rpm -qa --root="${ROOTFS_DIR}")
144+
EOT
132145
[ -n "${ROOTFS_DIR}" ] && rm -r "${ROOTFS_DIR}/var/cache/dnf"
133146
}
134147

148+
install_agent()
149+
{
150+
go get ${AGENT_REPOSITORY}
151+
pushd "${GOPATH}/src/${AGENT_REPOSITORY}"
152+
git fetch origin
153+
git checkout ${AGENT_VERSION}
154+
git pull || true
155+
make
156+
make install DESTDIR="${ROOTFS_DIR}"
157+
158+
cat >> ${IMAGE_INFO_FILE} << EOT
159+
160+
[agent]
161+
version=$(git log --pretty=format:'%h' -n 1)
162+
EOT
163+
popd
164+
}
165+
135166

136167
check_root()
137168
{
@@ -161,6 +192,7 @@ case "$BUILD" in
161192
rootfs)
162193
check_root
163194
build_rootfs
195+
install_agent
164196
;;
165197

166198
kernel-src)

0 commit comments

Comments
 (0)