Skip to content

pkg/generator: add auto-gen for tmp/build.sh#46

Merged
fanminshi merged 1 commit intooperator-framework:masterfrom
fanminshi:gen_build
Feb 22, 2018
Merged

pkg/generator: add auto-gen for tmp/build.sh#46
fanminshi merged 1 commit intooperator-framework:masterfrom
fanminshi:gen_build

Conversation

@fanminshi
Copy link
Copy Markdown
Contributor

@fanminshi fanminshi commented Feb 22, 2018

This generates a build script that compiles this operator project into a binary.
Also, we need to think about how to integrate this build script with operator-sdk build command and along with other potential scripts to make operator-sdk build $IMAGE work.

@fanminshi
Copy link
Copy Markdown
Contributor Author

Manual Test:

func TestGenBuild(t *testing.T) {
	buf := &bytes.Buffer{}
	if err := renderBuildFile(buf, "github.com/coreos/play", "play"); err != nil {
		t.Error(err)
		return
	}
	if err := ioutil.WriteFile("./build.sh", buf.Bytes(), 0744); err != nil {
		t.Error(err)
	}
}

Output:

#!/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)/_output/bin"
mkdir -p ${bin_dir} || true
# set some environment variables
PROJECT_NAME="play"
REPO_PATH="github.com/coreos/play"
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

@fanminshi
Copy link
Copy Markdown
Contributor Author

cc/ @hasbro17 @hongchaodeng

@fanminshi fanminshi mentioned this pull request Feb 22, 2018
21 tasks
Comment thread pkg/generator/build_tmpl.go Outdated
exit 1
fi

BIN_DIR="$(pwd)/_output/bin"
Copy link
Copy Markdown
Contributor

@hongchaodeng hongchaodeng Feb 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put _output/ under tmp/

Comment thread pkg/generator/build_tmpl.go Outdated
fi

BIN_DIR="$(pwd)/_output/bin"
mkdir -p ${bin_dir} || true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bin_dir -> BIN_DIR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@fanminshi
Copy link
Copy Markdown
Contributor Author

Latest Test Output:

#!/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} || true
# set some environment variables
PROJECT_NAME="play"
REPO_PATH="github.com/coreos/play"
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

@fanminshi
Copy link
Copy Markdown
Contributor Author

all fixed PTAL cc/ @hongchaodeng

Comment thread pkg/generator/build_tmpl.go Outdated
fi

BIN_DIR="$(pwd)/tmp/_output/bin"
mkdir -p ${BIN_DIR} || true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need || true. mkdir -p succeeds even if the dir exists.

Comment thread pkg/generator/build_tmpl.go Outdated

BIN_DIR="$(pwd)/tmp/_output/bin"
mkdir -p ${BIN_DIR} || true
# set some environment variables
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set some environment variables

What are the env used for? Please clarify.
Or if they are obvious, just no comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obvious enough. no need to have comment.

Comment thread pkg/generator/gen_build.go Outdated
"text/template"
)

// Main Build all the customized data needed to generate tmp/build.sh
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "Main Build" mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos!

@fanminshi
Copy link
Copy Markdown
Contributor Author

all fixed!

Latest test output:

#!/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="play"
REPO_PATH="github.com/coreos/play"
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

@hongchaodeng
Copy link
Copy Markdown
Contributor

LGTM

@fanminshi fanminshi merged commit 1c0cb43 into operator-framework:master Feb 22, 2018
@hongchaodeng hongchaodeng deleted the gen_build branch February 22, 2018 23:15
m1kola pushed a commit to m1kola/operator-sdk that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants