Created
December 5, 2014 11:38
-
-
Save ainoya/5a525ba8f639f4494811 to your computer and use it in GitHub Desktop.
lock while building image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build Docker image and run it as a container. | |
def up | |
begin | |
lock = File.open('/var/lock/subsys/pool.lock', 'w') | |
if lock.flock(File::LOCK_EX | File::LOCK_NB ) | |
image_id = build | |
container_id = run image_id | |
confirm_running container_id | |
else | |
@logger.info("Locked! Other environment is under building process") | |
@logger.info("Please access after finishing another building process...") | |
end | |
rescue => ex | |
@logger.error ex | |
raise | |
ensure | |
@logger.close | |
lock.flock(File::LOCK_UN) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment