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

Disable CGO #181

Closed
wants to merge 12 commits into from
Closed
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
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ endif
# Safe, since this code isn't performance critical.
export CGO_CFLAGS := -O1

# Disable CGO explicitly
export CGO_ENABLED=0

# build the vitess binaries with dynamic dependency on libc
build-dyn:
ifndef NOBANNER
echo $$(date): Building source tree
endif
bash ./build.env
CGO_ENABLED=0 go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...
go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...

# build the vitess binaries statically
build:
Expand All @@ -63,7 +66,7 @@ ifndef NOBANNER
endif
bash ./build.env
# build all the binaries by default with CGO disabled.
CGO_ENABLED=0 go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...
go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...

# cross-build can be used to cross-compile Vitess client binaries
# Outside of select client binaries (namely vtctlclient & vtexplain), cross-compiled Vitess Binaries are not recommended for production deployments
Expand All @@ -76,7 +79,7 @@ endif
# In order to cross-compile, go install requires GOBIN to be unset
export GOBIN=""
# For the specified GOOS + GOARCH, build all the binaries by default with CGO disabled
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...
GOOS=${GOOS} GOARCH=${GOARCH} go install -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) -ldflags "$(shell tools/build_version_flags.sh)" ./go/...

if [ ! -x "${HOME}/go/bin/${GOOS}_${GOARCH}/vttablet" ]; then \
echo "Missing vttablet at: ${HOME}/go/bin/${GOOS}_${GOARCH}/vttablet" && exit; \
Expand Down
2 changes: 1 addition & 1 deletion docker/base/Dockerfile.percona57
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG bootstrap_version=10.2
ARG bootstrap_version=19
ARG image="vitess/bootstrap:${bootstrap_version}-percona57"

FROM "${image}"
Expand Down
2 changes: 1 addition & 1 deletion docker/base/Dockerfile.percona80
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG bootstrap_version=10.2
ARG bootstrap_version=19
ARG image="vitess/bootstrap:${bootstrap_version}-percona80"

FROM "${image}"
Expand Down
1 change: 1 addition & 0 deletions go/vt/discovery/tablet_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) {
// up = false because we did not get a healthy response
hc.updateHealth(thc.SimpleCopy(), thc.Target, false, false)
}

// If there was a timeout send an error. We do this after stream has returned.
// This will ensure that this update prevails over any previous message that
// stream could have sent.
Expand Down
33 changes: 25 additions & 8 deletions go/vt/grpcclient/client_auth_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"encoding/json"
"flag"
"os"
"sync"
"errors"

"context"

Expand All @@ -31,6 +33,10 @@ var (
credsFile = flag.String("grpc_auth_static_client_creds", "", "when using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server")
// StaticAuthClientCreds implements client interface to be able to WithPerRPCCredentials
_ credentials.PerRPCCredentials = (*StaticAuthClientCreds)(nil)

clientCreds = (*StaticAuthClientCreds)(nil)

once sync.Once
)

// StaticAuthClientCreds holder for client credentials
Expand Down Expand Up @@ -59,15 +65,26 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) {
if *credsFile == "" {
return opts, nil
}
data, err := os.ReadFile(*credsFile)
if err != nil {
return nil, err
}
clientCreds := &StaticAuthClientCreds{}
err = json.Unmarshal(data, clientCreds)
if err != nil {
return nil, err

once.Do(func() {
credsData, err := os.ReadFile(*credsFile)
if err != nil {
// to-do: log the error message
return
}

clientCreds = &StaticAuthClientCreds{}
err = json.Unmarshal(credsData, clientCreds)
if err != nil {
// to-do: log the error message
return
}
})

if clientCreds == nil {
return nil, errors.New("no client creds found")
}

creds := grpc.WithPerRPCCredentials(clientCreds)
opts = append(opts, creds)
return opts, nil
Expand Down
Loading