Beispiel #1
0
// NewDockerPopulator returns a function that will populate the docker tar archive
func (b *BaseImageBuilder) NewDockerPopulator() func(*tar.Writer) error {
	return func(tarWriter *tar.Writer) error {
		// Generate dockerfile
		dockerfileContents, err := b.generateDockerfile()
		if err != nil {
			return err
		}
		err = util.WriteToTarStream(tarWriter, dockerfileContents, tar.Header{
			Name: "Dockerfile",
		})
		if err != nil {
			return err
		}

		// Add rsyslog_conf, monitrc.erb, and the post-start handler.
		for _, assetName := range dockerfiles.AssetNames() {
			switch {
			case strings.HasPrefix(assetName, "rsyslog_conf/"):
			case assetName == "monitrc.erb":
			case assetName == "post-start.sh":
			default:
				continue
			}
			assetContents, err := dockerfiles.Asset(assetName)
			if err != nil {
				return err
			}
			err = util.WriteToTarStream(tarWriter, assetContents, tar.Header{
				Name: assetName,
			})
			if err != nil {
				return err
			}
		}

		// Add configgin
		configginGzip, err := configgin.Asset("configgin.tgz")
		if err != nil {
			return err
		}
		err = util.TargzIterate(
			"configgin.tgz",
			bytes.NewReader(configginGzip),
			func(reader *tar.Reader, header *tar.Header) error {
				header.Name = filepath.Join("configgin", header.Name)
				if err = tarWriter.WriteHeader(header); err != nil {
					return err
				}
				if _, err = io.Copy(tarWriter, reader); err != nil {
					return err
				}
				return nil
			})
		if err != nil {
			return err
		}

		return nil
	}
}
Beispiel #2
0
// generateDockerfile builds a docker file for a given role.
func (r *RoleImageBuilder) generateDockerfile(role *model.Role, baseImageName string, outputFile io.Writer) error {
	asset, err := dockerfiles.Asset("Dockerfile-role")
	if err != nil {
		return err
	}

	dockerfileTemplate := template.New("Dockerfile-role")

	context := map[string]interface{}{
		"base_image":    baseImageName,
		"image_version": r.version,
		"role":          role,
		"licenses":      role.Jobs[0].Release.License.Files,
	}

	dockerfileTemplate, err = dockerfileTemplate.Parse(string(asset))
	if err != nil {
		return err
	}

	if err := dockerfileTemplate.Execute(outputFile, context); err != nil {
		return err
	}

	return nil
}
Beispiel #3
0
func (r *RoleImageBuilder) generateRunScript(role *model.Role) ([]byte, error) {
	asset, err := dockerfiles.Asset("run.sh")
	if err != nil {
		return nil, err
	}

	runScriptTemplate := template.New("role-runscript")
	runScriptTemplate.Funcs(template.FuncMap{
		"is_abs":       filepath.IsAbs,
		"is_pre_start": isPreStart,
	})
	context := map[string]interface{}{
		"role": role,
	}
	runScriptTemplate, err = runScriptTemplate.Parse(string(asset))
	if err != nil {
		return nil, err
	}

	var output bytes.Buffer
	err = runScriptTemplate.Execute(&output, context)
	if err != nil {
		return nil, err
	}

	return output.Bytes(), nil
}
Beispiel #4
0
func (b *BaseImageBuilder) generateDockerfile() ([]byte, error) {
	asset, err := dockerfiles.Asset("Dockerfile-base")
	if err != nil {
		return nil, err
	}

	dockerfileTemplate := template.New("Dockerfile-base")
	dockerfileTemplate, err = dockerfileTemplate.Parse(string(asset))
	if err != nil {
		return nil, err
	}

	var output bytes.Buffer
	err = dockerfileTemplate.Execute(&output, b)
	if err != nil {
		return nil, err
	}

	return output.Bytes(), nil
}
Beispiel #5
0
// generateDockerfile builds a docker file for the shared packages layer.
func (p *PackagesImageBuilder) generateDockerfile(baseImage string, packages model.Packages, outputFile io.Writer) error {
	context := map[string]interface{}{
		"base_image": baseImage,
		"packages":   packages,
	}
	asset, err := dockerfiles.Asset("Dockerfile-packages")
	if err != nil {
		return err
	}

	dockerfileTemplate := template.New("Dockerfile")
	dockerfileTemplate, err = dockerfileTemplate.Parse(string(asset))
	if err != nil {
		return err
	}

	if err := dockerfileTemplate.Execute(outputFile, context); err != nil {
		return err
	}

	return nil
}