Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Add Google Cloud SDK #36

Merged
merged 11 commits into from
Nov 22, 2016
Merged

Add Google Cloud SDK #36

merged 11 commits into from
Nov 22, 2016

Conversation

bootstraponline
Copy link
Contributor

@bootstraponline bootstraponline commented Nov 21, 2016

@viktorbenei
Copy link
Contributor

Thanks for the PR!

A note: please don't change the HOME env!
Also, see the related GH issue for an alternative way of using the google cloud SDK, using the official google cloud sdk docker image and docker run: https://github.com/bitrise-docker/android/issues/35#issuecomment-262001948

# --- https://firebase.google.com/docs/test-lab/command-line

# Install the Google Cloud SDK.
ENV HOME /
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't change the HOME env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

# Install the Google Cloud SDK.
ENV HOME /
ENV CLOUDSDK_PYTHON_SITEPACKAGES 1
RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.zip && unzip google-cloud-sdk.zip && rm google-cloud-sdk.zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SDK is available as an official apt package, it's usually better to use that. See the apt-get (Debian and Ubuntu only) section at https://cloud.google.com/sdk/downloads?hl=sr#linux

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apt provides no control over the configuration, for example installing only the beta components. These steps are from the official Docker image (where they also don't install via apt).

I will test to see if the apt install contains the necessary components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apt provides no control over the configuration, for example installing only the beta components.

AFAIK the apt versions include every component - or do you mean that there are components which are not available in the APT version?

Copy link
Contributor Author

@bootstraponline bootstraponline Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the apt versions include every component

No, certain components are broken out into dedicated packages.

Optionally install any of these additional components:
google-cloud-sdk-app-engine-python
google-cloud-sdk-app-engine-java
google-cloud-sdk-datastore-emulator
google-cloud-sdk-pubsub-emulator
google-cloud-sdk-bigtable-emulator
kubectl

I don't see one for beta which is required for testing. I'll know for sure in a bit once I finish exploring the package.

Update: beta is installed by default.
https://github.com/bitrise-docker/android/issues/35#issuecomment-262027376

@viktorbenei
Copy link
Contributor

Error for the first build:

Removing intermediate container 230d2b629f97
Step 62 : RUN sed -i -- 's/\"disable_updater\": false/\"disable_updater\": true/g' /google-cloud-sdk/lib/googlecloudsdk/core/config.json
 ---> Running in 513420058e70
sed: can't read /google-cloud-sdk/lib/googlecloudsdk/core/config.json: No such file or directory
The command '/bin/sh -c sed -i -- 's/\"disable_updater\": false/\"disable_updater\": true/g' /google-cloud-sdk/lib/googlecloudsdk/core/config.json' returned a non-zero code: 2

@bootstraponline
Copy link
Contributor Author

I'm seeing the errors also. I'll post an update once I've confirmed this is working.

&& sudo apt-get install -y -qq google-cloud-sdk

RUN /usr/bin/gcloud config set --installation component_manager/disable_update_check true
RUN sed -i -- 's/\"disable_updater\": false/\"disable_updater\": true/g' /usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/config.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required even if you run gcloud config set --installation component_manager/disable_update_check true ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't gcloud config set --installation component_manager/disable_update_check true enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, see the upstream comment:

# Disable updater completely.
# Running `gcloud components update` doesn't really do anything in a union FS.
# Changes are lost on a subsequent run.
RUN sed -i -- 's/\"disable_updater\": false/\"disable_updater\": true/g' /google-cloud-sdk/lib/googlecloudsdk/core/config.json

I also manually confirmed that gcloud config set never updates the config.json file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thank you!

# --- https://firebase.google.com/docs/test-lab/command-line
# --- https://cloud.google.com/sdk/downloads?hl=sr#linux

ENV CLOUD_SDK_REPO="cloud-sdk-xenial"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" would be better, without that we'll have to update this variable from xenial when we update the base Ubuntu version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back ticks should work, we use it here for example: https://github.com/bitrise-docker/bitrise-base/blob/master/Dockerfile#L95

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bootstraponline
Copy link
Contributor Author

Ok, this is ready for review.

  • docker-compose build completes successfully.
  • gcloud version lists all the relevant version info for the system report.


ENV CLOUD_SDK_REPO="cloud-sdk-xenial"

RUN echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, as $CLOUD_SDK_REPO is not used anywhere else, we could remove the ENV line and instead include

cloud-sdk-`lsb_release -c -s`

here directly, like:

RUN echo "deb https://packages.cloud.google.com/apt cloud-sdk-`lsb_release -c -s` main"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, I will make this update.

@bootstraponline
Copy link
Contributor Author

I think I've addressed all the feedback. Let me know if I missed anything.

@@ -23,6 +23,7 @@ ver_line="$(gradle --version | grep 'Gradle ')" ; echo "* Gradle: $ver_line"
ver_line="$(mvn --version | grep 'Apache Maven')" ; echo "* Maven: $ver_line"
ver_line="$(fastlane --version | grep 'fastlane ')" ; echo "* Fastlane: $ver_line"
ver_line="$( javac -version 2>&1 )" ; echo "* Java: $ver_line"
gcloud version # Lists all gcloud components
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this isn't a one liner, please move it into a separate section like https://github.com/bitrise-docker/android/pull/36/files#diff-1311e47d25cde7d83a0381e5c2b5d06eR32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@viktorbenei
Copy link
Contributor

Looks good - hopefully the tests will pass (a full round of test takes ~35 mins right now, as it does a full, clean docker build)

@bootstraponline
Copy link
Contributor Author

Tests passed.

@viktorbenei viktorbenei merged commit 0bed835 into bitrise-io:master Nov 22, 2016
@viktorbenei
Copy link
Contributor

LGTM, thank you @bootstraponline !

Release Schedule: as usual, the Android stack will be updated/released during the weekend, your changes will be available at the end of this week.

Thanks for the contribution, and Happy Building! :) 🎉

