Skip to content
Permalink
Browse files

Merge pull request #273 from chrisbanes/google-cloud-build

Google Cloud Build (following #271)
  • Loading branch information...
chrisbanes committed Feb 24, 2019
2 parents e382f01 + 974ed48 commit 69c49e825ecbc55371a8eb3832d90d69acc0bc02
@@ -24,10 +24,7 @@
</value>
</option>
</component>
<component name="ProjectPlainTextFileTypeManager">
<file url="file://$PROJECT_DIR$/tasks/src/main/java/app/tivi/tasks/TiviJob.kt" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
@@ -137,7 +137,7 @@ android {
buildTypes {
debug {
signingConfig signingConfigs.debug
versionNameSuffix "-dev [${getGitHash()}]"
versionNameSuffix "-dev"
applicationIdSuffix ".debug"
}

@@ -0,0 +1,117 @@
##
# Required images
#
# In order for this to run you need to deploy the Pixite Android cloud builders.
#
# ```bash
# git clone git@github.com:pixiteapps/android-cloud-build /tmp/android-cloud-build
# cd /tmp/android-cloud-build
# gcloud builds submit .
# ```

steps:

# Update the build number
- name: 'gcr.io/$PROJECT_ID/buildnum:1.0'
id: setup_env
waitFor: ['-']
args: ['gs://${_CONFIG_BUCKET}/buildnum']

- name: gcr.io/cloud-builders/gcloud
id: generate_cache_key
entrypoint: bash
waitFor: ['-']
args:
- -c
- |
./checksum.sh checksum.txt
- name: gcr.io/$PROJECT_ID/restore_cache:1.0
id: restore_cache
waitFor: ['generate_cache_key']
args:
- --bucket=gs://${_CACHE_BUCKET}
- --key=gradle-$( checksum checksum.txt )

# Build the project
- name: gcr.io/$PROJECT_ID/android:28
id: download_dependencies
args: ['./gradlew', 'dependencies']
<<: &env
env:
- 'TERM=dumb'
- 'GRADLE_USER_HOME=/workspace/.gradle'
# For standard maching, use these options
- 'GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2 -Dkotlin.incremental=false"'
- 'JAVA_TOOL_OPTIONS="-Xmx1024m"'
# For High CPU machine, use these options
# - 'GRADLE_OPTS="-Dorg.gradle.daemon=false -Dkotlin.incremental=false"'
# - 'JAVA_TOOL_OPTIONS="-Xmx4g"'
- 'BRANCH_NAME=$BRANCH_NAME'
- 'ARTIFACT_BUCKET=gs://${_ARTIFACT_BUCKET}'
waitFor:
- setup_env
- restore_cache

- name: 'gcr.io/$PROJECT_ID/android:28'
id: build
args: ['./gradlew', 'bundleDebug', 'assembleDebug', '-Ptivi.versioncode=1']
<<: *env
waitFor:
- download_dependencies

- name: gcr.io/$PROJECT_ID/deploy_to_gcs:1.0
args:
- --path=app/build/outputs
waitFor:
- build
<<: *env

#
# Check
#
- name: gcr.io/$PROJECT_ID/android:28
id: check
args: ['./gradlew', 'check', 'dependencyUpdates']
waitFor:
- build
<<: *env

- name: gcr.io/$PROJECT_ID/deploy_to_gcs:1.0
args:
- --path=app/build/reports
- --path=build/dependencyUpdates
waitFor: ['check']
<<: *env

- name: gcr.io/$PROJECT_ID/deploy_to_gcs:1.0
id: save_test_results
waitFor: ['check']
entrypoint: bash
<<: *env
args:
- -c
- |
mkdir -p junit
find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} junit/ \;
deploy_to_gcs --path=junit
- name: gcr.io/$PROJECT_ID/save_cache:1.0
waitFor: ['check']
args:
- --bucket=gs://${_CACHE_BUCKET}
- --key=gradle-$( checksum checksum.txt )
- --path=/workspace/.gradle/caches
- --path=/workspace/.gradle/wrapper

substitutions:
_ARTIFACT_BUCKET: tivi-build-artifacts
_CACHE_BUCKET: tivi-build-cache
_CONFIG_BUCKET: tivi-build-config

timeout: 1800s

# Uncomment this to use the High CPU machine
# options:
# machineType: 'N1_HIGHCPU_8'
@@ -0,0 +1,48 @@
# we use a gcr.io image and not openjdk:8-jdk-slim because it loads faster in the google Google Cloud Build environment
FROM gcr.io/cloud-builders/javac

LABEL maintainer="ryan@pixiteapps.com"

ENV DEBIAN_FRONTEND=noninteractive

# make Apt non-interactive
RUN echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90builder \
&& echo 'DPkg::Options "--force-confnew";' >> /etc/apt/apt.conf.d/90builder

# Install Dependencies
RUN apt-get update && \
apt-get install -y \
git locales sudo openssh-client ca-certificates tar gzip parallel \
zip unzip bzip2 gnupg curl wget

# Set timezone to UTC by default
RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime

# Use unicode
RUN locale-gen C.UTF-8 || true
ENV LANG=C.UTF-8

ARG sdk_version=sdk-tools-linux-4333796.zip
ARG android_home=/opt/android/sdk

# Install Android SDK
RUN sudo mkdir -p ${android_home} && \
curl --silent --show-error --location --fail --retry 3 --output /tmp/${sdk_version} https://dl.google.com/android/repository/${sdk_version} && \
unzip -q /tmp/${sdk_version} -d ${android_home} && \
rm /tmp/${sdk_version}

# Set environment variables
ENV ANDROID_HOME ${android_home}
ENV ADB_INSTALL_TIMEOUT 120
ENV PATH=${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}

RUN mkdir ~/.android && echo '### User Sources for Android SDK Manager' > ~/.android/repositories.cfg

RUN yes | sdkmanager --licenses && sdkmanager --update

# Update SDK manager and install system image, platform and build tools
RUN sdkmanager \
"tools" \
"platform-tools" \
"build-tools;28.0.3" \
"platforms;android-28"
@@ -0,0 +1,17 @@
# android

This is an image that contains the latest Android SDK and NDK, used to build Android projects.

## Examples

The following examples demonstrate build requests that use this builder.

### Fetch the contents of a remote URL

This `cloudbuild.yaml` extracts a zip archive, overwriting any existing data.

```
steps:
- name: gcr.io/$PROJECT_ID/unzip
args: ['-o', '-q', 'cache.zip']
```
@@ -0,0 +1,5 @@
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/android', '.']

images: ['gcr.io/$PROJECT_ID/android']
@@ -0,0 +1,10 @@
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/tar', './tar']

- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/android', './android']

images:
- 'gcr.io/$PROJECT_ID/tar'
- 'gcr.io/$PROJECT_ID/android'
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

version_file="/config/version.txt"

__LAST_BUILD_NUM=1900

if [ -f "${version_file}" ];then
echo "Reading existing version from ${version_file}"
source "${version_file}"
fi

BUILD_NUM=$((__LAST_BUILD_NUM+1))

echo
echo " Last build number: ${__LAST_BUILD_NUM}"
echo "Updating to build number: ${BUILD_NUM}"

echo "__LAST_BUILD_NUM=${BUILD_NUM}" > "${version_file}"

OUTPUT_FILE=build_environment.sh
echo "export BUILD_NUM=${BUILD_NUM}" > ${OUTPUT_FILE}

echo "Wrote output file: ${OUTPUT_FILE}"
@@ -0,0 +1,6 @@
FROM launcher.gcr.io/google/ubuntu16_04

RUN apt-get update && \
apt-get -y install tar bzip2 gzip

ENTRYPOINT ["tar"]
@@ -0,0 +1,28 @@
# tar

This is a tool build to simply invoke the
[`tar`](https://linux.die.net/man/1/tar) command.

Arguments passed to this builder will be passed to `tar` directly.

## Examples

The following examples demonstrate build requests that use this builder.

### Archive and compress caches

This `cloudbuild.yaml` archives and compresses the build cache directories.

```
steps:
- name: gcr.io/$PROJECT_ID/tar
args: ['cpzf', 'cache.tar.gz', '.gradle', '/root/.gradle', '/root/.m2']
```

### Extract an existing archive

```
steps:
- name: gcr.io/$PROJECT_ID/tar
args: ['cpzf', 'cache.tar.gz', '.gradle', '/root/.gradle', '/root/.m2']
```
@@ -0,0 +1,5 @@
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/tar', '.']

images: ['gcr.io/$PROJECT_ID/tar']

0 comments on commit 69c49e8

Please sign in to comment.
You can’t perform that action at this time.