Skip to content

Instantly share code, notes, and snippets.

@zeroc0d3
Last active February 13, 2024 13:43
Show Gist options
  • Save zeroc0d3/b44ad078cd8f4fee0787b0a04b733b5e to your computer and use it in GitHub Desktop.
Save zeroc0d3/b44ad078cd8f4fee0787b0a04b733b5e to your computer and use it in GitHub Desktop.
Push CI/CD Container Image to Dockerhub Registry
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# Docker Push Container (DockerHub)
# -----------------------------------------------------------------------------
# Author : Dwi Fahni Denni
# License : Apache v2
# -----------------------------------------------------------------------------
set -e
# export CI_PROJECT_PATH="devopscorner"
# export CI_PROJECT_NAME="cicd"
# export IMAGE="$CI_PROJECT_PATH/$CI_PROJECT_NAME"
export IMAGE=$1
login_docker() {
echo '==================='
echo ' Login DockerHub '
echo '==================='
echo ${DOCKERHUB_PASSWORD} | docker login --username ${DOCKERHUB_USERNAME} --password-stdin
echo '- DONE -'
echo ''
}
docker_push() {
export TAGS_ID=$2
IMAGES=`docker images --format "{{.Repository}}:{{.Tag}}" | grep $IMAGE:${TAGS_ID}`
for IMG in $IMAGES; do
echo "Docker Push => $IMG"
echo ">> docker push $IMG"
docker push $IMG
echo '- DONE -'
echo ''
done
}
main() {
login_docker
# docker_push devopscorner/cicd [alpine|ubuntu|codebuild|version|latest|tags|custom-tags]
docker_push $1 $2
echo ''
echo '-- ALL DONE --'
}
### START HERE ###
main $1 $2
### How to Execute ###
# ./dockerhub-push.sh [DOCKERHUB_IMAGE_PATH] [alpine|ubuntu|codebuild|version|latest|tags|custom-tags]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment