In this template:
- Spring Boot,
- PostgreSQL,
- Docker,
- GitHub workflows:
- Docker setup, and
- unit and integration tests of the Spring Boot application.
This template has been bootstrapped using this Spring Initializr configuration.
Add CR_PAT
secret to the repository to be able to sign into container
registry. Read more on this in GitHub's
documentation.
export SPRING_DATASOURCE_URL='jdbc:postgresql://database-container:5432/dbname'
export SPRING_DATASOURCE_USERNAME='spring_user'
export SPRING_DATASOURCE_PASSWORD='SpringUserPassword'
export POSTGRES_URL='jdbc:postgresql://localhost:5432'
export POSTGRES_DB='dbname'
export POSTGRES_USER='postgres'
export POSTGRES_PASSWORD='SuperuserPassword'
./bin/run.py --apply-migrations [--debug]
The application is now listening at http://localhost:8080
. If the --debug
option has been used, the debugger is listening on port 8000
.
Defaults such as database and Spring ports, and volume, network, image,
container names can be adjusted inside ./bin/config.ini
.
./bin/teardown.py [--cache --db --network --tmp]
ALTER USER spring_user WITH PASSWORD '<new_password>';
./gradlew test
./bin/integration_tests.py
Returns all welcome messages.
# {"id":"c3f7bfa4-fac9-46bd-b139-866e34b1f83f","content":"Foo"}
curl http://localhost:8080/api/welcome
Stores a new welcome message in the database.
Request body:
content
– welcome message content.
curl \
--request POST \
--header 'Content-Type: application/json' \
--data '{"content": "Bar"}' \
http://localhost:8080/api/welcome
Places around the project that need renaming.
Click here to expand
- .github/workflows/docker.yml:
MAIN_IMAGE: 'renameme'
export POSTGRES_DB='renameme'
export SPRING_DATASOURCE_URL='jdbc:postgresql://renameme-database:5432/renameme'
- bin/:
- config.ini:
database_container = renameme-database
database_test_container = renameme-test-database
network = renameme-network
test_network = renameme-test-network
main_image = renameme
build_image = renameme-gradle-build
- config.ini:
- src/:
- Package name:
src/main/java/me/rename/renameme
src/test/java/me/rename/renameme
- main/resources/:
- db/changelog/20210310-03--create-readwrite-role.sql:
REVOKE ALL ON DATABASE renameme FROM PUBLIC;
GRANT CONNECT ON DATABASE renameme TO readwrite;
--rollback REVOKE CONNECT ON DATABASE renameme FROM readwrite;
--rollback GRANT ALL ON DATABASE renameme TO PUBLIC;
- log4j2.xml:
fileName="log/renameme.log"
filePattern="log/renameme-%d{yyyy-MM-dd}-%i.log.gz"
<IfFileName glob="log/renameme-*.log.gz"/>
- db/changelog/20210310-03--create-readwrite-role.sql:
- test/resources/:
- log4j2.xml:
fileName="log/test/renameme.log"
filePattern="log/test/renameme-%d{yyyy-MM-dd}-%i.log.gz"
<IfFileName glob="log/test/renameme-*.log.gz"/>
- log4j2.xml:
- Package name:
- build.gradle:
group: 'me.rename'
- settings.gradle:
rootProject.name = 'renameme'