• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4#
5# Docker container for VMs that can run crosvm tests. This container is
6# primarily an intermediate step and imported into the crosvm_(aarch64)_builder
7# containers, but for testing purposes it can be run directly.
8
9# Target architecture of the VM. Either arm64 or amd64.
10ARG VM_ARCH
11
12# Build stage which will build the rootfs for our VM
13FROM debian:buster as vm_builder
14ARG VM_ARCH
15
16RUN apt-get update && apt-get install --yes \
17    cloud-image-utils \
18    curl \
19    expect \
20    qemu-system-arm \
21    qemu-system-x86 \
22    qemu-efi-aarch64
23
24WORKDIR /workspace/vm
25
26RUN curl -sSfL -o rootfs.qcow2 \
27    "http://cloud.debian.org/images/cloud/bullseye/daily/20210208-542/debian-11-generic-${VM_ARCH}-daily-20210208-542.qcow2"
28
29# Package `cloud_init_data.yaml` to be loaded during `first_boot.expect`
30COPY build/cloud_init_data.yaml ./
31RUN cloud-localds -v cloud_init.img cloud_init_data.yaml
32
33# Boot the VM once, to do initialization work so we do not have to do it at
34# every launch.
35COPY runtime/start_vm.${VM_ARCH} ./start_vm
36COPY build/first_boot.expect ./
37RUN expect -f first_boot.expect
38
39# Compress and sparsify image after doing all the init work.
40RUN qemu-img convert -O qcow2 -c rootfs.qcow2 rootfs.compressed \
41    && mv -f rootfs.compressed rootfs.qcow2
42
43
44# Runtime environment for amd64
45FROM debian:buster as runtime_amd64
46RUN apt-get update && apt-get install --yes --no-install-recommends \
47    qemu-system-x86
48
49
50# Runtime environment for arm64
51FROM debian:buster as runtime_arm64
52RUN apt-get update && apt-get install --yes --no-install-recommends \
53    ipxe-qemu \
54    qemu-system-arm \
55    qemu-efi-aarch64
56
57
58# Select the correct stage as runtime stage
59FROM runtime_${VM_ARCH} as runtime
60ARG VM_ARCH
61
62RUN apt-get install --yes --no-install-recommends \
63    openssh-client
64
65# Copy rootfs into runtime stage
66WORKDIR /workspace/vm
67COPY --from=vm_builder /workspace/vm/rootfs.qcow2 ./
68
69# Setup SSH profile for `vm`.
70RUN mkdir -p ~/.ssh
71COPY runtime/ssh /root/.ssh
72RUN chmod 0600 /root/.ssh/id_rsa
73
74# Copy utility scripts
75COPY runtime/start_vm.${VM_ARCH} ./start_vm
76
77# Automatically start the VM.
78ENTRYPOINT [ "/workspace/vm/start_vm" ]
79