Note The version of crane described below is a modified one. Find it on my github fork.
If you’re custom to working with github that you’ll recognize the following flow:- You fork a repo (e.g.
user/foo) - You commit and push code to your fork (e.g.
bivas/foo) - You create a pull request (PR) to merge your changes with original repo.
upstream remote and branching model is taken from git flow.
The docker flow problem
When working with docker, you pull and push images to a registry. Usually, when using your own registry, your push, pull, tag, build cycle might get messy.- You pull
company/foofromregistry.company.co - The pulled imaged is now locally tagged as
registry.company.co/company/foo - You write a
Dockerfileto build a dependent image:
a. Start withFROM company/foo?
b. Start withFROM registry.company.co/company/foo? - So you decide to
tagthe pulled image ascompany/fooRemember: You can’t useARGinFROMdirective, so your registry prefix is there for good (or until refactored) - Completed your local tests and you wish to
push. Again, yourtagyour image andpushit asregistry.company.co/company/foo
The crane flow
So we have our registry at registry.company.co, our images are prefixed as company and all our Dockerfiles begin with something like company/foo. We extended crane to support our flow of pull (from official registry), build (locally on developer workspace, and push (to a user registry for backup). The entire flow keeps the original image name as company/foo but knows when to change tags to support other flows. Here’s an example
crane.yaml file:containers:
os:
image: company/os
build:
context: os/
pull:
registry: ${DOCKER_REGISTRY}
etcd:
image: coreos/etcd:2
push:
skip: true
service:
image: company/service
build:
context: service/
pull:
registry: registry.company.co
push:
registry: registry.${USER}.company.co
override_user: ${USER}
The added directives:pull.registry= which registry topullfrom
cranewillpullfromregistry.company.co/company/fooand locally tag it ascompany/foo
pull.override_user= which user topullas
cranewillpullthe specified image as${USER}/fooand locally tag it ascompany/foo(useful when testing against your version of the container stack.
push.registry= which registry topushto
cranewillpushtoregistry.company.co/company/foothe image locally tagged ascompany/foo
push.override_user= which user topushas
cranewillpushthe specified image as${USER}/foothe image locally tagged ascompany/foo(useful to backup your images in registry)
push.skip= skip the image when attemptingpush(useful when dealing with community images)
FROM company/foo directive without dealing with re-tag. She can also modify company/foo and keep a backups without the need to re-tag the entire images stack. We have a github-like development cycle of “forking” (
pull) the official registry, pushing images to your private registry for development and backup (push). Once the developer is satisfied with the modifications - she creates a normal pull request to the modified Dockerfile.
No comments:
Post a Comment