Skip to content

Commit 9ff8e24

Browse files
committed
update readme
1 parent 615a317 commit 9ff8e24

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pkg
12
target

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM tomcat:8.5
2+
MAINTAINER Tung Nguyen <[email protected]>
3+
4+
# Debugging tools: A few ways to handle debugging tools.
5+
# Trade off is a slighltly more complex volume mount vs keeping the image size down.
6+
RUN apt-get update && \
7+
apt-get install -y \
8+
net-tools \
9+
tree \
10+
vim && \
11+
rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get purge
12+
13+
RUN echo "export JAVA_OPTS=\"-Dapp.env=staging\"" > /usr/local/tomcat/bin/setenv.sh
14+
COPY pkg/demo.war /usr/local/tomcat/webapps/demo.war
15+
16+
EXPOSE 8080
17+
CMD ["catalina.sh", "run"]

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,48 @@
22

33
Simple java project demos how to build a war file to be deployed on a Tomcat server.
44

5+
## Build
56

7+
The build script uses `mvn package` to produce a demo.war file and then bundles it with a Docker image that runs Tomcat. Usage:
68

9+
```sh
10+
bin/build
11+
```
12+
13+
## What happened
714

15+
* mvn package was ran and the `target/demo.war` was moved into `pkg/demo.war`
16+
* a docker image was built which copied the `pkg/demo.war` to `/usr/local/tomcat/webapps/demo.war`. Check out the [Dockerfile](Dockerfile) for details.
817

18+
Here's an example of some things to check after running the build script:
919

20+
```
21+
$ ls pkg/demo.war
22+
pkg/demo.war
23+
$ docker images
24+
REPOSITORY TAG IMAGE ID CREATED SIZE
25+
demo-java latest 88092dfb7325 6 minutes ago 591MB
26+
tomcat 8.5 a92c139758db 2 weeks ago 558MB
27+
$
28+
```
29+
30+
## Run
31+
32+
To run and test that Tomcat is serving the the war file:
33+
34+
```
35+
docker run --rm -p 8080:8080 demo-java
36+
```
37+
38+
Then you can hit the the [HOSTNAME]:8080/demo/Hello and to verify that Tomcat is servering the demo.war file. You should see an html page that says "Hello World"
1039

1140
## Initial Generation
1241

13-
The initial files and project structure was generated with the `mvn archetype:generate` command. Note, you do not have to run the command it is just noted here for posterity. More info: [Creating a webapp](https://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/webapp.html) and [Introduction to the Standard Directory Layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html).
42+
Here are some notes on the initial generation of the project. The initial files and project structure was generated with the `mvn archetype:generate` command. Note, you do not have to run the command it is just noted here for posterity. More info: [Creating a webapp](https://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/webapp.html) and [Introduction to the Standard Directory Layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html).
43+
44+
Change were made like adding a simple [Hello.java](src/main/java/Hello.java) Serlvet class.
45+
46+
The original command was:
1447

1548
``` sh
1649
mvn archetype:generate \
@@ -19,4 +52,3 @@ mvn archetype:generate \
1952
-DartifactId=demo \
2053
-DarchetypeArtifactId=maven-archetype-webapp
2154
```
22-

bin/build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash -exu
2+
3+
mvn package
4+
# move the artifact into pkg so we do not have to send the whole target file
5+
# to the docker build context. We will dockerignore target.
6+
mkdir -p pkg
7+
mv target/demo.war pkg/demo.war
8+
9+
docker build -t demo-java .

0 commit comments

Comments
 (0)