@viktorbenei
Copy link
Contributor

@bootstraponline I made a couple of minor (style) changes, for easier future maintenance - if you have the time feel free to 👍 / 👎 the PR: #37

@bootstraponline bootstraponline deleted the firebase_test_lab branch November 22, 2016 14:00
@bootstraponline
Copy link
Contributor Author

@bootstraponline I made a couple of minor (style) changes, for easier future maintenance - if you have the time feel free to 👍 / 👎 the PR: #37

+1ed.

Thanks for the awesome contribution process. It's great to have rapid feedback & a fast deploy cycle.

@viktorbenei
Copy link
Contributor

Thanks for the PR! ;)

Btw technically your change is now available in the -alpha docker image on Docker Hub, but you should not use that on bitrise.io, as those images are not pre cached, and are used only for daily tests.

@bootstraponline
Copy link
Contributor Author

@viktorbenei hey does gcloud info --run-diagnostics work for you? I get this in the container:

root@c9476a01207e:/bitrise/tmp/android#  gcloud info --run-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
ERROR: Reachability Check failed.
    Cannot reach https://cloudresourcemanager.googleapis.com/v1beta1/projects (ServerNotFoundError)
    Cannot reach https://www.googleapis.com/auth/cloud-platform (ServerNotFoundError)
    Cannot reach https://dl.google.com/dl/cloudsdk/channels/rapid/components-2.json (ServerNotFoundError)
Network connection problems may be due to proxy or firewall settings.

@viktorbenei
Copy link
Contributor

That seems like a network config issue on your Mac @bootstraponline - I don't have a VM/machine with the pre release image yet.

@bootstraponline
Copy link
Contributor Author

It works fine outside of the VM so yeah probably Docker is being strange. Hopefully it's not an issue on the production deploy.

@viktorbenei
Copy link
Contributor

It shouldn't be, but we'll see - feel free to add additional tests to the system_report, those are run automatically on every change, and daily on the latest image version (alpha)

@viktorbenei
Copy link
Contributor

(Additional full test builds are performed on the alpha images before release, first ones on Friday before the "feature lock down")

@bootstraponline
Copy link
Contributor Author

I submitted #38 which runs the network check in system_report.

@viktorbenei
Copy link
Contributor

Merged ;)

@bootstraponline
Copy link
Contributor Author

My Android Firebase tests are passing on bitrise. For now I added the install steps from the Dockerfile directly to a workflow. It takes about ~33 seconds to install the google-cloud-sdk package.

It might be nice to have documentation then Google can link people to Bitrise like they do for circle ci.

@viktorbenei
Copy link
Contributor

Awesome idea, and thanks for the links @bootstraponline !

I think this could be encapsulated into a Step too, to make it easy to setup & run tests. Feel free to submit a step if you have the time ;)

@bootstraponline
Copy link
Contributor Author

bootstraponline commented Nov 23, 2016

I encapsulated the logic into an internal Fastlane Ruby step. :)

I tested a bash version as well before porting to Ruby. Might be helpful for someone who wants to write a Bitrise Step.

set -euxo pipefail

mkdir -p ~/.gradle

# remove old daemons
rm -rf ~/.gradle/daemon

echo "org.gradle.jvmargs=-Xmx2560M" > ~/.gradle/gradle.properties

./gradlew :app:assembleDebug :app:assembleDebugAndroidTest > /dev/null

# todo: remove this after Dockerfile deploy next week
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
export DEBIAN_FRONTEND="noninteractive"

echo "deb https://packages.cloud.google.com/apt cloud-sdk-`lsb_release -c -s` main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

sudo apt-get update -qq
sudo apt-get install -y -qq google-cloud-sdk > /dev/null

# now auth to gcloud
echo $GCLOUD_KEY | base64 --decode > "$HOME/gcloudkey.json"
gcloud config set project "$GCLOUD_PROJECT"
gcloud auth activate-service-account --key-file "$HOME/gcloudkey.json" "$GCLOUD_USER"

# run the test!
export APP_APK="/bitrise/src/my/app/build/outputs/apk/app-debug.apk"
export TEST_APK="/bitrise/src/my/app/build/outputs/apk/app-debug-androidTest.apk"

# ensure we don't have old logs
rm -rf gcloud.log

unbuffer \
gcloud beta test android run \
--type instrumentation \
--app "$APP_APK" \
--test "$TEST_APK" \
--results-bucket  my-named-bucket \
--device-ids Nexus9 \
--os-version-ids 25 \
--locales en \
--orientations portrait \
--timeout 25m \
2>&1 | tee gcloud.log

# todo: parse gcloud.log for results bucket link
# and download artifacts with gsutil

@viktorbenei
Copy link
Contributor

Thanks @bootstraponline - I created a Bitrise Contrib ticket for this, and linked your comment/code ;) - bitrise-io/bitrise-contrib#29

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants