Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 22, 2018
Merged

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

merged 1 commit into from
Feb 22, 2018

Conversation

fanminshi
Copy link
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
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
Contributor Author

cc/ @hasbro17 @hongchaodeng

@fanminshi fanminshi mentioned this pull request Feb 22, 2018
21 tasks
exit 1
fi

BIN_DIR="$(pwd)/_output/bin"
Copy link
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/

fi

BIN_DIR="$(pwd)/_output/bin"
mkdir -p ${bin_dir} || true
Copy link
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
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
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
Contributor Author

all fixed PTAL cc/ @hongchaodeng

fi

BIN_DIR="$(pwd)/tmp/_output/bin"
mkdir -p ${BIN_DIR} || true
Copy link
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.


BIN_DIR="$(pwd)/tmp/_output/bin"
mkdir -p ${BIN_DIR} || true
# set some environment variables
Copy link
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
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.

"text/template"
)

// Main Build all the customized data needed to generate tmp/build.sh
Copy link
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
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
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
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.

None yet

2 participants