- Set up project structure
- Explain modifications
- Automate deployment using shell scripts, called from a Makefile
- enable debugging in IntelliJ IDEA
This process will vary slightly between windows and mac.
- If(windows) you will need to create a custom Ubuntu VM in VirtualBox.
- The steps for this are in "Docker Setup on Windows.docx"
- Special thanks to Jamie Jackson for discovering this solution, and to Hootan Vazhbakht for documenting the steps
- ant
- make
- keytool
- JDK
1. Begin by opening the templates and understanding the comments provided
in this example for Dockerfile and docker-compose.yml.
* in tomcat-9-server.xml, search for 'TODO' to find
* and modify the https and database config settings
2. Build all necessary files to build your application.
i. Create a directory for docker to keep things neat.
ii. inside $root/docker running tree gives me the following output
$ project/docker> tree -a
.
├── .keystore
|-- Dockerfile
├── README.md
├── docker-compose.yml
├── myproject.war
└── tomcat-9-server.xml
3. Create any files you don't have already
* it's a good idea to include a readme.md to explain how to launch your project.
* this helps with onboarding.
4. If you need to create a .keystore, run the following command
$ /docker> keytool -genkey -keystore .keystore -alias tomcat -keyalg RSA
* if you don't have keytool as an ailas *
* Run from the absolute path to the keytool > $JAVA_HOME/bin/keytool
5. If you need server.xml, find the template in tomcat's documentation for
the version you need and add your database configuration.
* remember to search the provided template for 'TODO'
* to find and modify the correct blocks
- docker-compose.yml
- builds the custom image specified in Dockerfile
- maps ports from the docker container to the host machine
note if on windows, your host machine will be the Ubuntu VM you created.
these ports will need to be fed from Ubuntu to Windows through VirtualBox - mounts warfile as a volume from the host to the container
- Dockerfile
- Defines the image
- copies the files from the host into the image
- run commands when the container launches
- server.xml
- Defines ports on which the application will run
- Defines database and http/https connection properties
- .keystore
- Allows application to run on https
- Make sure to set the password in server.xml!
- myproject.war
- Contains the compressed application itself
- Tomcat will automatically deploy the warfile if you have the correct settings in server.xml. ie:
<Host>...unpackWARs=true...autoDeploy=true...
<Context>...reloadable=true...</Context>...</Host>
- README.md
- The purpose of the README.md is to provide documentation for easy and painless environment setup when onboarding.
- Consider making this README.md a step-by-step guide with explanation plain enough for someone with minimal technical expertise, but advanced enough for an expert to be able to expand upon your work.
1. In the project_root, create a directory for ./scripts, and a Makefile
$ tree
.
├── docker
|-- scripts
├── web
├── (your_other_stuff)
└── Makefile
war:
bash scripts/make_war.sh
reload:
bash scripts/reload.sh
- Example commands from $project_root:
$ make war
-or-
$ make reload
#!/bin/sh
ant -f ../myProjBuild.xml && \
cp ../myProjDist/myproject.war ../docker && \
cd ../docker && \
docker-compose down && \
docker-compose up -d --build
#!/bin/sh
ant -f ../myProjBuild.xml && \
cp ../myProjDist/myproject.war ../docker && \
cd ../docker && \
docker restart docker_myproject_1
- Run > Debug > Edit Configurations
- Select "remote"
- Port: 8000 (or wherever you set the port to expose in your docker-compose.yml)
- module: myproject (the root directory of your application)