I created a Spring sample and tried to build the application into a Docker image and run the application in a Docker container in a Github actions workflow. Then I performed a simple Smoke test to make sure the image is created as expected.
The Docker image is built by the Spring boot maven plugin.
I created a simple docker-compose file to run the application and database together.
version: "3.5" # specify docker-compose version, v3.5 is compatible with docker 17.12.0+
# Define the services/containers to be run
services:
db:
image: mysql:8
ports:
- "3306:3306"
# command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: mysecret
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: testdb
volumes:
- ./data/mysql:/var/lib/mysql
- ./mysql-initdb.d:/docker-entrypoint-initdb.d
app:
image: hantsy/rest-many-to-many-example
depends_on:
- db
ports:
- "8080:8080"
environment:
- "SPRING_PROFILES_ACTIVE=dev"
- "SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/testdb"
In the Github actions workflow file, when running docker-compose command, it seems it can not be accessed via localhost. I created a Java test and used the curl command for test purposes, both failed to connect to http://localhost:8080 in the same flow.
Check out the complete Github actions workflow file.
I also tried to use PublicIP actions to get the public IP and access via the public IP, failed. See the public IP actions step configuration here.
But it worked well on my local machine, accessing http://localhost:8080 is working as expected.