Skip to content

Commit

Permalink
Merge pull request #61 from GoogleCloudPlatform/lesv-patch-002
Browse files Browse the repository at this point in the history
Use ENV in Dockerfile where possible
  • Loading branch information
lesv committed Jul 24, 2015
2 parents d86d52f + 9a6f834 commit 93540ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
3 changes: 1 addition & 2 deletions java/jetty-managed-vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ This describes a [Jetty](http://www.eclipse.org/jetty/) based [Servlet](http://w

`cd jetty-docker; docker build -t mvm-jetty-v03 .;cd ../bigtable-hello`

1. Edit `src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java` to set `PROJECT_ID`, `CLUSTER_UNIQUE_ID`, and `ZONE` (if necessary)
1. Edit `Dockerfile` to set `BIGTABLE_PROJECT`, `BIGTABLE_CLUSTER`, and `BIGTABLE_ZONE` (if necessary)

1. Edit `src/main/webapp/index.html` to set `google-signin-client_id`

1. Edit `Dockerfile` and set **`FROM`** to be the recently built `mvm-jetty-v03` image.

1. Copy your keyfile *.json to `src/main/webapp/WEB-INF`

Expand Down
4 changes: 4 additions & 0 deletions java/jetty-managed-vm/bigtable-hello/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

FROM mvm-jetty-v03

ENV BIGTABLE_PROJECT "PROJECT_ID"
ENV BIGTABLE_CLUSTER "CLUSTERID"
ENV BIGTABLE_ZONE "us-central1-b"

# The below line is only needed if you want to run on your local computer
# ENV GOOGLE_APPLICATION_CREDENTIALS=/app/WEB-INF/YOUR_KEY_FILE.json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
*
**/
public class BigtableHelper implements ServletContextListener {
/**
* You need to set your PROJECT_ID, CLUSTER_UNIQUE_ID (typically 'cluster') here, and if different,
* your Zone.
**/
private static final String PROJECT_ID = "PROJECT_ID_HERE";
private static final String CLUSTER_ID = "CLUSTER_UNIQUE_ID";

private static final String ZONE = "us-central1-b";
private static String PROJECT_ID = System.getenv("BIGTABLE_PROJECT");
private static String CLUSTER_ID = System.getenv("BIGTABLE_CLUSTER");
private static String ZONE = System.getenv("BIGTABLE_ZONE");

// The initial connection to Cloud Bigtable is an expensive operation -- We cache this Connection
// to speed things up. For this sample, keeping them here is a good idea, for
Expand All @@ -59,6 +55,12 @@ public static void connect() throws IOException {
c.set("google.bigtable.endpoint.host", "bigtable.googleapis.com");
c.set("google.bigtable.admin.endpoint.host", "bigtabletableadmin.googleapis.com");

if (ZONE == null) ZONE = "us-central1-b"; // default
if (PROJECT_ID == null || CLUSTER_ID == null ) {
sc.log("environment variables BIGTABLE_PROJECT, BIGTABLE_CLUSTER, and BIGTABLE_ZONE need to be defined.");
return;
}

c.set("google.bigtable.project.id", PROJECT_ID);
c.set("google.bigtable.cluster.name", CLUSTER_ID);
c.set("google.bigtable.zone.name", ZONE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile">
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID_HERE.apps.googleusercontent.com"> -->
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID_HERE.apps.googleusercontent.com" />
<script src="https://apis.google.com/js/platform.js" async defer'></script>
<script>
function obfuscateID(id) { // Our app just wants something unique, so we obfuscate the ID
Expand Down
2 changes: 1 addition & 1 deletion java/managed-vm-gae/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SECURITY WARNING - This app will read / write the two tables you create (**`gae-

`docker build -t gae-4bt . && cd ../gae-bigtable-hello`

1. Edit `src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java` to set `PROJECT_ID`, `CLUSTER_UNIQUE_ID`, and `ZONE` (if necessary)
1. Edit `Dockerfile` to set `BIGTABLE_PROJECT`, `BIGTABLE_CLUSTER`, and `BIGTABLE_ZONE` (if necessary)

1. Build the java artifacts and docker image

Expand Down
5 changes: 3 additions & 2 deletions java/managed-vm-gae/gae-bigtable-hello/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

FROM gae-4bt

# The below line is only needed if you want to run on your local computer
# ENV GOOGLE_APPLICATION_CREDENTIALS=/app/WEB-INF/YOUR_KEY_FILE.json
ENV BIGTABLE_PROJECT "PROJECTID"
ENV BIGTABLE_CLUSTER "CLUSTERID"
ENV BIGTABLE_ZONE "us-central1-b"

ADD target/bigtable-hello-SNAPSHOT/ /app

Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
*
**/
public class BigtableHelper implements ServletContextListener {
/**
* You need to set your PROJECT_ID, CLUSTER_UNIQUE_ID (typically 'cluster') here, and if different,
* your Zone.
**/
private static final String PROJECT_ID = "PROJECT_ID_HERE";
private static final String CLUSTER_ID = "CLUSTER_UNIQUE_ID";

private static final String ZONE = "us-central1-b";
private static String PROJECT_ID = System.getenv("BIGTABLE_PROJECT");
private static String CLUSTER_ID = System.getenv("BIGTABLE_CLUSTER");
private static String ZONE = System.getenv("BIGTABLE_ZONE");

// The initial connection to Cloud Bigtable is an expensive operation -- We cache this Connection
// to speed things up. For this sample, keeping them here is a good idea, for
Expand All @@ -59,6 +55,11 @@ public static void connect() throws IOException {
c.set("google.bigtable.endpoint.host", "bigtable.googleapis.com");
c.set("google.bigtable.admin.endpoint.host", "bigtabletableadmin.googleapis.com");

if (ZONE == null) ZONE = "us-central1-b"; // default
if (PROJECT_ID == null || CLUSTER_ID == null ) {
sc.log("environment variables BIGTABLE_PROJECT, BIGTABLE_CLUSTER, and BIGTABLE_ZONE need to be defined.");
return;
}
c.set("google.bigtable.project.id", PROJECT_ID);
c.set("google.bigtable.cluster.name", CLUSTER_ID);
c.set("google.bigtable.zone.name", ZONE);
Expand Down

0 comments on commit 93540ed

Please sign in to comment.