-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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 |
pkg/generator/build_tmpl.go
Outdated
exit 1 | ||
fi | ||
|
||
BIN_DIR="$(pwd)/_output/bin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put _output/ under tmp/
pkg/generator/build_tmpl.go
Outdated
fi | ||
|
||
BIN_DIR="$(pwd)/_output/bin" | ||
mkdir -p ${bin_dir} || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin_dir -> BIN_DIR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
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 |
all fixed PTAL cc/ @hongchaodeng |
pkg/generator/build_tmpl.go
Outdated
fi | ||
|
||
BIN_DIR="$(pwd)/tmp/_output/bin" | ||
mkdir -p ${BIN_DIR} || true |
There was a problem hiding this comment.
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.
pkg/generator/build_tmpl.go
Outdated
|
||
BIN_DIR="$(pwd)/tmp/_output/bin" | ||
mkdir -p ${BIN_DIR} || true | ||
# set some environment variables |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/generator/gen_build.go
Outdated
"text/template" | ||
) | ||
|
||
// Main Build all the customized data needed to generate tmp/build.sh |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typos!
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 |
LGTM |
Organize Ansible build/release files
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.