Provide example of using system properties to configure a java application locally and in the cloud
This commit is contained in:
parent
4bfd1770c9
commit
e10708aeef
56
README.md
56
README.md
|
@ -1,55 +1,11 @@
|
|||
appengine-standard-archetype
|
||||
============================
|
||||
# Java legacy secrets example
|
||||
|
||||
This is a generated App Engine Standard Java application from the appengine-standard-archetype archetype.
|
||||
This project was scaffolded from a java app engine example, [see original readme](scaffolded_readme.md). The purpose of this project is just to show how you can pass secrets as system properties to the running java application.
|
||||
|
||||
See the [Google App Engine standard environment documentation][ae-docs] for more
|
||||
detailed instructions.
|
||||
## Local development
|
||||
|
||||
[ae-docs]: https://cloud.google.com/appengine/docs/java/
|
||||
1. Run `mvn clean appengine:devserver -DMY_SECRET_KEY=cookies-are-great`. This will start a local development server on http://localhost:8080 displaying the contents of the provided `MY_SECRET_KEY` secret.
|
||||
|
||||
## Deployment
|
||||
|
||||
* [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
|
||||
* [Maven](https://maven.apache.org/download.cgi) (at least 3.5)
|
||||
* [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud)
|
||||
|
||||
## Setup
|
||||
|
||||
gcloud init
|
||||
gcloud auth application-default login
|
||||
|
||||
## Maven
|
||||
### Running locally
|
||||
|
||||
mvn appengine:devserver
|
||||
|
||||
### Deploying
|
||||
|
||||
mvn appengine:update
|
||||
|
||||
## Testing
|
||||
|
||||
mvn verify
|
||||
|
||||
As you add / modify the source code (`src/main/java/...`) it's very useful to add
|
||||
[unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting)
|
||||
to (`src/main/test/...`). The following resources are quite useful:
|
||||
|
||||
* [Junit4](http://junit.org/junit4/)
|
||||
* [Mockito](http://mockito.org/)
|
||||
* [Truth](http://google.github.io/truth/)
|
||||
|
||||
## Updating to latest Artifacts
|
||||
|
||||
An easy way to keep your projects up to date is to use the maven [Versions plugin][versions-plugin].
|
||||
|
||||
mvn versions:display-plugin-updates
|
||||
mvn versions:display-dependency-updates
|
||||
mvn versions:use-latest-versions
|
||||
|
||||
Note - Be careful when changing `javax.servlet` as App Engine Standard uses 3.1 for Java 8, and 2.5
|
||||
for Java 7.
|
||||
|
||||
Our usual process is to test, update the versions, then test again before committing back.
|
||||
|
||||
[plugin]: http://www.mojohaus.org/versions-maven-plugin/
|
||||
1. Run `mvn appengine:update -DMY_SECRET_KEY=cookies-are-great` to deploy an application to the cloud together with the provided `MY_SECRET_KEY` secret.
|
11
pom.xml
11
pom.xml
|
@ -15,6 +15,7 @@
|
|||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
|
||||
<archiveClasses>true</archiveClasses>
|
||||
<MY_SECRET_KEY>See readme for configuration</MY_SECRET_KEY>
|
||||
</properties>
|
||||
|
||||
<prerequisites>
|
||||
|
@ -126,6 +127,16 @@
|
|||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<!-- in order to interpolate version from pom into appengine-web.xml -->
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
|
||||
<filtering>true</filtering>
|
||||
<targetPath>WEB-INF</targetPath>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
|
|
55
scaffolded_readme.md
Normal file
55
scaffolded_readme.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
appengine-standard-archetype
|
||||
============================
|
||||
|
||||
This is a generated App Engine Standard Java application from the appengine-standard-archetype archetype.
|
||||
|
||||
See the [Google App Engine standard environment documentation][ae-docs] for more
|
||||
detailed instructions.
|
||||
|
||||
[ae-docs]: https://cloud.google.com/appengine/docs/java/
|
||||
|
||||
|
||||
* [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
|
||||
* [Maven](https://maven.apache.org/download.cgi) (at least 3.5)
|
||||
* [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud)
|
||||
|
||||
## Setup
|
||||
|
||||
gcloud init
|
||||
gcloud auth application-default login
|
||||
|
||||
## Maven
|
||||
### Running locally
|
||||
|
||||
mvn appengine:devserver
|
||||
|
||||
### Deploying
|
||||
|
||||
mvn appengine:update
|
||||
|
||||
## Testing
|
||||
|
||||
mvn verify
|
||||
|
||||
As you add / modify the source code (`src/main/java/...`) it's very useful to add
|
||||
[unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting)
|
||||
to (`src/main/test/...`). The following resources are quite useful:
|
||||
|
||||
* [Junit4](http://junit.org/junit4/)
|
||||
* [Mockito](http://mockito.org/)
|
||||
* [Truth](http://google.github.io/truth/)
|
||||
|
||||
## Updating to latest Artifacts
|
||||
|
||||
An easy way to keep your projects up to date is to use the maven [Versions plugin][versions-plugin].
|
||||
|
||||
mvn versions:display-plugin-updates
|
||||
mvn versions:display-dependency-updates
|
||||
mvn versions:use-latest-versions
|
||||
|
||||
Note - Be careful when changing `javax.servlet` as App Engine Standard uses 3.1 for Java 8, and 2.5
|
||||
for Java 7.
|
||||
|
||||
Our usual process is to test, update the versions, then test again before committing back.
|
||||
|
||||
[plugin]: http://www.mojohaus.org/versions-maven-plugin/
|
|
@ -27,7 +27,8 @@ public class HelloAppEngine extends HttpServlet {
|
|||
public static String getInfo() {
|
||||
return "Version: " + System.getProperty("java.version")
|
||||
+ " OS: " + System.getProperty("os.name")
|
||||
+ " User: " + System.getProperty("user.name");
|
||||
+ " User: " + System.getProperty("user.name")
|
||||
+ " Secret: " + System.getProperty("MY_SECRET_KEY");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
<threadsafe>true</threadsafe>
|
||||
<system-properties>
|
||||
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
|
||||
<property name="MY_SECRET_KEY" value="${MY_SECRET_KEY}" />
|
||||
</system-properties>
|
||||
</appengine-web-app>
|
||||
|
|
Reference in a new issue