-
Notifications
You must be signed in to change notification settings - Fork 62
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
Append -static-libgcc on Linux #215
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Copyright Istio Authors | ||
# Licensed under the Apache License, Version 2.0 (the "License") | ||
|
||
FROM gcr.io/distroless/cc:nonroot | ||
FROM gcr.io/distroless/cc-debian11:nonroot | ||
|
||
COPY ./build_release/auth_server /app/auth_server | ||
USER nonroot:nonroot | ||
# We can't use nonroot:nonroot here since in K8s: | ||
# https://github.com/kubernetes/kubernetes/blob/98eff192802a87c613091223f774a6c789543e74/pkg/kubelet/kuberuntime/security_context_others.go#L49. | ||
USER 65532:65532 | ||
ENTRYPOINT ["/app/auth_server"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,17 @@ | |
|
||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") | ||
|
||
# envoy_stdlib_deps appends "-static-libgcc" on Linux. | ||
load("@envoy//bazel:envoy_internal.bzl", "envoy_stdlib_deps") | ||
|
||
_DEFAULT_COPTS = ["-Wall", "-Wextra"] | ||
|
||
def authsvc_cc_library(name, deps = [], srcs = [], hdrs = [], copts = [], defines = [], includes = [], textual_hdrs = [], visibility = None): | ||
cc_library(name = name, deps = deps, srcs = srcs, hdrs = hdrs, copts = _DEFAULT_COPTS + copts, defines = defines, includes = includes, textual_hdrs = textual_hdrs, visibility = visibility) | ||
|
||
# By default, we always do linkstatic: https://docs.bazel.build/versions/main/be/c-cpp.html#cc_binary.linkstatic. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am bit confused for the comment here. trying to understand. bazel for cc by default always use static link. but for libgcc there might be an option (therefore we see the glibc.so errors before). is that correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, seems like to force linking libgcc statically you need to ask for -static-libgcc. I haven't tried to do |
||
def authsvc_cc_binary(name, deps = [], srcs = [], copts = [], defines = []): | ||
cc_binary(name = name, deps = deps, srcs = srcs, copts = _DEFAULT_COPTS + copts, defines = defines) | ||
cc_binary(name = name, deps = deps + envoy_stdlib_deps(), srcs = srcs, copts = _DEFAULT_COPTS + copts, defines = defines) | ||
|
||
def authsvc_cc_test(name, deps = [], srcs = [], data = []): | ||
cc_test( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# Copied from https://github.com/envoyproxy/envoy/blob/a12869fa9e9add4301a700978d5489e6a0cc0526/test/exe/envoy_static_test.sh. | ||
incfly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if [[ $(uname) == "Darwin" ]]; then | ||
echo "macOS doesn't support statically linked binaries, skipping." | ||
exit 0 | ||
fi | ||
|
||
# We can't rely on the exit code alone, since ldd fails for statically linked binaries. | ||
DYNLIBS=$(ldd "$1" 2>&1) || { | ||
if [[ ! "${DYNLIBS}" =~ 'not a dynamic executable' ]]; then | ||
echo "${DYNLIBS}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
if [[ "${DYNLIBS}" =~ libc\+\+ ]]; then | ||
echo "libc++ is dynamically linked:" | ||
echo "${DYNLIBS}" | ||
exit 1 | ||
elif [[ "${DYNLIBS}" =~ libstdc\+\+ || "${DYNLIBS}" =~ libgcc ]]; then | ||
echo "libstdc++ and/or libgcc are dynamically linked:" | ||
echo "${DYNLIBS}" | ||
exit 1 | ||
fi |
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.
@incfly to make it work, we need your help to add this PAT to the secrets of this repo (make sure that PAT is allowed to push stuff to the registry). Thanks!
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.
cool. I created this secret using my personal access token for now,
GH_REGISTRY_TOKEN_INCFLY
. I name it this way to make it clear the relationship.tried with following and works.
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.
oops. I forgot Approving the PR makes the PR merge automatically. let me send a fix to update the variable name used here.