Ok guys, I need further help.
So there are many combinations of the configuration of the different files (Dockerfile, fly.toml) , and I tried already a ton of them, and I’m so unlucky nothing had worked so far.
I think it’s easier if I copy here my Dockerfile and my fly.toml file too and give more data too, and maybe some of you guys can help me, maybe @rubys ?
Ok, so my Dockerfile is (so I’m totally new with all of these things):
FROM ibm-semeru-runtimes:open-11-jre-focal
WORKDIR /app/public
COPY target/GetYourTravel-0.0.1-SNAPSHOT.jar GetYourTravel-0.0.1-SNAPSHOT.jar
ENV _JAVA_OPTIONS="-XX:MaxRAM=70m"
CMD java $_JAVA_OPTIONS -Dspring.datasource.url=$SPRING_DATASOURCE_URL -Dspring.datasource.username=$SPRING_DATASOURCE_USERNAME -Dspring.datasource.password=$SPRING_DATASOURCE_PASSWORD -jar GetYourTravel-0.0.1-SNAPSHOT.jar
My fly.toml file is (I will leave the SPRING_DATASOURCE_URL and the SPRING_DATASOURCE_USERNAME environments empty by the environment part):
# fly.toml file generated for get-your-travel-app on 2023-03-30T18:07:34+02:00
app = "get-your-travel-app"
kill_signal = "SIGINT"
kill_timeout = 5
primary_region = "ams"
processes = []
[env]
MANAGEMENT_METRICS_EXPORT_PROMETHEUS_ENABLED = "false"
SPRING_DATASOURCE_URL = ""
SPRING_DATASOURCE_USERNAME = ""
_JAVA_OPTIONS = "-XX:MaxRAM=70m"
[experimental]
auto_rollback = true
[mounts]
destination = "/app/public/uploads"
source = "get_your_travel_app_data"
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
[[statics]]
guest_path = "/uploads"
url_prefix = "/app/public/uploads"
(I’ve tried more combinations of guest_path and url_prefix, but of course it’s possible that not everything yet, but really more, this is just the last one.)
My file structure inside my Spring Boot project (I just want you guys could see where my uploads folder is here):
And one other thing, tha classpath part of my Spring Boot app - related to this: https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot what @rubys mentioned above. So this in my case is (I think it should be fine, but if no, tell me please, but this part seems very self-evident):
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/uploads/**")) {
registry
.addResourceHandler("/uploads/**")
.addResourceLocations("classpath:/static/uploads/");
}
if (!registry.hasMappingForPattern("/static/**")) {
registry
.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
}
if (!registry.hasMappingForPattern("/resources/**")) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("classpath:/resources/");
}
}
So, again, my problem is: I can upload new photos via my webpage, and then these new photos will appear in the uploads folder under /app/public/ , so I can see them via flyctl ssh console
. But these uploaded photos don’t appear on my website, somehow I can’t reach them: I use this src attribute of the <img>
(thymeleaf syntax) :
<img th:src=@{'/app/public/uploads/' + ${picture}} >
What can be wrong guys? Maybe it’s not necessary to mount my volume, or the absolute path is wrong, or both, or wrong / incomplete Dockerfile or fly.toml, or… ?
Using the command: fly ssh console -a get-your-travel-app -C "df -h"
gives this:

Many many thanks!!