Skip to content

Commit

Permalink
Adds tool to create host images.
Browse files Browse the repository at this point in the history
  • Loading branch information
ser-io committed Jan 12, 2024
1 parent c36c5e8 commit 4f046a5
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Export Artifacts

on: [pull_request, push]

jobs:
build-debs:
runs-on: ubuntu-latest
container:
image: debian@sha256:4cb3f4198e4af2d03dffe6bfa4f3686773596494ef298f3882553d52e885634b # debian:bullseye-20240110
steps:
- name: apt update
run: apt update -y && apt upgrade -y
- name: install sudo
run: apt install -y sudo
- name: Checkout repository
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
- name: Build debs
run: bash build_debs.sh
- name: Build debs.tar
run: debs=(cuttlefish-*.deb) && tar -cvf debs.tar "${debs[@]}"
- name: Update debs.tar
uses: actions/upload-artifact@v3
with:
name: debs
path: debs.tar
build-gce-image:
needs: build-debs
runs-on: ubuntu-latest
steps:
- name: Download debs.tar
uses: actions/download-artifact@v3
with:
name: debs
- name: Untar debs.tar
run: tar -xf debs.tar
- name: list debs
run: ls

49 changes: 49 additions & 0 deletions build_debs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build the debian packages in this repository.

set -e

eval $(grep VERSION_CODENAME /etc/os-release)

[[ ${VERSION_CODENAME} == "bullseye" ]] || { echo "Invalid distribution '${VERSION_CODENAME}'. Use Debian 11 (bullseye)." >&2; exit 1; }

if [[ "${running_in_docker}" = "1" ]]; then
apt update
fi

sudo apt update
sudo apt install -y debconf-utils debhelper ubuntu-dev-tools equivs

dpkg-source -b base
dpkg-source -b frontend

for dsc in *.dsc; do
yes | sudo mk-build-deps -i "${dsc}" -t apt-get
done

for dsc in *.dsc; do
# Unpack the source and build it
dpkg-source -x "${dsc}"
dir="$(basename "${dsc}" .dsc)"
dir="${dir/_/-}"
pushd "${dir}/"
debuild -uc -us
popd
done

ls -la
30 changes: 30 additions & 0 deletions tools/buildimage/build_base_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Builds a base cloud debian image from https://salsa.debian.org/cloud-team/debian-cloud-images

set -e

sudo apt install -y git

git clone https://salsa.debian.org/cloud-team/debian-cloud-images.git

sudo apt install -y --no-install-recommends ca-certificates debsums dosfstools \
fai-server fai-setup-storage fdisk make python3 python3-libcloud python3-marshmallow \
python3-pytest python3-yaml qemu-utils udev

# cd debian-cloud-images && make image_bullseye_gce_amd64

51 changes: 51 additions & 0 deletions tools/buildimage/build_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build the debian packages in this repository.

set -e

sudo apt-get update
sudo apt install -y debconf-utils
# Avoids blocking "Default mirror not found" popup prompt when pbuilder is installed.
echo "pbuilder pbuilder/mirrorsite string https://deb.debian.org/debian" | sudo debconf-set-selections

# Stuff we need to get build support
sudo apt install -y debhelper ubuntu-dev-tools equivs

git clone https://github.com/google/android-cuttlefish -b main

pushd android-cuttlefish

dpkg-source -b base
dpkg-source -b frontend

for dsc in *.dsc; do
yes | sudo mk-build-deps -i "${dsc}" -t apt-get
done

for dsc in *.dsc; do
# Unpack the source and build it
dpkg-source -x "${dsc}"
dir="$(basename "${dsc}" .dsc)"
dir="${dir/_/-}"
pushd "${dir}/"
debuild -uc -us
popd
done

pushd

63 changes: 63 additions & 0 deletions tools/buildimage/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build custom image to be used in GCE VMs.

set -e

usage() {
echo "usage: $0 [-h] [-d]"
exit 1
}

running_in_docker=0

while getopts ":hd" opt; do
case "${opt}" in
h)
usage
;;
d)
running_in_docker=1
;;
\?)
echo "Invalid option: ${OPTARG}" >&2
usage
;;
:)
echo "Invalid option: ${OPTARG} requires an argument" >&2
usage
;;
esac
done

eval $(grep VERSION_CODENAME /etc/os-release)

[[ ${VERSION_CODENAME} == "bullseye" ]] || { echo "Invalid distribution '${VERSION_CODENAME}'. Use Debian 11 (bullseye)." >&2; exit 1; }

if [[ "${running_in_docker}" = "1" ]]; then
apt update
apt install -y sudo
fi

script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)

pushd /tmp
# Build debian cloud image, used as the base image.
bash "${script_dir}/build_base_image.sh"
# Build cuttlefish debian packages.
# bash "${script_dir}/build_cf_packages.sh"
popd

0 comments on commit 4f046a5

Please sign in to comment.