Browse Source

Fixes to the build workflow

Moved sample buildfiles into own directories
master
Till Wegmueller 3 years ago
parent
commit
505beb00cc
  1. 11
      host/build.go
  2. 2
      image/meta.go
  3. 24
      image/oci/tar_reader.go
  4. 5
      image/oci/writer.go
  5. 0
      supportfiles/dockerfiles/golang.Dockerfile
  6. 0
      supportfiles/dockerfiles/hipster.Dockerfile
  7. 0
      supportfiles/dockerfiles/multibuild.Dockerfile
  8. 0
      supportfiles/dockerfiles/volume.Dockerfile
  9. 6
      supportfiles/image-build-files/golang.hcl
  10. 0
      supportfiles/image-build-files/hipster.hcl
  11. 0
      supportfiles/image-build-files/multibuild.hcl
  12. 50
      supportfiles/image-build-files/registry.hcl
  13. 0
      supportfiles/image-build-files/volume.hcl

11
host/build.go

@ -36,6 +36,7 @@ func (h *Host) RunBuild(cfg *build.ImageConfig, opts *pod.Options) error {
if cfg.Maintainer != nil {
imgCfg.Maintainer = cfg.Maintainer
}
nameRef := reference.NewReferenceString(imgCfg.Name)
logrus.Tracef("name reference for new image %s", nameRef)
container, err := h.CreateBuildContainer(imgCfg, opts)
@ -323,6 +324,7 @@ func (h *Host) ExportToImage(ref reference.Reference, container *pod.Container,
Cmd: imageConfig.Command,
WorkingDir: imageConfig.WorkingDir,
Labels: imageConfig.Labels,
Volumes: volumeConfigToStringStruct(imageConfig.Volumes),
}
wr.AddImageConfig(specImageConfig)
@ -363,6 +365,15 @@ func (h *Host) ExportToImage(ref reference.Reference, container *pod.Container,
return repo, nil
}
func volumeConfigToStringStruct(v []build.VolumeConfig) map[string]struct{} {
retVal := make(map[string]struct{})
for _, vol := range v {
retVal[vol.Path] = struct{}{}
}
return retVal
}
func toStringStruct(stringSlice []string) map[string]struct{} {
retVal := make(map[string]struct{})
for _, str := range stringSlice {

2
image/meta.go

@ -41,7 +41,7 @@ func (r *Repository) Load() error {
return tracerr.Wrap(err)
}
defer indexFile.Close()
if err := json.NewDecoder(indexFile).Decode(r.Index); err != nil {
if err := json.NewDecoder(indexFile).Decode(&r.Index); err != nil {
return tracerr.Wrap(err)
}

24
image/oci/tar_reader.go

@ -57,7 +57,7 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
if err != nil {
return tracerr.Wrap(err)
}
logrus.Debugf("Changing to directory %s", dir)
logrus.Tracef("Changing to directory %s", dir)
if err = os.Chdir(dir); err != nil {
return tracerr.Wrap(err)
}
@ -72,7 +72,7 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
}
if strings.Contains(th.Name, ".wh.") {
path := filepath.Join(dir, strings.Replace(th.Name, ".wh.", "", -1))
logrus.Debugf("Deleting %s", path)
logrus.Tracef("Deleting %s", path)
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
return tracerr.Wrap(err)
}
@ -81,23 +81,23 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
path := filepath.Join(dir, th.Name)
switch th.Typeflag {
case tar.TypeDir:
logrus.Debugf("Extracting Directory %s", path)
logrus.Tracef("Extracting Directory %s", path)
if err := unpackDir(th, path); err != nil {
return tracerr.Wrap(err)
}
case tar.TypeSymlink:
//Defer symlink creation to later to avoid file not exist errors
logrus.Debugf("Saving Symlink %s for later extraction", path)
logrus.Tracef("Saving Symlink %s for later extraction", path)
symLinkList = append(symLinkList, *th)
case tar.TypeLink:
// Links must be created relative to dir in order to find a file that already exists
// Hardlinks are resolved at link time rather than symlinks which are resolved at runtime
logrus.Debugf("Extracting Hardlink %s", path)
logrus.Tracef("Extracting Hardlink %s", path)
if err := os.Link(filepath.Join(dir, th.Linkname), path); err != nil {
return tracerr.Wrap(err)
}
case tar.TypeReg:
logrus.Debugf("Extracting File %s", path)
logrus.Tracef("Extracting File %s", path)
if err := unpackFile(th, tarReader.archiveReader, path); err != nil {
return tracerr.Wrap(err)
}
@ -112,7 +112,7 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
for _, th := range symLinkList {
path := filepath.Join(dir, th.Name)
dirPath := filepath.Dir(path)
logrus.Debugf("Changing to directory %s", dirPath)
logrus.Tracef("Changing to directory %s", dirPath)
oldPWD, err := os.Getwd()
if err != nil {
return tracerr.Wrap(err)
@ -120,14 +120,14 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
if err = os.Chdir(dirPath); err != nil {
return tracerr.Wrap(err)
}
logrus.Debugf("Extracting Symlink %s", path)
logrus.Tracef("Extracting Symlink %s", path)
if err := os.Symlink(th.Linkname, path); err != nil {
if os.IsExist(err) {
// If the file exists recreate it
// TODO do some unification and rerun functionality anonymous function +defer ???
if err := os.Remove(path); err != nil {
if os.IsNotExist(err) {
logrus.Debugf("Changing to directory %s", oldPWD)
logrus.Tracef("Changing to directory %s", oldPWD)
if err = os.Chdir(oldPWD); err != nil {
return tracerr.Wrap(err)
}
@ -138,7 +138,7 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
if err := os.Symlink(th.Linkname, path); err != nil {
if os.IsExist(err) {
//If we get it a second time then just ignore it...
logrus.Debugf("Changing to directory %s", oldPWD)
logrus.Tracef("Changing to directory %s", oldPWD)
if err = os.Chdir(oldPWD); err != nil {
return tracerr.Wrap(err)
}
@ -150,13 +150,13 @@ func (tarReader *TarReader) ExtractTreeInto(dir string) error {
}
return tracerr.Wrap(err)
}
logrus.Debugf("Changing to directory %s", oldPWD)
logrus.Tracef("Changing to directory %s", oldPWD)
if err = os.Chdir(oldPWD); err != nil {
return tracerr.Wrap(err)
}
}
logrus.Debugf("Changing to directory %s", pwd)
logrus.Tracef("Changing to directory %s", pwd)
if err = os.Chdir(pwd); err != nil {
return tracerr.Wrap(err)
}

5
image/oci/writer.go

@ -113,8 +113,11 @@ func (w *Writer) WriteOCILayoutFile() error {
func (w *Writer) initialize() (err error) {
if w.Exists() {
return w.Load()
if err := w.Load(); err != nil {
return tracerr.Wrap(err)
}
}
if _, err = os.Stat(w.targetDir); os.IsNotExist(err) {
if err = os.Mkdir(w.targetDir, 0755); err != nil {
return err

0
supportfiles/golang.Dockerfile → supportfiles/dockerfiles/golang.Dockerfile

0
supportfiles/hipster.Dockerfile → supportfiles/dockerfiles/hipster.Dockerfile

0
supportfiles/multibuild.Dockerfile → supportfiles/dockerfiles/multibuild.Dockerfile

0
supportfiles/volume.Dockerfile → supportfiles/dockerfiles/volume.Dockerfile

6
supportfiles/golang.hcl → supportfiles/image-build-files/golang.hcl

@ -3,12 +3,12 @@ maintainer = {
email = "toasterson@gmail.com"
}
image "openindiana/golang" {
image "builders/golang" {
base = "openindiana/hipster"
env = {
PATH = "/usr/sbin:/sbin:/usr/bin"
}
}
action "Install Go Runtime" {
cmd = "pkg install -v golang-111"
cmd = "pkg install -v golang-114 system/header developer/build/gnu-make git developer/gcc-8 system/library/gcc-8-runtime jq wget"
}
}

0
supportfiles/hipster.hcl → supportfiles/image-build-files/hipster.hcl

0
supportfiles/multibuild.hcl → supportfiles/image-build-files/multibuild.hcl

50
supportfiles/image-build-files/registry.hcl

@ -0,0 +1,50 @@
maintainer = {
name = "Till Wegmueller"
email = "till.wegmueller@openflowlabs.com"
}
image "builders/registry" {
base = "builders/golang"
env = {
PATH = "/usr/sbin:/sbin:/usr/bin"
}
action "Download Registry From Git" {
cmd = "git clone https://github.com/docker/distribution.git /root/distribution"
}
action "Get Custom main.go file" {
cmd = "wget -O /root/distribution/cmd/registry/main.go https://gist.githubusercontent.com/Toasterson/62b19dd85e4151561081391fa9987f51/raw/1c0e14a7480b0a29f469334b889969af9a48b497/main.go"
}
action "Build the registry binary" {
cmd = "go build -o /dest/registry /root/distribution/cmd/registry/main.go"
}
}
image "aurora-opencloud/registry" {
base = "openindiana/hipster"
env = {
PATH = "/usr/sbin:/sbin:/usr/bin"
}
copy "Copy registry binary from builder image" {
source_image = "builders/registry"
path = "/dest/registry"
target = "/registry"
}
copy "Copy registry config from builder image" {
source_image = "builders/registry"
path = "/root/distribution/cmd/registry/config-example.yml"
target = "/registry_config.yml"
}
volume "/var/lib/registry" {
name = "Registry layer directory"
}
expose = [ "5000" ]
workdir = "/"
cmd = ["/registry", "--config", "/registry_config.yml" ]
}

0
supportfiles/volume.hcl → supportfiles/image-build-files/volume.hcl

Loading…
Cancel
Save