diff --git a/packer-template-script.sh b/packer-template-script.sh new file mode 100644 index 0000000..3a4a4c7 --- /dev/null +++ b/packer-template-script.sh @@ -0,0 +1,64 @@ +#!/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" + +message() { + echo "============================" + echo "$@" + echo "============================" +} + +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 \ + 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 \ + htop iotop sysstat iftop pigz bc device-tree-compiler lunzip \ + squashfs-tools + +message "Downloading repo tool..." +mkdir -p ~/bin +curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo +chmod a+x ~/bin/repo + +message "Downloading manifests..." +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 + +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..." +cd / +mksquashfs -Xcompression-level 7 /android /android.squashfs + +message "Cleanup squashfs mount..." +rm -rf /android + +message "Prepare squashfs mount..." +mkdir -p /mnt/android /android/{overlay,work}/ + +cat < /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 diff --git a/packer-template.json b/packer-template.json new file mode 100644 index 0000000..d775337 --- /dev/null +++ b/packer-template.json @@ -0,0 +1,20 @@ +{ + "variables": { + "do_api_token": "{{env `DIGITALOCEAN_API_TOKEN`}}" + }, + + "builders": [{ + "type": "digitalocean", + "api_token": "{{user `do_api_token`}}", + "size": "8gb", + "region": "ams2", + "image": "ubuntu-16-04-x64", + "droplet_name": "android-6.0-pine64-packer", + "snapshot_name": "android-6.0-pine64-squashfs-{{timestamp}}" + }], + + "provisioners": [{ + "type": "shell", + "script": "install-script.sh" + }] +}