Skip to content
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

Use docker push to push image #85

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 67 additions & 73 deletions create_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
# exit when any command fails
set -e

echo "::group::Validate Information"

# Validate That Required Inputs Were Supplied
function check_env() {
if [ -z $(eval echo "\$$1") ]; then
echo "Variable $1 not found. Exiting..."
exit 1
fi
}
echo "::group::Validate Information"

if [ "$INPUT_APPENDIX_FILE" ]; then
APPENDIX=`cat $INPUT_APPENDIX_FILE`
Expand Down Expand Up @@ -43,7 +35,7 @@ if [ "$INPUT_DOCKER_REGISTRY" ]; then
fi

# Set username
if [ -z "$INPUT_NOTEBOOK_USER" ] || [ "$INPUT_MYBINDERORG_TAG" ] || [ "$INPUT_BINDER_CACHE" ];
if [ -z "$INPUT_NOTEBOOK_USER" ] || [ "$INPUT_MYBINDERORG_TAG" ] || [ "$INPUT_BINDER_CACHE" ];
then
NB_USER="jovyan"

Expand Down Expand Up @@ -73,7 +65,6 @@ echo "::group::Show Variables"
echo "INPUT_ADDITIONAL_TAG: ${INPUT_ADDITIONAL_TAG}"
echo "INPUT_APPENDIX_FILE: ${INPUT_APPENDIX_FILE}"
echo "INPUT_BINDER_CACHE: ${INPUT_BINDER_CACHE}"
echo "INPUT_BINDER_CACHE: ${INPUT_BINDER_CACHE}"
echo "INPUT_IMAGE_NAME: ${INPUT_IMAGE_NAME}"
echo "INPUT_IMAGE_NAME: ${INPUT_IMAGE_NAME}"
echo "INPUT_MYBINDERORG_TAG: ${INPUT_MYBINDERORG_TAG}"
Expand All @@ -89,74 +80,45 @@ echo "::endgroup::"

echo "::set-output name=IMAGE_SHA_NAME::${SHA_NAME}"

if [ -z "$INPUT_NO_PUSH" ]; then
echo "::group::Build and Push ${SHA_NAME}"


# If BINDER_CACHE flag is specified, validate user intent by checking for the presence of .binder and binder directories.
if [ "$INPUT_BINDER_CACHE" ]; then
GENERIC_MSG="This Action assumes you are not explicitly using Binder to build your dependencies."

# Exit if .binder directory is present
if [ -d ".binder" ]; then
echo "Found directory .binder ${GENERIC_MSG} The presence of a directory named .binder indicates otherwise. Aborting this step.";
exit 1;
fi

# Delete binder directory if it exists and only contains Dockerfile, so repo2docker can do a fresh build.
if [ -d "binder" ]; then
# if /binder has files other than Dockerfile, exit with status code 1, else remove the binder folder.
num_files=`ls binder | grep -v 'Dockerfile' | wc -l`
if [[ "$num" -gt 0 ]];
then
echo "Files other than Dockerfile are present in your binder/ directory. ${GENERIC_MSG} This directory is used by this Action to point to an existing Docker image that Binder can pull.";
exit 1;
else
rm -rf binder
fi
fi
fi

jupyter-repo2docker --push --no-run --user-id 1000 --user-name ${NB_USER} --target-repo-dir ${REPO_DIR} --image-name ${SHA_NAME} --cache-from ${INPUT_IMAGE_NAME} --appendix "$APPENDIX" ${PWD}
echo "::group::Build ${SHA_NAME}"

if [ -z "$INPUT_LATEST_TAG_OFF" ]; then
docker tag ${SHA_NAME} ${INPUT_IMAGE_NAME}:latest
docker push ${INPUT_IMAGE_NAME}:latest
fi
if [ "$INPUT_ADDITIONAL_TAG" ]; then
docker tag ${SHA_NAME} ${INPUT_IMAGE_NAME}:$INPUT_ADDITIONAL_TAG
docker push ${INPUT_IMAGE_NAME}:$INPUT_ADDITIONAL_TAG
fi

echo "::endgroup::"
# If BINDER_CACHE flag is specified, validate user intent by checking for the presence of .binder and binder directories.
if [ "$INPUT_BINDER_CACHE" ]; then
GENERIC_MSG="This Action assumes you are not explicitly using Binder to build your dependencies."

echo "::set-output name=IMAGE_SHA_NAME::${SHA_NAME}"
echo "::set-output name=PUSH_STATUS::true"
# Exit if .binder directory is present
if [ -d ".binder" ]; then
echo "Found directory .binder ${GENERIC_MSG} The presence of a directory named .binder indicates otherwise. Aborting this step.";
exit 1;
fi

