New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the failed to mv error on python s2i #10
Conversation
This breaks watch :( |
Hey @anmolbabu can you please rebase to master? Tests had broken before.. See #11 |
Working approach for source deployments :
This way, the sources from $ODO_S2I_SRC_BIN_PATH are backed up before being moved to $APP_ROOT from which the sources will be deleted to void error in redhat-developer/odo#1054 before the same being movede over from $ODO_S2I_SRC_BIN_PATH(which empties it for the next iteration of watch) ToDo: Verification of the method being fool proof for every runtime and different combinations of watch and push triggered for binary and local source |
It looks like the tests are working as intended (I see that it failed in two sections..) Make sure you look at @kadel 's PR too as he restores from backup so it may conflict with regards to your PR. |
571d98b
to
330e924
Compare
4f49cc6
to
643371e
Compare
d317677
to
c6cd563
Compare
@cdrage Ack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works!
assemble-and-restart
Outdated
fi | ||
done | ||
# In case of java clear off the target directory | ||
rm -fr ${ODO_S2I_SRC_BIN_PATH}/src/target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because java s2i does not delete the previous compilation output. If this weren't added, then deleted source files would not be reflected in the compilation output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is java specific, I would like to avoid working with paths that are just for valid just for one type of builder images for now. We need a better way to handle that.
What if my project source that is in a different language contains src/target
path for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, if we don't delete this directory, watch + delete is totally broken for Java.
Perhaps we should wrap the delete call in an if statement that checks if the image is a Java image (by testing for the existence of the mvn binary)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anmolbabu I don't think that using "$ODO_S2I_BUILDER_IMG" == "redhat-openjdk-18/openjdk18-openshift"
is correct, because the image builder could have a different name, right?
I personally think that testing for the image capabilities (meaning testing if it has the mvn
binary) is the correct approach.
An alternative could be perhaps to check for the existence of pom.xml
in the pushed source code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other Java builder we use at the moment is the widlfly one and I haven't checked to see if it uses mvn clean
.
My issue is basically with the name - are you sure the builder image name that is injected as an env var will always be the same no matter how I name it in my cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is the name of docker image(not the name it is imported as for ex: I have imported it as openjdk18 like in tests) corresponding to s2i image...
So it is likely not to change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I'm fine with the change as long as we check and see if widlfly needs the same kind of handling :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is exactly the issue that this fixes? I have tried a few Java examples and with this commented out and haven't any issues. Except hitting redhat-developer/odo#1117 again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kadel To see the problem this fixes you need to do the following:
Use the updated source example from this PR.
odo create ...
odo push
odo watch
Then delete one of the Java classes. Once the watch picks up the delete, the build should fail (since of the required sources no longer exists).
If you remove this line, then the build does not fail because it retains the previous compiled file
assemble-and-restart
Outdated
fi | ||
done | ||
# In case of java clear off the target directory | ||
rm -fr ${ODO_S2I_SRC_BIN_PATH}/src/target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is java specific, I would like to avoid working with paths that are just for valid just for one type of builder images for now. We need a better way to handle that.
What if my project source that is in a different language contains src/target
path for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @anmolbabu if you can organize the code a bit that'd be great. Add some newlines between code that's different! 👍
assemble-and-restart
Outdated
@@ -2,6 +2,34 @@ | |||
set -x | |||
set -eo pipefail | |||
|
|||
# If WorkingDir is injected as an env from odo and destination path is not equal to WorkingDir injected by odo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is confusing..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack I will fix it
assemble-and-restart
Outdated
if [ ! -d ${ODO_SRC_BACKUP_DIR} ]; then | ||
mkdir -p ${ODO_SRC_BACKUP_DIR}/src | ||
fi | ||
# Backup the sources in DestinationDir to ODO_SRC_BACKUP_DIR bcoz the assemble script for some s2i images |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bcoz = because
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
rm -fr $ODO_S2I_WORKING_DIR/$file | ||
fi | ||
done | ||
# In case of java clear off the target directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is oddly specific... is there any way to make this more generic or do we actually have to hard-code in openjdk support?
This will be a future problem when newer versions of openjdk is released in the future of if the image name changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearing off the output directory should not cause any problems, even if the builder image does this on it's own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: #10 (comment)
@jorgemoralespou I would say not in the scope of this PR |
IFS=$b_IFS | ||
|
||
# In case of java clear off the target directory | ||
if [ -n "$ODO_S2I_BUILDER_IMG" ] && [ "$ODO_S2I_BUILDER_IMG" == "redhat-openjdk-18/openjdk18-openshift" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anmolbabu please add TODO
comment so we don't forget that this is a temporary hack and we need to find a proper solution for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
This PR is already a significant change (because it is tight to redhat-developer/odo#1125) Let's fix this right after we are done with this.
We need to fix it, this was not an issue before we started doing all this backup and restore charades. |
@jorgemoralespou I just compiled odo with redhat-developer/odo#1125 that uses image from this PR to make it easy to test this anywhere. You can download it here odo.zip ( It is compiled just for MacOS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some light testing, this LGTM 👍 code + comments + implementation.
good enough, don't block on me, but we need another review
@kadel All comments incoporated please review |
I don't feel qualified to review this PR, sorry. |
The error happens when the local component source contains a directory by name s2i. This fix clears the $APP_ROOT of all files and folders before the assemble script copies over sources from $destination dir to $app-root so that mv from assemble script does not compile that the folder already exists fixes redhat-developer/odo#1054 Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
run
Outdated
if [ -d /opt/app-root/backup ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then | ||
cp -rf /opt/app-root/backup/. ${ODO_S2I_DEPLOYMENT_DIR}/ | ||
if [ -d ${ODO_DEPLOYMENT_BACKUP_DIR} ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then | ||
cp -rf ${ODO_DEPLOYMENT_BACKUP_DIR}/. ${ODO_S2I_DEPLOYMENT_DIR}/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why everywhere in assemble-and-restart this has changed to rsync, but here it has remained as cp? same performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
Tests are failing because the new image is not compatible with current odo. (It requires redhat-developer/odo#1125 to work properly) |
run
Outdated
if [ -d /opt/app-root/backup ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then | ||
cp -rf /opt/app-root/backup/. ${ODO_S2I_DEPLOYMENT_DIR}/ | ||
if [ -d ${ODO_DEPLOYMENT_BACKUP_DIR} ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then | ||
rsync -r ${ODO_DEPLOYMENT_BACKUP_DIR}/. ${ODO_S2I_DEPLOYMENT_DIR}/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to use rsync -a
to make sure that it is really identical copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
assemble-and-restart
Outdated
fi | ||
cp -rf ${ODO_S2I_DEPLOYMENT_DIR}/. /opt/app-root/backup/ | ||
|
||
rsync -r ${ODO_S2I_DEPLOYMENT_DIR}/. ${ODO_DEPLOYMENT_BACKUP_DIR}/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to use rsync -a
to make sure that it is really identical copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
assemble-and-restart
Outdated
# After assemble script is run(which delets sources from destination dir by doing mv of them to the WorkingDir) and if only its component created from source, | ||
# copy back the sources from Source backup dir to DestinationDir for subsequent push of only updates by watch | ||
if [ ! -z "${ODO_S2I_WORKING_DIR}" ] && [ -n "$ODO_SRC_BACKUP_DIR" ] && ([ "${ODO_S2I_SRC_BIN_PATH}" != "${ODO_S2I_WORKING_DIR}" ] || [ "${ODO_S2I_DEPLOYMENT_DIR}" != "${ODO_S2I_WORKING_DIR}" ]); then | ||
rsync -r ${ODO_SRC_BACKUP_DIR}/src/. ${ODO_S2I_SRC_BIN_PATH}/src/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to use rsync -a
to make sure that it is really identical copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
assemble-and-restart
Outdated
# Backup the sources in DestinationDir to ODO_SRC_BACKUP_DIR because the assemble script for some s2i images | ||
# moves sources from DestinationDir to WorkingDir thereby deleting it there(DestinationDir). So, back it up | ||
# for partial push use cases like watch | ||
rsync -r ${ODO_S2I_SRC_BIN_PATH}/src/. ${ODO_SRC_BACKUP_DIR}/src/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to use rsync -a
to make sure that it is really identical copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
The error happens when the local component source contains
a directory by name s2i. This fix clears the $APP_ROOT of
all files and folders before the assemble script copies
over sources from $destination dir to $app-root so that
mv from assemble script does not compile that the folder
already exists
fixes redhat-developer/odo#1054
Signed-off-by: anmolbabu anmolbudugutta@gmail.com