A simple guestbook webapp written in java using Spring Boot..
updating 123
- In dev environment:
gradle bootRun
- In prod environment: Create runnable jar (see Build), and start it with
java -Dspring.profiles.active=prod -jar app.jar
Following procedure describes how to build a Docker Image and push it to the registry.
Assuming you're working directory is the project root.
- Build Runnable Jar:
gradle bootJar
- Build Docker Image:
docker build -t registry.gitlab.com/mn94/guestbook:latest .
- (optional) Login to Registry:
docker login registry.gitlab.com
- Push to Registry:
docker push registry.gitlab.com/mn94/guestbook:latest
- The schema DDL can be found in the project root
schema.sql
. - To regenerate the
schema.sql
based on the JPA entities follow this approach.
Before deploying the webapp, the application stack needs to be setup properly. This is meant to be a unique task (per deployment system), which includes setting up a docker network, a MySQL container, an inspector container as well as creating the initial schema.
- Create Network:
docker network create --driver=bridge guestbook
- Run MySQL Container:
docker run --name guestbook_db -v guestbook_db:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=guestbook --network guestbook -d mysql:5.7
- Run inspection container:
docker run -dit --name guestbook_inspector --network guestbook alpine ash
- Copy schema to inspection container:
docker cp schema.sql guestbook_inspector:/tmp/schema.sql
(assumingschema.sql
is in your current working directory) - Connect to inspection container:
docker container attach guestbook_inspector
- Install mysql client and curl:
apk update && apk upgrade && apk add mysql-client curl
- Import schema to MySQL DB:
mysql -h guestbook_db -u root -p guestbook < /tmp/schema.sql
- Disconnect from inspection container:
CTRL+P CTRL+Q
Following procedure describes how to deploy the guestbook webapp using docker. The same procedure applies when deploying new versions of the app.
Make sure the application stack has been setup and the Docker Image has been built.
- Delete old container (if exists):
docker container stop guestbook && docker container rm guestbook || true
- (optional) Login to Registry:
docker login registry.gitlab.com
- Pull latest image:
docker pull registry.gitlab.com/mn94/guestbook:latest
- Run container (on port 80 of host):
docker run -d -p 80:8080 --name guestbook --network guestbook registry.gitlab.com/mn94/guestbook:latest