Skip to content
Merged
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
21 changes: 21 additions & 0 deletions pkg/generator/build_tmpl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package generator

const buildTmpl = `#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

if ! which go > /dev/null; then
echo "golang needs to be installed"
exit 1
fi

BIN_DIR="$(pwd)/tmp/_output/bin"
mkdir -p ${BIN_DIR}
PROJECT_NAME="{{.ProjectName}}"
REPO_PATH="{{.RepoPath}}"
BUILD_PATH="${REPO_PATH}/cmd/${PROJECT_NAME}"
echo "building "${PROJECT_NAME}"..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ${BIN_DIR}/${PROJECT_NAME} $BUILD_PATH
`
29 changes: 29 additions & 0 deletions pkg/generator/gen_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package generator

import (
"io"
"text/template"
)

// Build contains all the customized data needed to generate tmp/build.sh
// for a new operator when pairing with buildTmpl template.
type Build struct {
RepoPath string
ProjectName string
}

// renderBuildFile generates the tmp/build.sh file given a repo path ("github.com/coreos/app-operator")
// and projectName ("app-operator").
func renderBuildFile(w io.Writer, repo, projectName string) error {
t := template.New("tmp/build.sh")
t, err := t.Parse(buildTmpl)
if err != nil {
return err
}

m := Build{
RepoPath: repo,
ProjectName: projectName,
}
return t.Execute(w, m)
}