Skip to content

Commit

Permalink
Merge pull request #106 from silinternational/develop
Browse files Browse the repository at this point in the history
Support multi-level images
  • Loading branch information
fillup authored May 18, 2017
2 parents 7045a05 + 0ab06b2 commit ac2b53c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ecs-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function assertRequiredArgumentsSet() {
fi

if [ $SERVICE == false ] && [ $TASK_DEFINITION == false ]; then
echo "One of SERVICE or TASK DEFINITON is required. You can pass the value using -n / --service-name for a service, or -d / --task-definiton for a task"
echo "One of SERVICE or TASK DEFINITON is required. You can pass the value using -n / --service-name for a service, or -d / --task-definition for a task"
exit 5
fi
if [ $SERVICE != false ] && [ $TASK_DEFINITION != false ]; then
Expand Down Expand Up @@ -141,7 +141,7 @@ function parseImageName() {
# - tag
# If a group is missing it will be an empty string
if [[ "x$TAGONLY" == "x" ]]; then
imageRegex="^([a-zA-Z0-9.\-]+):?([0-9]+)?/([a-zA-Z0-9._-]+)/?([a-zA-Z0-9._-]+)?:?([a-zA-Z0-9\._-]+)?$"
imageRegex="^([a-zA-Z0-9\.\-]+):?([0-9]+)?/([a-zA-Z0-9\._\-]+)(/[\/a-zA-Z0-9\._\-]+)?:?([a-zA-Z0-9\._\-]+)?$"
else
imageRegex="^:?([a-zA-Z0-9\._-]+)?$"
fi
Expand All @@ -152,7 +152,7 @@ function parseImageName() {
domain=${BASH_REMATCH[1]}
port=${BASH_REMATCH[2]}
repo=${BASH_REMATCH[3]}
img=${BASH_REMATCH[4]}
img=${BASH_REMATCH[4]/#\//}
tag=${BASH_REMATCH[5]}

# Validate what we received to make sure we have the pieces needed
Expand All @@ -173,7 +173,6 @@ function parseImageName() {
else
tag=${BASH_REMATCH[1]}
fi

else
# check if using root level repo with format like mariadb or mariadb:latest
rootRepoRegex="^([a-zA-Z0-9\-]+):?([a-zA-Z0-9\.\-]+)?$"
Expand Down
65 changes: 65 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ setup() {
[ "$output" == "repo/image:v1.2.3" ]
}

@test "test parseImageName repo multilevel image no tag" {
IMAGE="repo/multi/level/image"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "repo/multi/level/image:latest" ]
}

@test "test parseImageName repo multilevel image with tag" {
IMAGE="repo/multi/level/image:v1.2.3"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "repo/multi/level/image:v1.2.3" ]
}

@test "test parseImageName domain plus repo image no tag" {
IMAGE="docker.domain.com/repo/image"
TAGVAR=false
Expand All @@ -125,6 +141,22 @@ setup() {
[ "$output" == "docker.domain.com/repo/image:1.2.3" ]
}

@test "test parseImageName domain plus repo multilevel image no tag" {
IMAGE="docker.domain.com/repo/multi/level/image"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "docker.domain.com/repo/multi/level/image:latest" ]
}

@test "test parseImageName domain plus repo multilevel image with tag" {
IMAGE="docker.domain.com/repo/multi/level/image:1.2.3"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "docker.domain.com/repo/multi/level/image:1.2.3" ]
}

@test "test parseImageName domain plus port plus repo image no tag" {
IMAGE="docker.domain.com:8080/repo/image"
TAGVAR=false
Expand All @@ -141,6 +173,22 @@ setup() {
[ "$output" == "docker.domain.com:8080/repo/image:1.2.3" ]
}

@test "test parseImageName domain plus port plus repo multilevel image no tag" {
IMAGE="docker.domain.com:8080/repo/multi/level/image"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "docker.domain.com:8080/repo/multi/level/image:latest" ]
}

@test "test parseImageName domain plus port plus repo multilevel image with tag" {
IMAGE="docker.domain.com:8080/repo/multi/level/image:1.2.3"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "docker.domain.com:8080/repo/multi/level/image:1.2.3" ]
}

@test "test parseImageName domain plus port plus repo image with tag from var" {
IMAGE="docker.domain.com:8080/repo/image"
TAGVAR="CI_TIMESTAMP"
Expand All @@ -150,6 +198,23 @@ setup() {
[ "$output" == "docker.domain.com:8080/repo/image:1487623908" ]
}

@test "test parseImageName domain plus port plus repo multilevel image with tag from var" {
IMAGE="docker.domain.com:8080/repo/multi/level/image"
TAGVAR="CI_TIMESTAMP"
CI_TIMESTAMP="1487623908"
run parseImageName
[ ! -z $status ]
[ "$output" == "docker.domain.com:8080/repo/multi/level/image:1487623908" ]
}

@test "test parseImageName using ecr style domain" {
IMAGE="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo"
TAGVAR=false
run parseImageName
[ ! -z $status ]
[ "$output" == "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:latest" ]
}

@test "test parseImageName using ecr style image name and tag from var" {
IMAGE="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo"
TAGVAR="CI_TIMESTAMP"
Expand Down

0 comments on commit ac2b53c

Please sign in to comment.