Skip to content

Commit

Permalink
begin: when provided file doesn't look like an ACI, it's a rootfs tar…
Browse files Browse the repository at this point in the history
…ball

This commit modifies begin such that after a local file has been given
to acbuild and it's been extracted, acbuild will check for the existence
of a manifest and a rootfs. If either is missing, it's assumed that the
tarball acbuild just extracted is the rootfs for the container, and it
will move the files into the rootfs directory and create an empty
manifest.
  • Loading branch information
Derek Gonyeo authored and Derek Gonyeo committed Mar 21, 2016
1 parent e3c6add commit aa4da67
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
16 changes: 10 additions & 6 deletions Documentation/subcommands/begin.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ must start with `.`, `~`, or `/`. As an example, if the ACI is in the current
directory, then instead of passing in `alpine-latest-linux-amd64.aci`, what
would be passed in is `./alpine-latest-linux-amd64.aci`.

## Starting with a pre-existing rootfs
## Starting with a local, pre-existing rootfs

If the user has a rootfs they wish to use in the ACI, perhaps produced by a
tool like [buildroot](http://buildroot.org/), a directory can be passed to
begin. The contents of the directory will be copied into the ACI, and the ACI
will have a manifest identical to when the begin command is not passed a
directory.
A build can be started with a rootfs of a container. This rootfs could perhaps
be produced by a tool like [buildroot](http://buildroot.org/), or downloaded
from somewhere like the [Ubuntu Core
releases](http://cdimage.ubuntu.com/ubuntu-core/releases/14.04/release/).

The rootfs can either be in a local directory, or a local tar file. In either
case, the rootfs is copied into the container and an empty manifest is created
that is identical to beginning with an empty ACI.

When specifying something on the local filesystem to the begin command, the
path to it _must_ start with `.`, `~`, or `/`. As an example, if the directory
Expand All @@ -74,4 +77,5 @@ acbuild begin ./my-app.aci
acbuild begin quay.io/coreos/alpine-sh
acbuild --work-path /tmp/mybuild begin
acbuild begin ~/projects/buildroot/output/target
acbuild begin ./ubuntu-core-14.04-core-amd64.tar.gz
```
40 changes: 39 additions & 1 deletion lib/begin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,45 @@ func (a *ACBuild) beginFromLocalImage(start string) error {
if finfo.IsDir() {
return fmt.Errorf("provided starting ACI is a directory: %s", start)
}
return util.ExtractImage(start, a.CurrentACIPath, nil)
err = util.ExtractImage(start, a.CurrentACIPath, nil)
if err != nil {
return err
}

for _, file := range []struct {
FileName string
FilePath string
}{
{"manifest file", path.Join(a.CurrentACIPath, aci.ManifestFile)},
{"rootfs directory", path.Join(a.CurrentACIPath, aci.RootfsDir)},
} {
_, err = os.Stat(file.FilePath)
switch {
case os.IsNotExist(err):
fmt.Fprintf(os.Stderr, "%s is missing, assuming build is beginning with a tar of a rootfs\n", file.FileName)
return a.startedFromTar()
case err != nil:
return err
}
}
return nil
}

func (a *ACBuild) startedFromTar() error {
tmpPath := path.Join(a.ContextPath, "rootfs")
err := os.Rename(a.CurrentACIPath, tmpPath)
if err != nil {
return err
}
err = a.beginWithEmptyACI()
if err != nil {
return err
}
err = os.Remove(path.Join(a.CurrentACIPath, aci.RootfsDir))
if err != nil {
return err
}
return os.Rename(tmpPath, path.Join(a.CurrentACIPath, aci.RootfsDir))
}

func (a *ACBuild) beginFromLocalDirectory(start string) error {
Expand Down

0 comments on commit aa4da67

Please sign in to comment.