Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
rootfs: Add support to create dockerfiles based on templates
Browse files Browse the repository at this point in the history
To simplify maintaince, create dockerfiles based on templates.

This way when golang version is updated it will be done in one place
versions.txt.

This also allow to allways intall the same version of golang in any
dockerfile.

Signed-off-by: Jose Carlos Venegas Munoz <[email protected]>
  • Loading branch information
jcvenegas committed Jan 25, 2018
1 parent 6dcaef7 commit 03fa417
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 23 deletions.
1 change: 1 addition & 0 deletions rootfs-builder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
7 changes: 0 additions & 7 deletions rootfs-builder/centos/Dockerfile

This file was deleted.

6 changes: 6 additions & 0 deletions rootfs-builder/centos/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
From centos:@OS_VERSION@

RUN yum -y update && yum install -y git make gcc

# This will install the proper golang to build Kata components
@INSTALL_GO@
3 changes: 0 additions & 3 deletions rootfs-builder/clearlinux/Dockerfile

This file was deleted.

6 changes: 6 additions & 0 deletions rootfs-builder/clearlinux/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
From fedora:27

RUN dnf -y update && dnf install -y git systemd pkgconfig gcc

# This will install the proper golang to build Kata components
@INSTALL_GO@
7 changes: 0 additions & 7 deletions rootfs-builder/euleros/Dockerfile

This file was deleted.

5 changes: 5 additions & 0 deletions rootfs-builder/euleros/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM euleros:@OS_VERSION@

RUN yum -y update && yum install -y yum git make gcc
# This will install the proper golang to build Kata components
@INSTALL_GO@
2 changes: 1 addition & 1 deletion rootfs-builder/euleros/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Remove them or add more

# EulerOS Version
OS_VERSION=${OS_VERSION:-2}
OS_VERSION=${OS_VERSION:-2.2}

#Mandatory Packages that must be installed
# systemd: An init system that will start kata-agent
Expand Down
4 changes: 2 additions & 2 deletions rootfs-builder/euleros/rootfs_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ logfile=/var/log/yum-euleros.log
exactarch=1
[Base]
name=EulerOS-2.2 Base
baseurl=http://developer.huawei.com/ict/site-euleros/euleros/repo/yum/2.2/os/x86_64/
name=EulerOS-${OS_VERSION} Base
baseurl=http://developer.huawei.com/ict/site-euleros/euleros/repo/yum/${OS_VERSION}/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=file://${CONFIG_DIR}/RPM-GPG-KEY-EulerOS
Expand Down
3 changes: 0 additions & 3 deletions rootfs-builder/fedora/Dockerfile

This file was deleted.

6 changes: 6 additions & 0 deletions rootfs-builder/fedora/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
From fedora:@OS_VERSION@

RUN dnf -y update && dnf install -y git redhat-release systemd pkgconfig gcc

# This will install the proper golang to build Kata components
@INSTALL_GO@
27 changes: 27 additions & 0 deletions rootfs-builder/rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ROOTFS_DIR=${ROOTFS_DIR:-${PWD}/rootfs}
AGENT_VERSION=${AGENT_VERSION:-master}
GO_AGENT_PKG=${GO_AGENT_PKG:-github.com/kata-containers/agent}
AGENT_BIN=${AGENT_BIN:-kata-agent}
#Load default vesions for golang and other componets
source "${script_dir}/versions.txt"

# Name of file that will implement build_rootfs
typeset -r LIB_SH="rootfs_lib.sh"

Expand Down Expand Up @@ -79,6 +82,29 @@ check_function_exist() {
[ "$(type -t ${function_name})" == "function" ] || die "${function_name} function was not defined"
}

generate_dockerfile() {
dir="$1"

readonly install_go="
ADD https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz /tmp
RUN tar -C /usr/ -xzf /tmp/go${GO_VERSION}.linux-amd64.tar.gz
ENV GOROOT=/usr/go
ENV PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
"

readonly dockerfile_template="Dockerfile.in"
[ -d "${dir}" ] || die "${dir}: not a directory"
pushd ${dir}
[ -f "${dockerfile_template}" ] || die "${dockerfile_template}: file not found"
set -x
sed \
-e "s|@OS_VERSION@|${OS_VERSION}|g" \
-e "s|@INSTALL_GO@|${install_go//$'\n'/\\n}|g" \
${dockerfile_template} > Dockerfile
set +x
popd
}


while getopts c:hr: opt
do
Expand Down Expand Up @@ -110,6 +136,7 @@ check_function_exist "build_rootfs"
if [ -n "${USE_DOCKER}" ] ; then
image_name="${distro}-rootfs-osbuilder"

generate_dockerfile "${distro_config_dir}"
docker build \
--build-arg http_proxy="${http_proxy}" \
--build-arg https_proxy="${https_proxy}" \
Expand Down
11 changes: 11 additions & 0 deletions rootfs-builder/template/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#@distro@: docker image to be used to create a rootfs
#@OS_VERSION@: Docker image version to build this dockerfile
from @distro@:@OS_VERSION@

# This dockerfile needs to provide all the componets need to build a rootfs
# Install any package need to create a rootfs (package manager, extra tools)

# RUN commands

# This will install the proper golang to build Kata components
@INSTALL_GO@
5 changes: 5 additions & 0 deletions rootfs-builder/template/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ endif
mkdir -p $(DESTDIR)
cp "$(MK_DIR)/rootfs_lib_template.sh" "$(DESTDIR)/rootfs_lib.sh"
cp "$(MK_DIR)/config_template.sh" "$(DESTDIR)/config.sh"
sed \
-e "s|@distro@|$(ROOTFS_BASE_NAME)|g" \
Dockerfile.template > $(DESTDIR)/Dockerfile.in


1 change: 1 addition & 0 deletions rootfs-builder/versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GO_VERSION=1.9.2

0 comments on commit 03fa417

Please sign in to comment.