Archive

Archive for the ‘Shell’ Category

GCloud SDK Setup for App Engine Java for Mac

January 18, 2018 Leave a comment

Google Cloud Platform (https://cloud.google.com/) is a cloud infrastructure solution from Google. In the next blog we will build and deploy a simple Spring Boot application on Google Flex App Engine. This writeup covers the setup of the gcloud sdk on Mac OS X for the purpose above.

First check if Python is installed in the OS using one of the following commands

python -V
python --version

 

Download the Google Cloud SDK from this location for your OS https://cloud.google.com/sdk/ .In my case I downloaded the 64bit version for Mac: google-cloud-sdk-157.0.0-darwin-x86_64.tar.gz

Extract the files and then run the command ./install.sh in the directory created. This will install the sdk.
Once installed the output will show the components installed and give some commands that can be run to update the components.

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                  Components                                                 │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│     Status    │                         Name                         │            ID            │    Size   │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions                             │ app-engine-go            │  96.7 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                      │   4.0 MiB │
│ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                 │   3.3 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool                      │ datalab                  │   < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │  15.4 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │  38.1 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │  21.0 MiB │
│ Not Installed │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │  14.5 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │   2.3 MiB │
│ Not Installed │ gcloud Alpha Commands                                │ alpha                    │   < 1 MiB │
│ Not Installed │ gcloud Beta Commands                                 │ beta                     │   < 1 MiB │
│ Not Installed │ gcloud app Java Extensions                           │ app-engine-java          │ 132.2 MiB │
│ Not Installed │ gcloud app PHP Extensions (Mac OS X)                 │ app-engine-php-darwin    │  21.9 MiB │
│ Not Installed │ gcloud app Python Extensions                         │ app-engine-python        │   6.4 MiB │
│ Not Installed │ kubectl                                              │ kubectl                  │  14.8 MiB │
│ Installed     │ BigQuery Command Line Tool                           │ bq                       │   < 1 MiB │
│ Installed     │ Cloud SDK Core Libraries                             │ core                     │   6.1 MiB │
│ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                   │   2.9 MiB │
│ Installed     │ Default set of gcloud commands                       │ gcloud                   │           │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘

 
Based on the input provided by you, the bash_profile will be updated and the PATH will be set for gcloud.
Once this is done run the following command

gcloud init

This will prompt you to login to your account. This along with some more input will provide the initial setup for the components. Once done the process will also give an option to use an existing project on Google Cloud, or , create a new one. Select a new project and proceed.

In order to develop a Java application on Google App Engine we require the app engine components. We will install those components now by running the following command.

gcloud components install app-engine-java

This should complete the setup for the sdk. The rest of the information/steps is optional.

Eclipse Plugin for Development
I tried to use the Eclipse plugin but was outdated at the time and works only for the standard App Engine (not for the Flex app engine). Have been using the command line for the push since then.

Misc Commands
Here are some other commands that might be useful in future development.

Used to set a Project for the SDK

gcloud config set project PROJECT_NAME 

List of configuration parameters that have been set(includes account, usage reporting flag and project name)

gcloud config list

List of authorized accounts and the one being used actively

gcloud auth list

Used to update the components in the sdk that was installed.

gcloud components update

Reference: https://cloud.google.com/sdk/

Multiple versions of Java on Mac OS X

January 18, 2018 Leave a comment

I was working on the Google Cloud platform a couple of months back when Java 8 was not supported on the Standard App Engine. However, the Flex engine had Java 8 support (currently even the standard has support for it). When trying out Standard Vs Flex, I had to find something to switch between the Java versions. Jenv came to the rescue (http://www.jenv.be/)

The following steps show how to work with jenv on Mac OS X. (Java 8 was already installed on my OS.)

Use Homebrew to install some packages. Brew is the command for Homebrew (https://brew.sh/) and Homebrew is the package manager for Mac.

Update Homebrew and install Cask if it is not installed already(Cask is an extension of brew for graphical applications)

brew update && brew cask 

Update the repositories in brew to use caskroom/versions

brew tap caskroom/versions

Install Java7 from Caskroom versions

brew cask install java7

Use brew to install jenv

brew install jenv

The following command gives the list of versions of Java installed. The one with the * is the one being used globally

jenv versions 

To install a new version, first we need to make the versions dir

mkdir /Users/codesilo/.jenv/versions

Then add the Java (installed by cask earlier) to the versions of jenv by using the following command

jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/

Use the following command to set the selected install as the global jenv version to be used

jenv global oracle64-1.7.0.80

The versions command will give the following result now

$ jenv versions
  system
  1.7
  1.7.0.80
  1.8
  1.8.0.101
* oracle64-1.7.0.80 (set by /Users/codesilo/.jenv/version)
  oracle64-1.8.0.101

You can also configure directory level version (local version) or shell instance version by using the following commands

$ jenv local oracle64-1.7.0.80
$ jenv shell oracle64-1.7.0.80

 

Categories: Java, Shell Tags: , , , , , , ,