Skip to content

Commit

Permalink
Add two phases of creating squash mount
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Dec 3, 2016
1 parent 187a6a0 commit ee34ffa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
48 changes: 31 additions & 17 deletions packer-template-script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

export TARGET=tulip_chiphd-userdebug
export USE_CCACHE=true
export CCACHE_DIR=/android/ccache
export ANDROID_JACK_VM_ARGS="-Xmx4g -Dfile.encoding=UTF-8 -XX:+TieredCompilation"
Expand All @@ -14,9 +13,12 @@ message() {
set -ve

message "Installing dependencies..."
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt-get update -y
sudo apt-get install -y openjdk-7-jdk python git-core gnupg flex bison gperf build-essential \
apt-get update -y
apt-get install -y software-properties-common

add-apt-repository -y ppa:openjdk-r/ppa
apt-get update -y
apt-get install -y openjdk-${JDK_VERSION}-jdk python git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
libgl1-mesa-dev libxml2-utils xsltproc unzip mtools u-boot-tools \
Expand All @@ -33,32 +35,44 @@ mkdir -p /android
cd /android

rm -rf .repo/local_manifests
~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r74 --depth=1
git clone https://github.com/ayufan-pine64/local_manifests -b marshmallow .repo/local_manifests
~/bin/repo init -u https://android.googlesource.com/platform/manifest -b "${MANIFEST}" --depth=1
git clone https://github.com/ayufan-pine64/local_manifests -b "${VARIANT}" .repo/local_manifests

message "Syncing repositories..."
~/bin/repo sync -j 20 -c --force-sync

message "Building..."
source build/envsetup.sh
lunch "${TARGET}"
command make -j$(($(nproc)+1)) || command make -j$(($(nproc)+1)) || true

message "Cleaning objects..."
command make installclean

message "Building squashfs image..."
message "Building squashfs image (repositories)..."
cd /
mksquashfs -Xcompression-level 7 /android /android.squashfs
mksquashfs /android /android.squashfs -Xcompression-level 7

message "Cleanup squashfs mount..."
rm -rf /android

message "Prepare squashfs mount..."
mkdir -p /mnt/android /android/{overlay,work}/

cat <<EOF > /etc/rc.local
cat <<"EOF" > /etc/rc.local
#!/bin/sh -e
mount -t squashfs /android.squashfs /mnt/android
mount -t overlay overlay -o lowerdir=/mnt/android,upperdir=/android/overlay,workdir=/android/work /android
EOF

message "Mounting squash image..."
/etc/rc.local

message "Configuring ccache..."
cd /android
prebuilts/misc/linux-x86/ccache/ccache -M 0 -F 0

message "Building..."
source build/envsetup.sh
lunch "${BUILD_TARGET}"
make -j $(nproc) || make -j $(nproc) || make -j $(nproc)

message "Cleaning..."
make installclean

message "Updating squashfs..."
cd /
umount /android /mnt/android
mksquashfs /android/overlay /android.squashfs -Xcompression-level 7
31 changes: 25 additions & 6 deletions packer-template.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
{
"variables": {
"do_api_token": "{{env `DIGITALOCEAN_API_TOKEN`}}"
"jdk_version": "7",
"build_target": "tulip_chiphd_atv-userdebug",
"manifest": "android-6.0.1_r74",
"variant": "marshmallow",

"do_api_token": "{{env `DIGITALOCEAN_API_TOKEN`}}",
"do_region": "ams2",
"do_size": "8gb",
},

"builders": [{
"type": "digitalocean",
"api_token": "{{user `do_api_token`}}",
"size": "8gb",
"region": "ams2",
"size": "{{user `do_size`}}",
"region": "{{user `do_region`}}",
"image": "ubuntu-16-04-x64",
"droplet_name": "android-6.0-pine64-packer",
"snapshot_name": "android-6.0-pine64-squashfs-{{timestamp}}"
"droplet_name": "{{user `manifest`}}-pine64-build-env",
"snapshot_name": "{{user `manifest`}}-pine64-build-env-{{timestamp}}",
"state_timeout": "180m"
}, {
"type": "docker",
"image": "ubuntu:xenial",
"privileged": true,
"commit": true
}],

"provisioners": [{
"type": "shell",
"script": "install-script.sh"
"script": "packer-template-script.sh",
"environment_vars": [
"JDK_VERSION={{user `jdk_version`}}",
"BUILD_TARGET={{user `build_target`}}",
"MANIFEST={{user `manifest`}}",
"VARIANT={{user `variant`}}"
]
}]
}

0 comments on commit ee34ffa

Please sign in to comment.