Creating a working JavaFX demo in the web
I did this working in my BasicDemo
app.
I created my own Dockerfile
and docker-compose.yml
like the following
Dockerfile
FROM amazoncorretto:21
# Update yum and install dependencies
RUN yum update -y && yum install -y \
pango \
cairo \
freetype \
fontconfig && \
yum clean all
# Set the working directory and configure the CMD
WORKDIR /jproserver
CMD ["sh", "-c", "cd /jproserver && ./bin/restart.sh"]
The installations are necessary to run the project in Docker.
Then the docker-compose.yml file:
docker-compose.yml
services:
jpro-demo:
container_name: jpro-demo
build:
context: . # Directory where Dockerfile is located
dockerfile: Dockerfile
ports:
- "7080:8080"
volumes:
- .:/jproserver
restart: always
In my build.gradle
I used an ssh plugin to deploy and run my application id 'org.hidetake.ssh' version '2.11.2'
I created two tasks cleanAll
and deployHome
to basically clean the build directory, down the docker app, and remove the persisted storage of the build. Then the deployHome
moves the build zip, unzips it, then unpacks the parent folder.
plugins {
id 'java'
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
id 'jpro-gradle-plugin'
id 'org.hidetake.ssh' version '2.11.2'
}
/**
More Stuff...
*/
ssh.settings {
knownHosts = file("${System.env.USERPROFILE}/.ssh/known_hosts")
// knownHosts = allowAnyHosts
}
remotes {
homeServer {
host = home_ip // Replace with your instance IP
user = home_user // Replace with your SSH username
identity = file(home_pk) // Replace with the path to your private SSH key
}
}
task cleanAll(dependsOn: 'clean') {
doLast {
ssh.run {
session(remotes.homeServer) {
// delete everything in the jpro folder
execute 'docker compose -f /home/thomas/docker/jpro/docker-compose.yml down -v'
execute 'rm -rf /home/thomas/docker/jpro/*'
}
}
}
}
task deployHome(dependsOn: 'jproRelease') {
doLast {
ssh.run {
session(remotes.homeServer) {
put from: project.file("build/distributions/BasicDemo-jpro.zip"), into: '/home/thomas/docker/jpro/' // Replace with remote path
// unzip the file on the remote server
execute 'unzip /home/thomas/docker/jpro/BasicDemo-jpro.zip -d /home/thomas/docker/jpro/' // Replace with your actual service name
// delete the zip file
execute 'rm /home/thomas/docker/jpro/BasicDemo-jpro.zip'
// Unpack and overwrite all the contents of the BasicDemo-jpro folder into the jpro folder
execute 'cp -r /home/thomas/docker/jpro/BasicDemo-jpro/* /home/thomas/docker/jpro/' // Replace with your actual service name
put from: project.file("Dockerfile"), into: '/home/thomas/docker/jpro/' // Replace with remote path
put from: project.file("docker-compose.yml"), into: '/home/thomas/docker/jpro/' // Replace with remote path
// Restart the service on the remote server
execute 'docker compose -f /home/thomas/docker/jpro/docker-compose.yml up -d --build' // Replace with your actual service name
}
}
}
}