diff --git a/.gitignore b/.gitignore index 79bd19b..5ae1cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ gitignore* +lib/secrets.sh diff --git a/Jenkinsfile b/Jenkinsfile index c73e51d..9518e0c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,8 +20,16 @@ pipeline { stage('Build/Run') { agent { label "linux && ${ARCH}" } steps { - sh "./scripts/docker_build_image.sh ${DISTRO}" - sh "./scripts/docker_run_image.sh ${DISTRO}" + withCredentials([string( + credentialsId: 'DOCKER_REGISTRY', + variable: 'DOCKER_REGISTRY'), + usernamePassword(credentialsId: 'DOCKER_REGISTRY_CRED', + passwordVariable: 'DOCKER_REGISTRY_PASS', + usernameVariable: 'DOCKER_REGISTRY_USER' + )]) { + sh "./scripts/docker_build_image.sh ${DISTRO}" + sh "./scripts/docker_run_image.sh ${DISTRO}" + } } } } diff --git a/lib/docker.sh b/lib/docker.sh index 1fc6f64..88c7d4a 100644 --- a/lib/docker.sh +++ b/lib/docker.sh @@ -88,6 +88,17 @@ docker_build_image() { -t "${image_tag}" \ -f "${dockerfile}" \ . || return 1 + + # if a docker registry is defined, push to it + if [[ "${DOCKER_REGISTRY}" != '' ]]; then + docker tag "${image_tag}" "${DOCKER_REGISTRY}/${image_tag}" + docker login \ + -u "${DOCKER_REGISTRY_USER}" \ + -p "${DOCKER_REGISTRY_PASS}" \ + "${DOCKER_REGISTRY}" + docker push "${DOCKER_REGISTRY}/${image_tag}" + fi + docker system prune -f done } @@ -130,6 +141,17 @@ FB_FUNC_COMPLETION['docker_run_image']="${VALID_DOCKER_IMAGES[*]}" docker_run_image() { validate_selected_image "$@" || return 1 check_docker || return 1 + + # if a docker registry is defined, pull from it + if [[ "${DOCKER_REGISTRY}" != '' ]]; then + docker login \ + -u "${DOCKER_REGISTRY_USER}" \ + -p "${DOCKER_REGISTRY_PASS}" \ + "${DOCKER_REGISTRY}" + docker pull "${DOCKER_REGISTRY}/${image_tag}" + docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}" + fi + for distro in "${DISTROS[@]}"; do image_tag="$(set_distro_image_tag "${distro}")" echo_info "running ffmpeg build for ${image_tag}"