зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1290531 - Move image tag resolution to Python; r=dustin
We already had code for resolving the image registry and tag. We refactored it slightly to be more useful then changed build.sh to accept the tag as an argument. At this point, build.sh is basically a wrapper around `docker`. But there's a special case for executing custom "build.sh" files we need to eliminate first... MozReview-Commit-ID: A9HVvxgCdG2 --HG-- extra : rebase_source : 30a408860aea619813f32723fe960d1224b5dbc7
This commit is contained in:
Родитель
efd6c78ba9
Коммит
1ec6c0a5b5
|
@ -77,6 +77,8 @@ def build_image(name):
|
|||
if not os.path.isdir(image_dir):
|
||||
raise Exception('image directory does not exist: %s' % image_dir)
|
||||
|
||||
tag = docker.docker_image(name, default_version='latest')
|
||||
|
||||
docker_bin = which.which('docker')
|
||||
|
||||
# Verify that Docker is working.
|
||||
|
@ -86,7 +88,15 @@ def build_image(name):
|
|||
raise Exception('Docker server is unresponsive. Run `docker ps` and '
|
||||
'check that Docker is running')
|
||||
|
||||
args = [os.path.join(IMAGE_DIR, 'build.sh'), name]
|
||||
args = [os.path.join(IMAGE_DIR, 'build.sh'), name, tag]
|
||||
res = subprocess.call(args, cwd=IMAGE_DIR)
|
||||
if res:
|
||||
raise Exception('error building image')
|
||||
|
||||
if tag.endswith(':latest'):
|
||||
print('*' * 50)
|
||||
print('WARNING: no VERSION file found in image directory.')
|
||||
print('Image is not suitable for deploying/pushing.')
|
||||
print('Create an image suitable for deploying/pushing by creating')
|
||||
print('a VERSION file in the image directory.')
|
||||
print('*' * 50)
|
||||
|
|
|
@ -18,7 +18,7 @@ DOCKER_ROOT = os.path.join(GECKO, 'testing', 'docker')
|
|||
ARTIFACT_URL = 'https://queue.taskcluster.net/v1/task/{}/artifacts/{}'
|
||||
|
||||
|
||||
def docker_image(name):
|
||||
def docker_image(name, default_version=None):
|
||||
'''Determine the docker image name, including repository and tag, from an
|
||||
in-tree docker file.'''
|
||||
try:
|
||||
|
@ -28,8 +28,14 @@ def docker_image(name):
|
|||
with open(os.path.join(DOCKER_ROOT, 'REGISTRY')) as f:
|
||||
registry = f.read().strip()
|
||||
|
||||
with open(os.path.join(DOCKER_ROOT, name, 'VERSION')) as f:
|
||||
version = f.read().strip()
|
||||
try:
|
||||
with open(os.path.join(DOCKER_ROOT, name, 'VERSION')) as f:
|
||||
version = f.read().strip()
|
||||
except IOError:
|
||||
if not default_version:
|
||||
raise
|
||||
|
||||
version = default_version
|
||||
|
||||
return '{}/{}:{}'.format(registry, name, version)
|
||||
|
||||
|
|
|
@ -6,51 +6,10 @@
|
|||
|
||||
gecko_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
|
||||
|
||||
usage() {
|
||||
echo "Build a docker image (and tag it)"
|
||||
echo
|
||||
echo "$0 <image-name>"
|
||||
echo
|
||||
echo " Images are defined in testing/docker/<image-name>."
|
||||
echo " For more see: $PWD/README.md"
|
||||
echo
|
||||
}
|
||||
|
||||
usage_err() {
|
||||
echo $1
|
||||
echo
|
||||
usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
build() {
|
||||
local image_name=$1
|
||||
local tag=$2
|
||||
local folder="$gecko_root/testing/docker/$image_name"
|
||||
local folder_reg="$folder/REGISTRY"
|
||||
local folder_ver="$folder/VERSION"
|
||||
local could_deploy=false
|
||||
|
||||
# Assume that if an image context directory does not contain a VERSION file then
|
||||
# it is not suitable for deploying. Default to using 'latest' as the tag and
|
||||
# warn the user at the end.
|
||||
if [ ! -f $folder_ver ]; then
|
||||
echo "This image does not contain a VERSION file. Will use 'latest' as the image version"
|
||||
local tag="$image_name:latest"
|
||||
else
|
||||
local version=$(cat $folder_ver)
|
||||
test -n "$version" || usage_err "$folder_ver is empty aborting..."
|
||||
|
||||
# Fallback to default registry if one is not in the folder...
|
||||
if [ ! -f "$folder_reg" ]; then
|
||||
folder_reg=$PWD/REGISTRY
|
||||
fi
|
||||
|
||||
local registry=$(cat $folder_reg)
|
||||
test -n "$registry" || usage_err "$folder_reg is empty aborting..."
|
||||
|
||||
local tag="$registry/$image_name:$version"
|
||||
local could_deploy=true
|
||||
fi
|
||||
|
||||
if [ -f $folder/build.sh ]; then
|
||||
shift
|
||||
|
@ -62,18 +21,6 @@ build() {
|
|||
fi
|
||||
|
||||
echo "Success built $image_name and tagged with $tag"
|
||||
if [ "$could_deploy" = true ]; then
|
||||
echo "If deploying now you can run 'docker push $tag'"
|
||||
else
|
||||
echo "*****************************************************************"
|
||||
echo "WARNING: No VERSION file was found in the image directory."
|
||||
echo "Image has not been prepared for deploying at this time."
|
||||
echo "However, the image can be run locally. To prepare to "
|
||||
echo "push to a user account on a docker registry, tag the image "
|
||||
echo "by running 'docker tag $tag [REGISTRYHOST/][USERNAME/]NAME[:TAG]"
|
||||
echo "prior to running 'docker push'."
|
||||
echo "*****************************************************************"
|
||||
fi
|
||||
}
|
||||
|
||||
build $*
|
||||
|
|
Загрузка…
Ссылка в новой задаче