I want to run the Nodejs application on Openshift and because I want to use persistent files (like images), I need to store them in a directory OPENSHIFT_DATA_DIR.
I created this action_hooks for the build phase:
#!/bin/bash
#First of all I check if the dir exists. If not I create it
if [ ! -d $OPENSHIFT_DATA_DIR'images' ]
then
echo "Create "$OPENSHIFT_DATA_DIR'images'
mkdir -p $OPENSHIFT_DATA_DIR'images'
fi
#Create symlink
echo "Create link: "$OPENSHIFT_REPO_DIR'images -> '$OPENSHIFT_DATA_DIR'images'
ln -sf $OPENSHIFT_DATA_DIR'images' $OPENSHIFT_REPO_DIR'images'
Symbolic link created, but index.html cannot access downloaded file
This is my (dumb) test page index.html:
<html>
<head>
<title>Test page</title>
</head>
<body>
<div id="image_container"/>
<div id="button_container"/>
<script type="text/javascript">
var loaded = false
var debug = false
var clickAction = function() {
if (debug) {
alert(process.env.OPENSHIFT_DATA_DIR)
}
else {
if (!loaded) {
var container = document.getElementById("image_container")
var image = document.createElement("img")
image.src = "images/montagna.jpg"
image.id = "img001"
container.appendChild(image)
loaded = true
}
else {
var container = document.getElementById("image_container")
var image = document.getElementById("img001")
container.removeChild(image)
loaded = false
}
}
}
window.onload = function() {
var container = document.getElementById("button_container")
var button = document.createElement("input")
button.type = "button"
button.name = "button1"
button.value = "clickme"
button.setAttribute("onclick", "clickAction()")
container.appendChild(button)
};
</script>
</body>
</html>
When I click on the button, I get a 404 error from the server ( this is a link to the application).
Please note that I uploaded the file via SFTP (using Filezilla) inside the ~/app-root/data/imagesapplication directory , and the symlink works because I see the image also from ~/app-root/repo/images.