Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:alpine as builder

RUN apk update \
&& apk add git curl \
&& apk add ca-certificates

RUN adduser --uid 10000 -D -g '' user

COPY . $GOPATH/src/github.com/tomaszkiewicz/docker-copy-docker-image
WORKDIR $GOPATH/src/github.com/tomaszkiewicz/docker-copy-docker-image

RUN go get -u github.com/kardianos/govendor \
&& export GO_VERSION=$(go version | cut -d' ' -f3 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') \
&& govendor sync

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /main

FROM alpine

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd

COPY --from=builder /main /main

USER user
ENTRYPOINT ["/main"]
20 changes: 16 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"io/ioutil"
"os"
"strings"
"regexp"
)

func moveLayerUsingFile(srcHub *registry.Registry, destHub *registry.Registry, srcRepo string, destRepo string, layer schema1.FSLayer, file *os.File) error {
Expand Down Expand Up @@ -119,10 +120,15 @@ func connectToRegistry(args RepositoryArguments) (*registry.Registry, error) {
username := ""
password := ""

if strings.HasPrefix(url, "ecr:") {
registryId := strings.TrimPrefix(url, "ecr:")
r, _ := regexp.Compile(`(?P<account_id>[0-9]{12})\.dkr\.ecr\.(?P<region>[\w\d-]+)\.amazonaws\.com`)
r2 := r.FindAllStringSubmatch(url, -1)

if r2 != nil {
registryId := r2[0][1]
region := r2[0][2]

sess, err := session.NewSession(&aws.Config{Region: aws.String(region)})

sess, err := session.NewSession()
if err != nil {
return nil, fmt.Errorf("Failed to create new AWS SDK session. %v", err)
}
Expand Down Expand Up @@ -231,7 +237,13 @@ func main() {
}
}

err = destHub.PutManifest(*destArgs.Repository, *destArgs.Tag, manifest)
destManifest := &schema1.SignedManifest{
Manifest: manifest.Manifest,
}

destManifest.Manifest.Name = *destArgs.Repository

err = destHub.PutManifest(*destArgs.Repository, *destArgs.Tag, destManifest)
if err != nil {
fmt.Printf("Failed to upload manifest to %s/%s:%s. %v", destHub.URL, *destArgs.Repository, *destArgs.Tag, err)
exitCode = -1
Expand Down