How to install Google Cloud SDK on Travis? - google-cloud-platform

I have tried to install Google Cloud SDK on Travis with the following .travis.yml
sudo: required
language: go
- curl https://sdk.cloud.google.com | bash;
My attempt is inspired by this guide from Google: https://cloud.google.com/solutions/continuous-delivery-with-travis-ci
Unfortunately, I get this output on Travis:
$ curl https://sdk.cloud.google.com | bash;
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 421 0 421 0 0 17820 0 --:--:-- --:--:-- --:--:-- 60142
Downloading Google Cloud SDK install script: https://dl.google.com/dl/cloudsdk/channels/rapid/install_google_cloud_sdk.bash
######################################################################## 100.0%
Running install script from: /tmp/tmp.uz8jP70e56/install_google_cloud_sdk.bash
which curl
curl -# -f https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz
######################################################################## 100.0%
Installation directory (this will create a google-cloud-sdk subdirectory) (/home/travis):
Travis waits for 10 minutes and then terminates the build. It seems like it is waiting for an installation directory.
How do I install Google Cloud SDK on Travis?

You are running into this issue because there is no interaction possible on Travis CI. Hence, the installation script is blocked waiting for input and Travis CI kills the build after 10 minutes.
The trick is to disable the prompts when installing the Google Cloud SDK. This can be done by setting the CLOUDSDK_CORE_DISABLE_PROMPTS environment variable to 1.
Here's a sample recipe to put in your .travis.yml file (including caching it for faster subsequent builds):
cache:
directories:
- "$HOME/google-cloud-sdk/"
script:
- gcloud version || true
- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl https://sdk.cloud.google.com | bash; fi
# Add gcloud to $PATH
- source /home/travis/google-cloud-sdk/path.bash.inc
- gcloud version
Hope this helps!

Related

Jenkins for C++ Project with Docker

