Dockerized, SpringBoot conversion of MiniTwit, a Twitter clone using Spark (Java), Spring, Freemarker, and HSQLDB.
New features in karlkfi/minitwit:
- Spring Boot
- Enhanced ServerProperties config (env var, yaml, etc)
- Executable jar
- Logback logging, instead of slf4j-simple
- Docker container image
- Docker (container image includes all application dependencies)
-
Clone the repository and go to the root directory.
git clone git@github.com:karlkfi/minitwit.git cd minitwit
-
Build the docker image
docker build -t karlkfi/minitwit .
-
Run the docker image in the background
docker run -d --name minitwit karlkfi/minitwit
-
Find the docker container's IP
MINITWIT_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' minitwit)
-
Open MiniTwit in your browser
http://${MINITWIT_IP}:${SERVER_PORT}/
-
Sign up as a new user
If your e-mail address has an associated Gravatar image, this will be used as your profile image.
-
Log in
Use the credentials created in the previous step to log in.
-
Post a message
-
See your message added to the timeline
There are several ways to configure MiniTwit using Spring's ServerProperties, but only a few of them are being mapped to SparkJava.
The following environment variables can be passed to MiniTwit through Docker using environment variables:
Name | Type | Default | Description |
---|---|---|---|
SERVER_PORT | Integer | 80 | Port on which the server will listen |
SPRING_DATASOURCE_URL | String | jdbc:hsqldb: | JDBC path to the database |
SPRING_DATASOURCE_USERNAME | String | jdbc:hsqldb: | Database username |
SPRING_DATASOURCE_PASSWORD | String | <null> | Database password |
SPRING_DATASOURCE_DRIVER-CLASS-NAME | String | <auto-detect> | JDBC Driver class |
SPRING_DATASOURCE_PLATFORM | String | hsqldb | Name of the platform-specific schema to use (hsqldb or mysql) |
By default, MiniTwit uses HyperSQL as an in-memory database.
For persistent storage, use MySQL.
# create mysql environment file
cat > mysql.env << EOF
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=minitwit
MYSQL_USER=minitwit
MYSQL_PASSWORD=minitwit
EOF
# start mysql server
docker run -d --name=mysql --env-file=mysql.env mysql:5.7.15
# find mysql IP
MYSQL_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' mysql)
# create minitwit environment file
cat > minitwit.env << EOF
SPRING_DATASOURCE_URL=jdbc:mysql://${MYSQL_IP}:3306/minitwit?autoReconnect=true&useSSL=false
SPRING_DATASOURCE_USERNAME=minitwit
SPRING_DATASOURCE_PASSWORD=minitwit
SPRING_DATASOURCE_DRIVER-CLASS-NAME=com.mysql.cj.jdbc.Driver
SPRING_DATASOURCE_PLATFORM=mysql
EOF
# start minitwit server
docker run -d --name minitwit --env-file=minitwit.env karlkfi/minitwit
##License MIT License
See LICENSE for details.
- Docker Springboot MiniTwit (c) 2016 Karl Isenberg
- Java MiniTwit (c) 2015 Esteban Herrera
- Flask MiniTwit Example (c) 2015 Armin Ronacher