Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
lib/begin: added support for beginning from remote docker images
Browse files Browse the repository at this point in the history
This commit pulls in docker2aci to add support for commands such as:

    acbuild begin docker://alpine

Beginning from local docker images remains unimplemented, and will be
added in a future commit.
  • Loading branch information
Derek Gonyeo committed Jun 14, 2016
1 parent 90e3bd3 commit 6b522af
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions lib/begin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"runtime"
"strings"

"github.com/appc/acbuild/registry"
"github.com/appc/acbuild/util"

docker2aci "github.com/appc/docker2aci/lib"
"github.com/appc/docker2aci/lib/common"
"github.com/appc/spec/aci"
"github.com/appc/spec/discovery"
"github.com/appc/spec/schema"
Expand Down Expand Up @@ -94,6 +97,11 @@ func (a *ACBuild) Begin(start string, insecure bool) (err error) {
return a.beginFromLocalImage(start)
}
} else {
dockerPrefix := "docker://"
if strings.HasPrefix(start, dockerPrefix) {
start = strings.TrimPrefix(start, dockerPrefix)
return a.beginFromRemoteDockerImage(start, insecure)
}
return a.beginFromRemoteImage(start, insecure)
}
}
Expand Down Expand Up @@ -228,12 +236,6 @@ func (a *ACBuild) writeEmptyManifest() error {
}

func (a *ACBuild) beginFromRemoteImage(start string, insecure bool) error {
// Check if we're starting with a docker image
if strings.HasPrefix(start, "docker://") {
// TODO use docker2aci
return fmt.Errorf("docker containers are currently unsupported")
}

app, err := discovery.NewAppFromString(start)
if err != nil {
return err
Expand Down Expand Up @@ -295,3 +297,50 @@ func (a *ACBuild) beginFromRemoteImage(start string, insecure bool) error {

return util.ExtractImage(path.Join(tmpDepStoreTarPath, files[0].Name()), a.CurrentACIPath, nil)
}

func (a *ACBuild) beginFromRemoteDockerImage(start string, insecure bool) (err error) {
outputDir, err := ioutil.TempDir("", "acbuild")
if err != nil {
return err
}
defer os.RemoveAll(outputDir)

tempDir, err := ioutil.TempDir("", "acbuild")
if err != nil {
return err
}
defer os.RemoveAll(tempDir)

insecureConf := common.InsecureConfig{
SkipVerify: insecure,
AllowHTTP: insecure,
}

config := docker2aci.RemoteConfig{
CommonConfig: docker2aci.CommonConfig{
Squash: true,
OutputDir: outputDir,
TmpDir: tempDir,
Compression: common.GzipCompression,
},
Username: "",
Password: "",
Insecure: insecureConf,
}
renderedACIs, err := docker2aci.ConvertRemoteRepo(start, config)
if err != nil {
return err
}
if len(renderedACIs) > 1 {
return fmt.Errorf("internal error: docker2aci didn't squash the image")
}
if len(renderedACIs) == 0 {
return fmt.Errorf("internal error: docker2aci didn't produce any images")
}
absRenderedACI, err := filepath.Abs(renderedACIs[0])
if err != nil {
return err
}

return util.ExtractImage(absRenderedACI, a.CurrentACIPath, nil)
}

0 comments on commit 6b522af

Please sign in to comment.