From 9a6f834f1cb79672fdc0bb7b59193db4c787f7dd Mon Sep 17 00:00:00 2001 From: Les Vogel Date: Thu, 23 Jul 2015 21:22:37 -0700 Subject: [PATCH] Use ENV in Dockerfile where possible --- java/jetty-managed-vm/README.md | 3 +-- java/jetty-managed-vm/bigtable-hello/Dockerfile | 4 ++++ .../BigtableHelper.java | 16 +++++++++------- .../bigtable-hello/src/main/webapp/index.html | 2 +- java/managed-vm-gae/README.md | 2 +- .../managed-vm-gae/gae-bigtable-hello/Dockerfile | 5 +++-- .../BigtableHelper.java | 15 ++++++++------- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/java/jetty-managed-vm/README.md b/java/jetty-managed-vm/README.md index 4faa9ee8..fb366f5c 100644 --- a/java/jetty-managed-vm/README.md +++ b/java/jetty-managed-vm/README.md @@ -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` diff --git a/java/jetty-managed-vm/bigtable-hello/Dockerfile b/java/jetty-managed-vm/bigtable-hello/Dockerfile index 277a2075..a8243083 100644 --- a/java/jetty-managed-vm/bigtable-hello/Dockerfile +++ b/java/jetty-managed-vm/bigtable-hello/Dockerfile @@ -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 diff --git a/java/jetty-managed-vm/bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java b/java/jetty-managed-vm/bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java index ba6e5a1e..1f3cbd0e 100644 --- a/java/jetty-managed-vm/bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java +++ b/java/jetty-managed-vm/bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java @@ -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 @@ -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); diff --git a/java/jetty-managed-vm/bigtable-hello/src/main/webapp/index.html b/java/jetty-managed-vm/bigtable-hello/src/main/webapp/index.html index 1a506085..2390a025 100644 --- a/java/jetty-managed-vm/bigtable-hello/src/main/webapp/index.html +++ b/java/jetty-managed-vm/bigtable-hello/src/main/webapp/index.html @@ -1,7 +1,7 @@ - --> +