I want to integrate my C++ project with Jenkins using Docker.
First I created a setup for Jenkins using:
Dockerfile:
FROM jenkins/jenkins:latest
USER root
RUN apt-get update && apt-get install git && apt-get install make g++ -y
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
ENV CASC_JENKINS_CONFIG /var/jenkins_home/casc.yaml
ENV JENKINS_ADMIN_ID=admin
ENV JENKINS_ADMIN_PASSWORD=password
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt
COPY casc.yaml /var/jenkins_home/casc.yaml
plugins.txt
ant:latest
antisamy-markup-formatter:latest
authorize-project:latest
build-timeout:latest
cloudbees-folder:latest
configuration-as-code:latest
credentials-binding:latest
email-ext:latest
git:latest
github-branch-source:latest
gradle:latest
ldap:latest
mailer:latest
matrix-auth:latest
pam-auth:latest
pipeline-github-lib:latest
pipeline-stage-view:latest
ssh-slaves:latest
timestamper:latest
workflow-aggregator:latest
ws-cleanup:latest
casc.yaml
jenkins:
securityRealm:
local:
allowsSignup: false
users:
- id: ${JENKINS_ADMIN_ID}
password: ${JENKINS_ADMIN_PASSWORD}
authorizationStrategy:
globalMatrix:
permissions:
- "USER:Overall/Administer:admin"
- "GROUP:Overall/Read:authenticated"
remotingSecurity:
enabled: true
security:
queueItemAuthenticator:
authenticators:
- global:
strategy: triggeringUsersAuthorizationStrategy
unclassified:
location:
url: http://127.0.0.1:8080/
So far, so good. I used docker build -t jenkins:jcasc . and docker run --name jenkins --rm -p 8080:8080 jenkins:jcasc and Jenkins starts normally. I entered the user name (admin) and the password and it worked.
There are although 2 issues that Jenkins displays:
-> It appears that your reverse proxy set up is broken.
-> Building on the built-in node can be a security issue. You should set up distributed builds. See the documentation.
I ignored them so far, and continued with my project and installed Blue Ocean.
After installing Blue Ocean I connected it to my GitHub repository and for this I created a token and the pipeline was created, but it is not giving any result.
The log says:
Branch indexing
Connecting to https://api.github.com with no credentials, anonymous access
Jenkins-Imposed API Limiter: Current quota for Github API usage has 37 remaining (1 over budget). Next quota of 60 in 36 min. Sleeping for 4 min 43 sec.
Jenkins is attempting to evenly distribute GitHub API requests. To configure a different rate limiting strategy, such as having Jenkins restrict GitHub API requests only when near or above the GitHub rate limit, go to "GitHub API usage" under "Configure System" in the Jenkins settings.
My C++ project looks like this:
-->HelloWorld
|
-->HelloWorld.cpp
-->scripts
|
-->Linux-Build.sh
|
-->Linux-Run.sh
-->Jenkinsfile
HelloWorld.cpp:
#include <iostream>
int main(){
std::cout << "Hello World!" << std::endl;
return 0;
}
Linux-Build.sh
#!/bin/bash
vendor/bin/premake/premake5 gmake2
make
Linux-Run.sh
#!/bin/bash
bin/Debug/HelloWorld
Jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo "Building..."'
sh 'chmod +x scripts/Linux-Build.sh'
sh 'scripts/Linux-Build.sh'
archiveArtifacts artifacts: 'bin/Debug/*', fingerprint: true
}
}
stage('Test') {
steps {
sh 'echo "Running..."'
sh 'chmod +x scripts/Linux-Run.sh'
sh 'scripts/Linux-Run.sh'
}
}
}
}
So, where might be the problem? I don't know if the problem is in my C++ code, or in the Docker configuration.
I am also a big fan of cmake, instead of make and I would prefer to use cmake for this, but I am not sure how to integrate this and make it work.
EDIT:
In the tutorial that I followed there was a "vendor" directory but the instructor didn't show what was in that directory.
EDIT:
The program took 4 minutes but it eventually did something and the error is:
+ scripts/Linux-Build.sh
scripts/Linux-Build.sh: line 3: vendor/bin/premake/premake5: No such file or directory
make: *** No targets specified and no makefile found. Stop.
script returned exit code 2
So, the problem is in the C++ project, not Docker.

Health degraded after downgrading php version for my ZF2 Application

I am trying to setup elastic beanstalk. After selecting PHP 5.6 my application is not deploying and showing the below errors and also my health is showing degraded -
i-08a5a7a9b027a7de9 Severe 16 hours 4 -- -- -- -- -- -- -- -- -- -- 0.00 0.00 0.1 0.0 99.9 0.0
Application update failed at 2019-07-25T13:30:00Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_composer_install.sh failed.
. /opt/elasticbeanstalk/support/envvars-wrapper.sh
++ set +x
++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
EB_APP_STAGING_DIR=/var/app/ondeck
cd /var/app/ondeck
'[' -f composer.json ']'
export COMPOSER_HOME=/root
COMPOSER_HOME=/root
'[' -d vendor ']'
++ /opt/elasticbeanstalk/bin/get-config optionsettings -n aws:elasticbeanstalk:container:php:phpini -o composer_options
PHP_COMPOSER_OPTIONS=
echo 'Found composer.json file. Attempting to install vendors.'
Found composer.json file. Attempting to install vendors.
composer.phar install --no-ansi --no-interaction
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error: Out of memory (allocated 755761152) (tried to allocate 134217728 bytes) in phar:///opt/elasticbeanstalk/support/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
Fatal error: Out of memory (allocated 755761152) (tried to allocate 134217728 bytes) in phar:///opt/elasticbeanstalk/support/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220.
Incorrect application version "Sample Application-3" (deployment 4). Expected version "Sample Application" (deployment 1).
I have already tried to setup first a sample application and then tried to upload my app but didn't work
Try clearing composer cache on your instances, or rebuild environment. See if it helps

