-
Notifications
You must be signed in to change notification settings - Fork 10
fix: #453 remove profile image #873
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
base: master
Are you sure you want to change the base?
Conversation
LOG.info( | ||
"Image ID for profile '{}' changed: {} -> {}", | ||
profileName, | ||
previousImageId, | ||
currentImageId); |
Check notice
Code scanning / SonarCloud
Logging should not be vulnerable to injection attacks
currentImageId); | ||
removeImageIfUnused(previousImageId); | ||
} else { | ||
LOG.info("Image ID for profile '{}' unchanged: {}", profileName, currentImageId); |
Check notice
Code scanning / SonarCloud
Logging should not be vulnerable to injection attacks
…t private so it can be tested
|
|
||
String previousImageId = profileConfig.getLastImageId(); | ||
String currentImageId = dockerClient.inspectContainerCmd(containerName).exec().getImageId(); | ||
|
||
profileService.updateLastImageId(profileName, currentImageId); | ||
|
||
String safeProfileName = StringEscapeUtils.escapeJava(profileName); | ||
String safePrevImageId = StringEscapeUtils.escapeJava(previousImageId); | ||
String safeCurrImageId = StringEscapeUtils.escapeJava(currentImageId); | ||
|
||
if (previousImageId != null && !previousImageId.equals(currentImageId)) { | ||
LOG.info( | ||
"Image ID for profile '{}' changed from '{}' to '{}'", | ||
safeProfileName, | ||
safePrevImageId, | ||
safeCurrImageId); | ||
removeImageIfUnused(previousImageId); | ||
} else { | ||
LOG.info( | ||
"Image ID for profile '{}' unchanged (still '{}')", safeProfileName, safeCurrImageId); | ||
} |
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.
I'd move this to a separate function
Hey! I've done a simple functional test to start with (not the extensive tests you described, I had some trouble login in to dockerhub via terminal).
|
Closes #453
What's changed:
Implementation
It turned out to be quite tricky to reliably get the docker imageID based on the tags, so instead I've added a new slot to the
ProfileConfig
class which stores this information the first time the profile is started. It is then updated every time the profile is restarted in case it has changed, and this value is then used to delete the image from disk.How to test:
docker login
Run the following:
Edit file eg with
Now add this script, which will can be used to create a very minimal docker image for testing (note you need to change 'timmyjc' to your docker usename)
Save and exit
Now create a new image using:
Check imageID, and remove local image so it is easier to test
Test that deleting the profile still works if the image has never been pulled
docker images | grep [yourusername]
- the image shouldn't show because the profile has been startedINFO o.m.armadillo.profile.DockerService - No image ID provided; skipping image removal
Test that the image will be deleted when the profile has been pulled and profile is running
docker images | grep [yourusername]
- you should now see the image listedo.m.armadillo.profile.DockerService - Removed image tag '[yourusername]/mytest:latest'
o.m.armadillo.profile.DockerService - Removed image ID 'sha256:xxx' from local Docker cache
docker images | grep [yourusername]
- check there are no images still storedTest that the image will be deleted when the profile has been pulled and profile is stopped
docker images | grep [yourusername]
- you should now see the image listedo.m.armadillo.profile.DockerService - Removed image tag '[yourusername]/mytest:latest'
o.m.armadillo.profile.DockerService - Removed image ID 'sha256:xxx
from local Docker cache`Test that the image will be deleted when the profile is updated with a new image
docker images | grep [yourusername]
INFO o.m.armadillo.profile.DockerService - Image ID for profile 'test' changed from 'sha256:xxx' to 'sha256:xxx'
INFO o.m.armadillo.profile.DockerService - Removed image ID 'sha256:xxx`docker images | grep [yourusername]
- you should still see 'latest', but check that the imageID has changed from before and after the restart