-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update dockers with platform & SONiC version as part of name/tag. #4337
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
Merged
renukamanavalan
merged 5 commits into
sonic-net:master
from
renukamanavalan:push_docker
Apr 10, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
413ae4b
Include platform info in name.
renukamanavalan 4f45677
Per review comments, make SONIC_VERSION optional and added some comme…
renukamanavalan 11adb1b
1) Added additional params are optional
renukamanavalan 9d4d57a
Update per review comments
renukamanavalan 3c6eace
Drop redundant quotes
renukamanavalan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,79 @@ | ||
| #! /bin/bash | ||
|
|
||
| sonic_version="" | ||
| sonic_platform="" | ||
|
|
||
| while getopts ":v:p:" opt | ||
| do | ||
| case ${opt} in | ||
| v ) # SONiC image version | ||
| sonic_version=${OPTARG} | ||
| ;; | ||
| p ) # Platform info | ||
| sonic_platform=${OPTARG} | ||
| ;; | ||
| \? ) echo "\ | ||
| Usage: [-v <version> ] [ -p <platform> ] <DOCKER_IMAGE_FILE> <REGISTRY_SERVER> <REGISTRY_PORT> \ | ||
| <REGISTRY_USERNAME> <REGISTRY_PASSWD> [<DOCKER_IMAGE_TAG>]" | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| shift $((OPTIND -1)) | ||
|
|
||
| DOCKER_IMAGE_FILE=$1 | ||
| REGISTRY_SERVER=$2 | ||
| REGISTRY_PORT=$3 | ||
| REGISTRY_USERNAME=$4 | ||
| REGISTRY_PASSWD=$5 | ||
| DOCKER_IMAGE_TAG=$6 | ||
| REGISTRY_SERVER_WITH_PORT=${REGISTRY_SERVER}${REGISTRY_PORT:+:$REGISTRY_PORT} | ||
|
|
||
| set -e | ||
| docker load < $DOCKER_IMAGE_FILE | ||
| push_it() { | ||
renukamanavalan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # $1 - Given image name | ||
| # $2 - Remote image name | ||
|
|
||
| ## Fetch the Jenkins build number if inside it | ||
| [ ${BUILD_NUMBER} ] || { | ||
renukamanavalan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "No BUILD_NUMBER found, setting to 0." | ||
| BUILD_NUMBER="0" | ||
| docker tag $1 $2 | ||
| echo "Pushing $2" | ||
| image_sha=$(docker push $2 | sed -n "s/.*: digest: sha256:\([0-9a-f]*\).*/\\1/p") | ||
| echo "Remove $2" | ||
| docker rmi $2 || true | ||
| echo "Image sha256: $image_sha" | ||
| } | ||
|
|
||
| ## Prepare tag | ||
| docker_image_name=$(basename $DOCKER_IMAGE_FILE | cut -d. -f1) | ||
| remote_image_name=$REGISTRY_SERVER:$REGISTRY_PORT/$docker_image_name:$DOCKER_IMAGE_TAG | ||
| timestamp="$(date -u +%Y%m%d)" | ||
| build_version="${timestamp}.bld-${BUILD_NUMBER}" | ||
| build_remote_image_name=$REGISTRY_SERVER:$REGISTRY_PORT/$docker_image_name:$build_version | ||
| set -e | ||
|
|
||
| ## Add registry information as tag, so will push as latest | ||
| ## Add additional tag with build information | ||
| docker tag $docker_image_name $remote_image_name | ||
| docker tag $docker_image_name $build_remote_image_name | ||
| echo "Loading image ${DOCKER_IMAGE_FILE}" | ||
| docker load < ${DOCKER_IMAGE_FILE} | ||
|
|
||
| ## Login the docker image registry server | ||
| ## Note: user name and password are passed from command line | ||
| docker login -u $REGISTRY_USERNAME -p "$REGISTRY_PASSWD" $REGISTRY_SERVER:$REGISTRY_PORT | ||
|
|
||
| ## Push image to registry server | ||
| ## And get the image digest SHA256 | ||
| echo "Pushing $remote_image_name" | ||
| image_sha=$(docker push $remote_image_name | sed -n "s/.*: digest: sha256:\([0-9a-f]*\).*/\\1/p") | ||
| docker rmi $remote_image_name || true | ||
| echo "Image sha256: $image_sha" | ||
| echo "Pushing $build_remote_image_name" | ||
| docker push $build_remote_image_name | ||
| docker rmi $build_remote_image_name || true | ||
| docker login -u ${REGISTRY_USERNAME} -p "${REGISTRY_PASSWD}" ${REGISTRY_SERVER_WITH_PORT} | ||
|
|
||
| ## Get Docker image name | ||
| docker_image_name=$(basename ${DOCKER_IMAGE_FILE} | cut -d. -f1) | ||
| remote_image_name=${REGISTRY_SERVER_WITH_PORT}/${docker_image_name} | ||
|
|
||
| [ -z "${DOCKER_IMAGE_TAG}" ] || { | ||
| push_it ${docker_image_name} ${remote_image_name}:${DOCKER_IMAGE_TAG} | ||
| } | ||
|
|
||
| if [ -n "${sonic_version}" ] && [ -n "${sonic_platform}" ] | ||
| then | ||
| remote_image_name=${REGISTRY_SERVER_WITH_PORT}/sonic-dockers/${sonic_platform}/${docker_image_name}:${sonic_version} | ||
| push_it ${docker_image_name} ${remote_image_name} | ||
| else | ||
| ## Fetch the Jenkins build number if inside it | ||
| [ ${BUILD_NUMBER} ] || { | ||
| echo "No BUILD_NUMBER found, setting to 0." | ||
| BUILD_NUMBER="0" | ||
| } | ||
|
|
||
| timestamp="$(date -u +%Y%m%d)" | ||
| build_version="${timestamp}.bld-${BUILD_NUMBER}" | ||
| push_it ${docker_image_name} ${remote_image_name}:${build_version} | ||
| fi | ||
|
|
||
| docker rmi $docker_image_name || true | ||
| echo "Job completed" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.