Give access to a google storage bucket to Google Build while building a Docker image

I am new to google cloud services and I am trying to set up an automatic build of my production requiring to download a heavy file.
I would like to download a file from a dedicated Google Storage bucket inside the Docker build process. To do so, I have added the following line to my Dockerfile:
RUN curl https://storage.cloud.google.com/[bucketname]/[filename] -o [filename]
Since files from this bucket shouldn't be publicly accessible, I disabled object level permission and added to the member [ProjectID]#cloudbuild.gserviceaccount.com the right Storage Object Viewer.
But when the docker file script run, the file downloaded is empty
Step 7/9 : RUN curl https://storage.cloud.google.com/[bucketname]/[filename] -o [filename]
---> Running in 5d1a5a1bbe87
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Removing intermediate container 5d1a5a1bbe87
---> 42938a9cc8d1
Step 8/9 : RUN ls -l [filename]
---> Running in 34ac112051a1
-rw-r--r-- 1 root root 0 Jun 15 00:37 [filename]
This link works perfectly well if I login in google.console and access it through my navigator.
I tried changing the permission settings, and ended up adding cloud build account, storage legacy bucket reader, storage legacy object reader, storage object viewer together without much success.
I am obviously doing something wrong. But its not clear to me if:
This link format is only valid in the console and I should use an other URL to get this file
The permission configuration is wrong
I still have to process to some http authorization through curl
I am overlooking something else.
Thanks for your help :)
After a long research, try and error, I managed to find out a good way to do it. here is the recipe for those whou may need to reproduce a similar setup, and my future me.
Create a service account in console.cloud.google.com / AIM & Admin dedicated to this task (You can also use cloud shell https://cloud.google.com/iam/docs/creating-managing-service-accounts)
Generate a key for this service account (you can use the web console or type gcloud iam service-accounts keys create ~/key.json --iam-account [SA-NAME]#[PROJECT-ID].iam.gserviceaccount.com in Cloud Shell (https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-gcloud)
Add this file to your repository. Install Cloud Shell to your Docker so that you can log in (right, you are going to install a whole sdk just to log in...) :
RUN curl https://sdk.cloud.google.com | bash > /dev/null
ENV PATH="${PATH}:/root/google-cloud-sdk/bin"
Now, in a shell script run by RUN ./myscript.sh from your docker file, you will add:
Activate your service account with gcloud auth activate-service-account [ACCOUNT] --key-file=~/key.json (https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account)
You can generate an authentification token associated to this account with TOKEN=`gcloud auth print-access-token [ACCOUNT]` (https://cloud.google.com/sdk/gcloud/reference/auth/print-access-token)
Finaly, you can add the curl command :
RUN curl -L -H "Authorization: Bearer [TOKEN]" https://www.googleapis.com/storage/v1/b/[bucketname]/o/[objectname]?alt=media -o filename
I did not used gcloud cp gs://bucketname/bucketfile ./ because python2 was not available in my Docker image and python3 isn't supported by google.
Congratulate yourself with a chocolat cake or a sugary treat. (:
Bonus: If like me your docker build timeout, you have to add a cloudbuild.yaml next to your Dockerfile. Here is a generic file I use for my builds:
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/$REPO_NAME:$BUILD_ID', '.' ]
images:
- 'gcr.io/$PROJECT_ID/$REPO_NAME:$BUILD_ID'
timeout: 900s

Apache Zeppelin 0.7.3 - http error 503 in browser

Following the minimalist installation instructions from here, then on macOS High Sierra 10.13.1 executing:
bin/zeppelin-daemon.sh start
The daemon starts OK, but pointing any browser to http://localhost:8080 yields
HTTP ERROR: 503
Problem accessing /. Reason:
Service Unavailable
Powered by Jetty://
The same thing happens if I run as root, or if I run the browser as root, or if I install via homebrew (brew install apache-zeppelin).
Permissions problem?
What is a solution?
Thanks!
The workaround was:
Install Java 8, following How to set or change the default Java (JDK) version on OS X?, i.e.
brew tap caskroom/versions
brew cask install java8
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Then:
sudo bash
zeppelin-daemon.sh start
/Applications/Safari.app/Contents/MacOS/Safari
Point browser to:
http://localhost:8080
Success! Conclusions:
Zeppelin 0.7.3 only supports Java <= 8.0
zeppelin-daemon.sh must be run as root, but browser doesn't have to be
Install Java 1.8 as mentioned in the above post.
If we can give the super user password at the time of installing, we do not have to run as root every time. See below for the logs and the option to give password.
[ksurendranath#machine /usr/local/Cellar/apache-zeppelin/0.7.3/libexec/logs 10:54 AM ]$ brew cask install java8
==> Tapping caskroom/cask
Cloning into '/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask'...
remote: Counting objects: 4057, done.
remote: Compressing objects: 100% (4022/4022), done.
remote: Total 4057 (delta 37), reused 824 (delta 31), pack-reused 0
Receiving objects: 100% (4057/4057), 1.39 MiB | 11.49 MiB/s, done.
Resolving deltas: 100% (37/37), done.
Tapped 0 formulae (4,066 files, 4.4MB)
==> Creating Caskroom at /usr/local/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password:
Get the process info on the port you are using the Zeppelin server
1)sudo netstat -anp|grep 8080
2)sudo kill (ProcessID)
3)/zeppelin-server/bin/zeppelin-daemon.sh restart
This might help you

Failing to download Leiningen standalone jar file

I am simply unable to install leiningen on Debian linux :
> lein
Downloading Leiningen to /home/debianaut/.lein/self-installs/leiningen-2.4.3-standalone.jar now...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 355 100 355 0 0 240 0 0:00:01 0:00:01 --:--:-- 375
100 14.2M 100 14.2M 0 0 51565 0 0:04:48 0:04:48 --:--:-- 41059
Failed to download https://github.com/technomancy/leiningen/releases/download/2.4.3/leiningen-2.4.3-standalone.jar
It's possible your HTTP client's certificate store does not have the
correct certificate authority needed. This is often caused by an
out-of-date version of libssl. Either upgrade it or set HTTP_CLIENT
to turn off certificate checks:
export HTTP_CLIENT="wget --no-check-certificate -O" # or
export HTTP_CLIENT="curl --insecure -f -L -o"
It's also possible that you're behind a firewall haven't yet
set HTTP_PROXY and HTTPS_PROXY.
I tried with setting HTTP_CLIENT but still same error . The version I read from lein script is 2.4.3.
I also experienced this error. This is what I did in Ubuntu 15.04, with Leiningen 2.5.2.
Save the lein file into the ~bin directory (create it if it doesn't exist).
Change the permissions of the lein file to make it executable (chmod 755 ~/bin/lein)
Open lein with a text editor
On line 116, change .jar to .zip, so that it should be LEIN_JAR="$LEIN_HOME/self-installs/leiningen-$LEIN_VERSION-standalone.zip"
Download Leiningen 2.5.2 from GitHub.
Put the zip file leiningen-2.5.2-standalone.zip into ~/.lein/self-installs (do not unzip - create the directory if it doesn't exist - this is a hidden directory, in Gnome Files, hit Ctrl+H to see it)
To initiate your first project: lein new MyFirstLeinProject
VoilĂ .
I had the same problem using leiningen 2.1.3 on Mac OS X 10.8.5 (Mountain Lion). That script tried to download https://leiningen.s3.amazonaws.com/downloads/leiningen-2.1.3-standalone.jar
Eventually I went back to leiningen.org and fetched the current lein script from https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
It worked well. The resource downloaded was: https://github.com/technomancy/leiningen/releases/download/2.5.1/leiningen-2.5.1-standalone.zip