Remove protocol from custom registry for setting in the name and checking in the name

This commit is contained in:
Lars Gohr
2019-10-10 22:02:23 +02:00
parent 1133a364e4
commit cade1bc239
2 changed files with 20 additions and 3 deletions

View File

@@ -8,8 +8,9 @@ function main() {
sanitize "${INPUT_USERNAME}" "username" sanitize "${INPUT_USERNAME}" "username"
sanitize "${INPUT_PASSWORD}" "password" sanitize "${INPUT_PASSWORD}" "password"
if uses "${INPUT_REGISTRY}" && ! isPartOfTheName; then REGISTRY_NO_PROTOCOL=$(echo "${INPUT_REGISTRY}" | sed -e 's/^https:\/\///g')
INPUT_NAME="${INPUT_REGISTRY}/${INPUT_NAME}" if uses "${INPUT_REGISTRY}" && ! isPartOfTheName "${REGISTRY_NO_PROTOCOL}"; then
INPUT_NAME="${REGISTRY_NO_PROTOCOL}/${INPUT_NAME}"
fi fi
translateDockerTag translateDockerTag
@@ -51,7 +52,7 @@ function sanitize() {
} }
function isPartOfTheName() { function isPartOfTheName() {
[ $(echo "${INPUT_NAME}" | sed -e "s/${INPUT_REGISTRY}//g") != "${INPUT_NAME}" ] [ $(echo "${INPUT_NAME}" | sed -e "s/${1}//g") != "${INPUT_NAME}" ]
} }
function translateDockerTag() { function translateDockerTag() {

View File

@@ -227,6 +227,22 @@ Called /usr/local/bin/docker logout"
[ "$output" = "$expected" ] [ "$output" = "$expected" ]
} }
@test "it pushes to another registry and removes the protocol from the reference" {
export INPUT_REGISTRY='https://my.Registry.io'
export INPUT_NAME='my/repository'
run /entrypoint.sh
local expected="
Called /usr/local/bin/docker login -u USERNAME --password-stdin https://my.Registry.io
Called /usr/local/bin/docker build -t my.Registry.io/my/repository:latest .
Called /usr/local/bin/docker push my.Registry.io/my/repository:latest
::set-output name=tag::latest
Called /usr/local/bin/docker logout"
echo $output
[ "$output" = "$expected" ]
}
@test "it caches the image from a former build" { @test "it caches the image from a former build" {
export INPUT_CACHE='true' export INPUT_CACHE='true'