mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-22 20:20:39 +00:00
Merge pull request #169 from colinhoglund/fix_registry_string_trimming
Fix ECR registry string trimming
This commit is contained in:
commit
aa9e40e076
@ -8,6 +8,8 @@ pipeline:
|
|||||||
commands:
|
commands:
|
||||||
- go get -u github.com/golang/dep/cmd/dep
|
- go get -u github.com/golang/dep/cmd/dep
|
||||||
- dep ensure
|
- dep ensure
|
||||||
|
- go vet ./...
|
||||||
|
- go test -cover ./...
|
||||||
- sh .drone.sh
|
- sh .drone.sh
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
|
@ -55,9 +55,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if create {
|
if create {
|
||||||
err = ensureRepoExists(svc, strings.TrimPrefix(repo, registry))
|
err = ensureRepoExists(svc, trimHostname(repo, registry))
|
||||||
if err != nil {
|
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) {
|
func ensureRepoExists(svc *ecr.ECR, name string) (err error) {
|
||||||
input := &ecr.CreateRepositoryInput{}
|
input := &ecr.CreateRepositoryInput{}
|
||||||
input.SetRepositoryName(name)
|
input.SetRepositoryName(name)
|
||||||
|
20
cmd/drone-docker-ecr/main_test.go
Normal file
20
cmd/drone-docker-ecr/main_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user