if [ "$INPUT_PUBLIC_REGISTRY_CHECK" ]; then
echo "::group::Verify That Image Is Public"
docker logout
if docker pull $SHA_NAME; then
echo "Verified that $SHA_NAME is publicly visible."
else
echo "Could not pull docker image: $SHA_NAME. Make sure this image is public before proceeding."
exit 1
# Delete binder directory if it exists and only contains Dockerfile, so repo2docker can do a fresh build.
if [ -d "binder" ]; then
# if /binder has files other than Dockerfile, exit with status code 1, else remove the binder folder.
num_files=`ls binder | grep -v 'Dockerfile' | wc -l`
if [[ "$num" -gt 0 ]];
then
echo "Files other than Dockerfile are present in your binder/ directory. ${GENERIC_MSG} This directory is used by this Action to point to an existing Docker image that Binder can pull.";
exit 1;
else
rm -rf binder
fi
echo "::endgroup::"
fi
fi

else
echo "::group::Build Image Without Pushing"
jupyter-repo2docker --no-run --user-id 1000 --user-name ${NB_USER} --target-repo-dir ${REPO_DIR} --image-name ${SHA_NAME} --cache-from ${INPUT_IMAGE_NAME} --appendix "${APPENDIX}" ${PWD}
if [ -z "$INPUT_LATEST_TAG_OFF" ]; then
docker tag ${SHA_NAME} ${INPUT_IMAGE_NAME}:latest
fi
if [ "$INPUT_ADDITIONAL_TAG" ]; then
docker tag ${SHA_NAME} ${INPUT_IMAGE_NAME}:$INPUT_ADDITIONAL_TAG
fi
echo "::endgroup::"
echo "::set-output name=PUSH_STATUS::false"/
# Just build the image, do not push it
jupyter-repo2docker --no-run --user-id 1000 --user-name ${NB_USER} \
--target-repo-dir ${REPO_DIR} --image-name ${SHA_NAME} --cache-from ${INPUT_IMAGE_NAME} \
--appendix "$APPENDIX" ${PWD}

if [ -z "$INPUT_LATEST_TAG_OFF" ]; then
docker tag ${SHA_NAME} ${INPUT_IMAGE_NAME}:latest
fi
if [ "$INPUT_ADDITIONAL_TAG" ]; then
docker tag ${SHA_NAME} ${INPUT_IMAGE_NAME}:$INPUT_ADDITIONAL_TAG
fi
echo "::endgroup::"

# If a directory named image-tests exists, run tests on the built image
if [ -d "${PWD}/image-tests" ]; then
Expand Down Expand Up @@ -190,8 +152,40 @@ if [ -d "${PWD}/image-tests" ]; then
echo "::endgroup::"
fi

if [ -z "$INPUT_NO_PUSH" ]; then
echo "::group::Pushing ${SHA_NAME}"

docker push ${SHA_NAME}

if [ -z "$INPUT_LATEST_TAG_OFF" ]; then
docker push ${INPUT_IMAGE_NAME}:latest
fi
if [ "$INPUT_ADDITIONAL_TAG" ]; then
docker push ${INPUT_IMAGE_NAME}:$INPUT_ADDITIONAL_TAG
fi

echo "::endgroup::"

echo "::set-output name=PUSH_STATUS::true"

if [ "$INPUT_PUBLIC_REGISTRY_CHECK" ]; then
echo "::group::Verify That Image Is Public"
docker logout
if docker pull $SHA_NAME; then
echo "Verified that $SHA_NAME is publicly visible."
else
echo "Could not pull docker image: $SHA_NAME. Make sure this image is public before proceeding."
exit 1
fi
echo "::endgroup::"
fi

else
echo "::set-output name=PUSH_STATUS::false"
fi

if [ "$INPUT_BINDER_CACHE" ]; then
echo "::group::Commit Local Dockerfile For Binder Cache"
echo "::group::Commit Local Dockerfile For Binder Cache"
python /binder_cache.py "$SHA_NAME"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
Expand All @@ -209,7 +203,7 @@ fi


if [ "$INPUT_MYBINDERORG_TAG" ]; then
echo "::group::Triggering Image Build on mybinder.org"
echo "::group::Triggering Image Build on mybinder.org"
/trigger_binder.sh "https://gke.mybinder.org/build/gh/$GITHUB_REPOSITORY/$INPUT_MYBINDERORG_TAG"
echo "::endgroup::"
fi