Use a multi-stage build

This commit is contained in:
Héctor Molinero Fernández 2020-06-10 22:48:26 +02:00
parent fdddb96dcf
commit e680530071

View File

@ -1,9 +1,60 @@
##################################################
## "build" stage
##################################################

FROM docker.io/ubuntu:20.04 AS build

# Install system packages
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Download noVNC
ARG NOVNC_VERSION=v1.1.0
ARG NOVNC_TARBALL_URL=https://github.com/novnc/noVNC/archive/${NOVNC_VERSION}.tar.gz
ARG NOVNC_TARBALL_CHECKSUM=2c63418b624a221a28cac7b9a7efecc092b695fc1b7dd88255b074ab32bc72a7
RUN curl -Lo /tmp/novnc.tgz "${NOVNC_TARBALL_URL:?}"
RUN printf '%s' "${NOVNC_TARBALL_CHECKSUM:?} /tmp/novnc.tgz" | sha256sum -c
RUN mkdir /tmp/novnc/ && tar -xzf /tmp/novnc.tgz --strip-components=1 -C /tmp/novnc/

# Download Websockify
ARG WEBSOCKIFY_VERSION=v0.9.0
ARG WEBSOCKIFY_TARBALL_URL=https://github.com/novnc/websockify/archive/${WEBSOCKIFY_VERSION}.tar.gz
ARG WEBSOCKIFY_TARBALL_CHECKSUM=6ebfec791dd78be6584fb5fe3bc27f02af54501beddf8457368699f571de13ae
RUN curl -Lo /tmp/websockify.tgz "${WEBSOCKIFY_TARBALL_URL:?}"
RUN printf '%s' "${WEBSOCKIFY_TARBALL_CHECKSUM:?} /tmp/websockify.tgz" | sha256sum -c
RUN mkdir /tmp/websockify/ && tar -xzf /tmp/websockify.tgz --strip-components=1 -C /tmp/websockify/

# Download ReactOS ISO
ARG REACTOS_ISO_URL=https://downloads.sourceforge.net/project/reactos/ReactOS/0.4.13/ReactOS-0.4.13-iso.zip
ARG REACTOS_ISO_CHECKSUM=5bd27a9f9af4589ca1683795775c747a96c5a45fcb570f543d5370f55c079ae6
RUN curl -Lo /tmp/reactos.zip "${REACTOS_ISO_URL:?}"
RUN printf '%s' "${REACTOS_ISO_CHECKSUM:?} /tmp/reactos.zip" | sha256sum -c
RUN unzip -p /tmp/reactos.zip 'ReactOS-*.iso' > /tmp/reactos.iso

################################################## ##################################################
## "qemu-reactos" stage ## "qemu-reactos" stage
################################################## ##################################################


FROM docker.io/ubuntu:20.04 AS qemu-reactos FROM docker.io/ubuntu:20.04 AS qemu-reactos


# Install system packages
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
net-tools \
procps \
python3 \
qemu-kvm \
qemu-system-x86 \
qemu-utils \
runit \
&& rm -rf /var/lib/apt/lists/*

# Environment # Environment
ENV QEMU_CPU=2 ENV QEMU_CPU=2
ENV QEMU_RAM=1024M ENV QEMU_RAM=1024M
@ -16,51 +67,17 @@ ENV QEMU_BOOT_ORDER=cd
ENV QEMU_BOOT_MENU=off ENV QEMU_BOOT_MENU=off
ENV QEMU_KVM=false ENV QEMU_KVM=false


# Install system packages # Create some directories for QEMU
RUN export DEBIAN_FRONTEND=noninteractive \ RUN mkdir -p /var/lib/qemu/iso/ /var/lib/qemu/images/
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
net-tools \
procps \
python3 \
qemu-kvm \
qemu-system-x86 \
qemu-utils \
runit \
unzip \
&& rm -rf /var/lib/apt/lists/*


# Install noVNC # Copy noVNC
ARG NOVNC_VERSION=v1.1.0 COPY --from=build --chown=root:root /tmp/novnc/ /opt/novnc/
ARG NOVNC_TARBALL_URL=https://github.com/novnc/noVNC/archive/${NOVNC_VERSION}.tar.gz
ARG NOVNC_TARBALL_CHECKSUM=2c63418b624a221a28cac7b9a7efecc092b695fc1b7dd88255b074ab32bc72a7
RUN mkdir -p /opt/novnc/ \
&& curl -Lo /tmp/novnc.tgz "${NOVNC_TARBALL_URL:?}" \
&& printf '%s' "${NOVNC_TARBALL_CHECKSUM:?} /tmp/novnc.tgz" | sha256sum -c \
&& tar -xzf /tmp/novnc.tgz --strip-components=1 -C /opt/novnc/ \
&& rm -f /tmp/novnc.tgz


# Install Websockify # Copy Websockify
ARG WEBSOCKIFY_VERSION=v0.9.0 COPY --from=build --chown=root:root /tmp/websockify/ /opt/novnc/utils/websockify/
ARG WEBSOCKIFY_TARBALL_URL=https://github.com/novnc/websockify/archive/${WEBSOCKIFY_VERSION}.tar.gz
ARG WEBSOCKIFY_TARBALL_CHECKSUM=6ebfec791dd78be6584fb5fe3bc27f02af54501beddf8457368699f571de13ae
RUN mkdir -p /opt/novnc/utils/websockify/ \
&& curl -Lo /tmp/websockify.tgz "${WEBSOCKIFY_TARBALL_URL:?}" \
&& printf '%s' "${WEBSOCKIFY_TARBALL_CHECKSUM:?} /tmp/websockify.tgz" | sha256sum -c \
&& tar -xzf /tmp/websockify.tgz --strip-components=1 -C /opt/novnc/utils/websockify/ \
&& rm -f /tmp/websockify.tgz


# Download ReactOS ISO # Copy ReactOS ISO
ARG REACTOS_ISO_URL=https://downloads.sourceforge.net/project/reactos/ReactOS/0.4.13/ReactOS-0.4.13-iso.zip COPY --from=build --chown=root:root /tmp/reactos.iso /var/lib/qemu/iso/reactos.iso
ARG REACTOS_ISO_CHECKSUM=5bd27a9f9af4589ca1683795775c747a96c5a45fcb570f543d5370f55c079ae6
RUN mkdir -p /tmp/reactos/ /var/lib/qemu/iso/ /var/lib/qemu/images/ \
&& curl -Lo /tmp/reactos/reactos.zip "${REACTOS_ISO_URL:?}" \
&& printf '%s' "${REACTOS_ISO_CHECKSUM:?} /tmp/reactos/reactos.zip" | sha256sum -c \
&& unzip /tmp/reactos/reactos.zip -d /tmp/reactos/ \
&& mv /tmp/reactos/*.iso /var/lib/qemu/iso/reactos.iso \
&& rm -rf /tmp/reactos/


# Copy services # Copy services
COPY --chown=root:root ./scripts/service/ /etc/service/ COPY --chown=root:root ./scripts/service/ /etc/service/
@ -68,10 +85,9 @@ COPY --chown=root:root ./scripts/service/ /etc/service/
# Copy scripts # Copy scripts
COPY --chown=root:root ./scripts/bin/ /usr/local/bin/ COPY --chown=root:root ./scripts/bin/ /usr/local/bin/


# Expose ports # VNC
## VNC
EXPOSE 5900/tcp EXPOSE 5900/tcp
## noVNC # noVNC
EXPOSE 6080/tcp EXPOSE 6080/tcp


CMD ["/usr/local/bin/container-foreground-cmd"] CMD ["/usr/local/bin/container-foreground-cmd"]