Skip to content

Commit 93540ed

Browse files
committed
Merge pull request #61 from GoogleCloudPlatform/lesv-patch-002
Use ENV in Dockerfile where possible
2 parents d86d52f + 9a6f834 commit 93540ed

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

java/jetty-managed-vm/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ This describes a [Jetty](http://www.eclipse.org/jetty/) based [Servlet](http://w
8181

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

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

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

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

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

java/jetty-managed-vm/bigtable-hello/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
FROM mvm-jetty-v03
1616

17+
ENV BIGTABLE_PROJECT "PROJECT_ID"
18+
ENV BIGTABLE_CLUSTER "CLUSTERID"
19+
ENV BIGTABLE_ZONE "us-central1-b"
20+
1721
# The below line is only needed if you want to run on your local computer
1822
# ENV GOOGLE_APPLICATION_CREDENTIALS=/app/WEB-INF/YOUR_KEY_FILE.json
1923

java/jetty-managed-vm/bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@
3131
*
3232
**/
3333
public class BigtableHelper implements ServletContextListener {
34-
/**
35-
* You need to set your PROJECT_ID, CLUSTER_UNIQUE_ID (typically 'cluster') here, and if different,
36-
* your Zone.
37-
**/
38-
private static final String PROJECT_ID = "PROJECT_ID_HERE";
39-
private static final String CLUSTER_ID = "CLUSTER_UNIQUE_ID";
4034

41-
private static final String ZONE = "us-central1-b";
35+
private static String PROJECT_ID = System.getenv("BIGTABLE_PROJECT");
36+
private static String CLUSTER_ID = System.getenv("BIGTABLE_CLUSTER");
37+
private static String ZONE = System.getenv("BIGTABLE_ZONE");
4238

4339
// The initial connection to Cloud Bigtable is an expensive operation -- We cache this Connection
4440
// 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 {
5955
c.set("google.bigtable.endpoint.host", "bigtable.googleapis.com");
6056
c.set("google.bigtable.admin.endpoint.host", "bigtabletableadmin.googleapis.com");
6157

58+
if (ZONE == null) ZONE = "us-central1-b"; // default
59+
if (PROJECT_ID == null || CLUSTER_ID == null ) {
60+
sc.log("environment variables BIGTABLE_PROJECT, BIGTABLE_CLUSTER, and BIGTABLE_ZONE need to be defined.");
61+
return;
62+
}
63+
6264
c.set("google.bigtable.project.id", PROJECT_ID);
6365
c.set("google.bigtable.cluster.name", CLUSTER_ID);
6466
c.set("google.bigtable.zone.name", ZONE);

java/jetty-managed-vm/bigtable-hello/src/main/webapp/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<html lang="en">
22
<head>
33
<meta name="google-signin-scope" content="profile">
4-
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID_HERE.apps.googleusercontent.com"> -->
4+
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID_HERE.apps.googleusercontent.com" />
55
<script src="https://apis.google.com/js/platform.js" async defer'></script>
66
<script>
77
function obfuscateID(id) { // Our app just wants something unique, so we obfuscate the ID

java/managed-vm-gae/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ SECURITY WARNING - This app will read / write the two tables you create (**`gae-
6868

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

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

7373
1. Build the java artifacts and docker image
7474

java/managed-vm-gae/gae-bigtable-hello/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
FROM gae-4bt
1616

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

2021
ADD target/bigtable-hello-SNAPSHOT/ /app
2122

java/managed-vm-gae/gae-bigtable-hello/src/main/java/com.example.cloud.bigtable.helloworld/BigtableHelper.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@
3131
*
3232
**/
3333
public class BigtableHelper implements ServletContextListener {
34-
/**
35-
* You need to set your PROJECT_ID, CLUSTER_UNIQUE_ID (typically 'cluster') here, and if different,
36-
* your Zone.
37-
**/
38-
private static final String PROJECT_ID = "PROJECT_ID_HERE";
39-
private static final String CLUSTER_ID = "CLUSTER_UNIQUE_ID";
4034

41-
private static final String ZONE = "us-central1-b";
35+
private static String PROJECT_ID = System.getenv("BIGTABLE_PROJECT");
36+
private static String CLUSTER_ID = System.getenv("BIGTABLE_CLUSTER");
37+
private static String ZONE = System.getenv("BIGTABLE_ZONE");
4238

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

58+
if (ZONE == null) ZONE = "us-central1-b"; // default
59+
if (PROJECT_ID == null || CLUSTER_ID == null ) {
60+
sc.log("environment variables BIGTABLE_PROJECT, BIGTABLE_CLUSTER, and BIGTABLE_ZONE need to be defined.");
61+
return;
62+
}
6263
c.set("google.bigtable.project.id", PROJECT_ID);
6364
c.set("google.bigtable.cluster.name", CLUSTER_ID);
6465
c.set("google.bigtable.zone.name", ZONE);

0 commit comments

Comments
 (0)