0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-26 05:30:39 +00:00

Merge pull request #169 from colinhoglund/fix_registry_string_trimming

Fix ECR registry string trimming
This commit is contained in:
Brad Rydzewski 2018-02-21 12:29:47 -08:00 committed by GitHub
commit aa9e40e076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -8,6 +8,8 @@ pipeline:
commands:
- go get -u github.com/golang/dep/cmd/dep
- dep ensure
- go vet ./...
- go test -cover ./...
- sh .drone.sh
publish:

View File

@ -55,9 +55,9 @@ func main() {
}
if create {
err = ensureRepoExists(svc, strings.TrimPrefix(repo, registry))
err = ensureRepoExists(svc, trimHostname(repo, registry))
if err != nil {
os.Exit(1)
log.Fatal(fmt.Sprintf("error creating ECR repo: %v", err))
}
}
@ -75,6 +75,12 @@ func main() {
}
}
func trimHostname(repo, registry string) string {
repo = strings.TrimPrefix(repo, registry)
repo = strings.TrimLeft(repo, "/")
return repo
}
func ensureRepoExists(svc *ecr.ECR, name string) (err error) {
input := &ecr.CreateRepositoryInput{}
input.SetRepositoryName(name)

View File

@ -0,0 +1,20 @@
package main
import "testing"
func TestTrimHostname(t *testing.T) {
registry := "000000000000.dkr.ecr.us-east-1.amazonaws.com"
// map full repo path to expected repo name
repos := map[string]string{
registry + "/repo": "repo",
registry + "/namespace/repo": "namespace/repo",
registry + "/namespace/namespace/repo": "namespace/namespace/repo",
}
for repo, name := range repos {
splitName := trimHostname(repo, registry)
if splitName != name {
t.Errorf("%s is not equal to %s.", splitName, name)
}
}
}