1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F #5188: move dockerfiles into external templates (#484)

This commit is contained in:
Alejandro Huertas Herrero 2020-11-27 11:11:14 +01:00 committed by GitHub
parent c65a119a2e
commit 29ca7ce9a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 93 additions and 68 deletions

View File

@ -252,6 +252,8 @@ SHARE_DIRS="$SHARE_LOCATION/examples \
$SHARE_LOCATION/websockify/websockify \
$SHARE_LOCATION/esx-fw-vnc \
$SHARE_LOCATION/oneprovision \
$SHARE_LOCATION/dockerhub \
$SHARE_LOCATION/dockerhub/dockerfiles \
$SHARE_LOCATION/schemas \
$SHARE_LOCATION/schemas/libvirt \
$SHARE_LOCATION/schemas/xsd \
@ -710,6 +712,8 @@ INSTALL_FILES=(
SSH_SH_OVERRIDE_LIB_FILES:$LIB_LOCATION/sh/override
SSH_SHARE_FILES:$SHARE_LOCATION/ssh
CONTEXT_SHARE:$SHARE_LOCATION/context
DOCKERFILE_TEMPLATE:$SHARE_LOCATION/dockerhub
DOCKERFILES_TEMPLATES:$SHARE_LOCATION/dockerhub/dockerfiles
)
INSTALL_CLIENT_FILES=(
@ -2732,6 +2736,16 @@ ONEHEM_BIN_FILES="src/hem/bin/onehem-server"
ONEHEM_ETC_FILES="src/hem/etc/onehem-server.conf"
#-----------------------------------------------------------------------------
# Dockerfiles templates
#-----------------------------------------------------------------------------
DOCKERFILES_TEMPLATES="src/datastore_mad/remotes/dockerhub/dockerfiles/alpine \
src/datastore_mad/remotes/dockerhub/dockerfiles/centos \
src/datastore_mad/remotes/dockerhub/dockerfiles/debian"
DOCKERFILE_TEMPLATE="src/datastore_mad/remotes/dockerhub/dockerfile"
#-----------------------------------------------------------------------------
# Docker Machine files
#-----------------------------------------------------------------------------

View File

@ -45,6 +45,10 @@ TMP_DIR=/var/tmp
#Context location
CONTEXT_PATH="$SHARE_LOCATION/context"
#Dockerfiles templates directory
DOCKERFILES="$SHARE_LOCATION/dockerhub/dockerfiles"
DOCKERFILE="$SHARE_LOCATION/dockerhub"
#-------------------------------------------------------------------------------
# This function takes care of removing all temporary directories in case
# something fails
@ -122,83 +126,24 @@ fi
case "$distro" in
debian|ubuntu)
commands=$(cat <<EOC
RUN [ ! -e /sbin/init ] && ln -s /lib/systemd/systemd /sbin/init
RUN apt-get update
RUN apt-get update && apt-get install -y \
curl \
dbus \
kmod \
iproute2 \
iputils-ping \
net-tools \
openssh-server \
sudo \
systemd \
udev \
vim-tiny \
wget \
haveged
RUN apt-get install -y /root/context/one-context_*.deb
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN systemctl enable haveged
EOC
)
commands=$(cat "$DOCKERFILES/debian")
;;
centos)
commands=$(cat <<EOC
RUN yum update -y
RUN yum install -y epel-release
RUN yum install -y initscripts \
e2fsprogs \
haveged
RUN yum localinstall -y \`find /root/context -type f \( ! -iname "*ec2*" -iname "*el7.noarch.rpm" \)\`
RUN systemctl enable haveged
EOC
)
commands=$(cat "$DOCKERFILES/centos")
;;
alpine)
commands=$(cat <<EOC
RUN apk add coreutils \
openrc \
udev \
openssh
RUN apk -U add haveged
RUN rc-update add sysfs boot && \
rc-update add devfs boot && \
rc-update add procfs boot && \
rc-update add hostname boot && \
rc-update add haveged boot
RUN echo "ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100" >> /etc/inittab
RUN apk add --allow-untrusted /root/context/*.apk
RUN rc-update del one-context boot && \
rc-update add one-context default
RUN rc-update add sshd default && \
rc-update add udev default && \
rc-update add networking default
RUN echo 'rc_sys=""' >> /etc/rc.conf
EOC
)
commands=$(cat "$DOCKERFILES/alpine")
;;
*)
;;
esac
cat > $dockerfile <<EOC
FROM $docker_hub
USER root
COPY context /root/context
$commands
RUN rm -rf /root/context
RUN echo "#Generated by OpenNebula" > /etc/resolv.conf
RUN rm -f /etc/ssh/ssh_host_* > /dev/null 2>&1
RUN usermod -p '*' root > /dev/null 2>&1
EOC
#Replace variables _docker_hub and _commands
dockerfile_template=$(cat "$DOCKERFILE/dockerfile")
dockerfile_template=${dockerfile_template/\%IMAGE_ID\%/$docker_hub}
dockerfile_template=${dockerfile_template/\%COMMANDS\%/$commands}
echo "$dockerfile_template" > "$dockerfile"
cp -rL $CONTEXT_PATH $dockerdir

View File

@ -0,0 +1,17 @@
# Main dockerfile template used to create images from DockerHub
#
# IMPORTANT: IMAGE_ID and COMMANDS can **NOT** be changed, they are used
# in the download process and are replaced by some variables.
#
# The rest of the template can be modified depending on your needs.
#
# It is installed on /usr/share/one/dockerfiles
FROM %IMAGE_ID%
USER root
COPY context /root/context
%COMMANDS%
RUN rm -rf /root/context
RUN echo "#Generated by OpenNebula" > /etc/resolv.conf
RUN rm -f /etc/ssh/ssh_host_* > /dev/null 2>&1
RUN usermod -p '*' root > /dev/null 2>&1

View File

@ -0,0 +1,22 @@
RUN apk add coreutils \
openrc \
udev \
openssh
RUN apk -U add haveged
RUN rc-update add sysfs boot && \
rc-update add devfs boot && \
rc-update add procfs boot && \
rc-update add hostname boot && \
rc-update add haveged boot
RUN echo "ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100" >> /etc/inittab
RUN apk add --allow-untrusted /root/context/*.apk
RUN rc-update del one-context boot && \
rc-update add one-context default
RUN rc-update add sshddefault && \
rc-update add udevdefault && \
rc-update add networking default
RUN echo 'rc_sys=""' >> /etc/rc.conf

View File

@ -0,0 +1,7 @@
RUN yum update -y
RUN yum install -y epel-release
RUN yum install -y initscripts \
e2fsprogs \
haveged
RUN yum localinstall -y \`find /root/context -type f \( ! -iname "*ec2*" -iname "*el7.noarch.rpm" \)\`
RUN systemctl enable haveged

View File

@ -0,0 +1,20 @@
RUN [ ! -e /sbin/init ] && ln -s /lib/systemd/systemd /sbin/init
RUN apt-get update
RUN apt-get update && apt-get install -y \
curl \
dbus \
kmod \
iproute2 \
iputils-ping \
net-tools \
openssh-server \
sudo \
systemd \
udev \
vim-tiny \
wget \
haveged
RUN apt-get install -y /root/context/one-context_*.deb
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN systemctl enable haveged