vagrant-libvirt/Dockerfile
Darragh Bailey d282a9dbd6
Docker image bundle vagrant-libvirt with vagrant (#1569)
Move the vagrant-libvirt plugin into being combined directly with
vagrant which both prevents the plugin from being reinstalled by any
subsequent call to `vagrant plugin install <plugin>` and avoids the need
to create and manage symlinks to a /vagrant.d directory for boxes.
2022-09-01 20:14:24 +01:00

99 lines
2.4 KiB
Docker

# syntax = docker/dockerfile:1.3-labs
ARG VAGRANT_VERSION=2.3.0
FROM ubuntu:bionic as base
RUN apt update \
&& apt install -y --no-install-recommends \
bash \
ca-certificates \
curl \
git \
gosu \
kmod \
libvirt-bin \
openssh-client \
qemu-utils \
rsync \
&& rm -rf /var/lib/apt/lists \
;
ENV VAGRANT_HOME /.vagrant.d
ARG VAGRANT_VERSION
ENV VAGRANT_VERSION ${VAGRANT_VERSION}
RUN set -e \
&& curl https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}-1_amd64.deb -o vagrant.deb \
&& apt update \
&& apt install -y ./vagrant.deb \
&& rm -rf /var/lib/apt/lists/* \
&& rm -f vagrant.deb \
;
ENV VAGRANT_DEFAULT_PROVIDER=libvirt
FROM base as build
# allow caching of packages for build
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN sed -i '/deb-src/s/^# //' /etc/apt/sources.list
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
apt update \
&& apt build-dep -y \
vagrant \
ruby-libvirt \
&& apt install -y --no-install-recommends \
libxslt-dev \
libxml2-dev \
libvirt-dev \
ruby-bundler \
ruby-dev \
zlib1g-dev \
;
WORKDIR /build
COPY . .
RUN rake build
RUN find /opt/vagrant/embedded/ -type f | grep -v /opt/vagrant/embedded/plugins.json > /files-to-delete.txt
RUN /opt/vagrant/embedded/bin/gem install --install-dir /opt/vagrant/embedded/gems/${VAGRANT_VERSION} ./pkg/vagrant-libvirt*.gem
RUN cat <<EOF > /opt/vagrant/embedded/plugins.json
{
"version": "1",
"installed": {
"vagrant-libvirt": {
"ruby_version":"$(/opt/vagrant/embedded/bin/ruby -e 'puts RUBY_VERSION')",
"vagrant_version":"${VAGRANT_VERSION}",
"gem_version":"",
"require":"",
"sources":[]
}
}
}
EOF
FROM build as pruned
RUN cat /files-to-delete.txt | xargs rm -f
FROM base as slim
COPY --from=pruned /opt/vagrant/embedded/gems /opt/vagrant/embedded/gems
COPY --from=build /opt/vagrant/embedded/plugins.json /opt/vagrant/embedded/plugins.json
COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT ["entrypoint.sh"]
FROM build as final
COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT ["entrypoint.sh"]
# vim: set expandtab sw=4: