Skip to content

Commit 3cc2cc1

Browse files
authored
Move test demo apps out of Bazel to ease Go version deprecation and support testing offsetgen instrumentation (#2217)
1 parent 7ab7ee2 commit 3cc2cc1

File tree

10 files changed

+250
-29
lines changed

10 files changed

+250
-29
lines changed

src/stirling/testing/demo_apps/go_grpc_tls_pl/server/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ go_library(
3232
importpath = "px.dev/pixie/src/stirling/testing/demo_apps/go_grpc_tls_pl/server",
3333
deps = [
3434
"//src/stirling/testing/demo_apps/go_grpc_tls_pl/server/greetpb:service_pl_go_proto",
35-
"@com_github_sirupsen_logrus//:logrus",
36-
"@com_github_spf13_pflag//:pflag",
37-
"@com_github_spf13_viper//:viper",
3835
"@org_golang_google_grpc//:grpc",
3936
"@org_golang_x_net//http2",
4037
"@org_golang_x_net//http2/h2c",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2018- The Pixie Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
ARG GO_IMAGE_DIGEST
18+
FROM alpine:3.20@sha256:de4fe7064d8f98419ea6b49190df1abbf43450c1702eeb864fe9ced453c1cc5f AS certs
19+
20+
RUN apk add --no-cache openssl
21+
22+
WORKDIR /tmp/certs
23+
24+
# Generate CA key and cert
25+
RUN openssl ecparam -genkey -name secp384r1 -out ca.key && \
26+
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 \
27+
-subj "/C=US/ST=California/L=San Francisco/O=Pixie Labs Inc./CN=Pixie CA" \
28+
-out ca.crt
29+
30+
# Generate server key
31+
RUN openssl ecparam -genkey -name secp384r1 -out server.key
32+
33+
# Generate server CSR
34+
RUN openssl req -new -key server.key \
35+
-subj "/C=US/ST=California/L=San Francisco/O=Pixie Labs Inc./CN=127.0.0.1" \
36+
-out server.csr
37+
38+
# Create server cert config with SAN and extensions
39+
RUN echo "subjectAltName=IP:127.0.0.1" > server.ext && \
40+
echo "basicConstraints=CA:FALSE" >> server.ext && \
41+
echo "keyUsage = digitalSignature, keyEncipherment" >> server.ext && \
42+
echo "extendedKeyUsage = serverAuth" >> server.ext
43+
44+
# Sign server CSR with CA
45+
RUN openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
46+
-out server.crt -days 365 -sha256 -extfile server.ext
47+
48+
FROM golang:${GO_IMAGE_DIGEST} as build
49+
50+
ARG GOOGLE_GOLANG_GRPC
51+
52+
WORKDIR /app
53+
54+
# Copy source and build
55+
COPY server.go .
56+
COPY greetpb greetpb
57+
RUN go mod init px.dev/pixie/src/stirling/testing/demo_apps/go_grpc_tls_pl/server && \
58+
go get google.golang.org/grpc@${GOOGLE_GOLANG_GRPC} && \
59+
go get github.com/gogo/protobuf/proto && \
60+
go mod tidy
61+
RUN CGO_ENABLED=0 go build -o server .
62+
63+
FROM scratch
64+
COPY --from=certs /tmp/certs/ca.crt /etc/ssl/ca.crt
65+
COPY --from=certs /tmp/certs/server.crt /etc/ssl/server.crt
66+
COPY --from=certs /tmp/certs/server.key /etc/ssl/server.key
67+
COPY --from=build /app/server /app/server
68+
69+
ENTRYPOINT ["/app/server"]
70+
CMD ["--server_tls_cert", "/etc/ssl/server.crt", "--server_tls_key", "/etc/ssl/server.key", "--tls_ca_cert", "/etc/ssl/ca.crt"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Go GRPC and HTTP2 server for testing HTTP2/GRPC traicing
2+
3+
This directory contains a Go grpc and http2 server for testing Pixie's Go http2 and grpc tracing. This application is built through bazel and by the `update_ghcr.sh` script contained in this directory. The reason for this is that as Go versions fall out of support, maintaining these in our bazel build hinders our ability to upgrade our go deps and to upgrade Pixie's Go version.
4+
5+
In addition to this, Pixie's upcoming opentelemetry-go-instrumentation offsetgen based tracing requires building binaries with Go's toolchain until https://github.com/bazel-contrib/rules_go/issues/3090 is resolved.
6+
7+
As new Go versions are released, the out of support versions should be removed from bazel and added to the `update_ghcr.sh` script in this directory. This will allow our builds to maintain test coverage for older Go versions without complicating our ability to upgrade Pixie's Go version and dependencies.
8+
9+
Run `update_ghcr.sh` in this directory to push the images for each Go version to the ghcr.io repo.

src/stirling/testing/demo_apps/go_grpc_tls_pl/server/server.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ import (
2222
"context"
2323
"crypto/tls"
2424
"crypto/x509"
25+
"flag"
26+
"log"
2527
"net"
2628
"net/http"
2729
"os"
2830
"os/signal"
2931
"syscall"
3032
"time"
3133

32-
log "github.com/sirupsen/logrus"
33-
"github.com/spf13/pflag"
34-
"github.com/spf13/viper"
3534
"golang.org/x/net/http2"
3635
"golang.org/x/net/http2/h2c"
3736
"google.golang.org/grpc"
@@ -52,21 +51,20 @@ func (s *Server) SayHello(ctx context.Context, in *greetpb.HelloRequest) (*greet
5251
}
5352

5453
func main() {
55-
pflag.String("server_tls_cert", "", "Path to server.crt")
56-
pflag.String("server_tls_key", "", "Path to server.key")
57-
pflag.String("tls_ca_cert", "", "Path to ca.crt")
58-
pflag.Parse()
59-
viper.BindPFlags(pflag.CommandLine)
54+
serverCert := flag.String("server_tls_cert", "", "Path to server.crt")
55+
serverKey := flag.String("server_tls_key", "", "Path to server.key")
56+
caCert := flag.String("tls_ca_cert", "", "Path to ca.crt")
57+
flag.Parse()
6058

61-
pair, err := tls.LoadX509KeyPair(viper.GetString("server_tls_cert"), viper.GetString("server_tls_key"))
59+
pair, err := tls.LoadX509KeyPair(*serverCert, *serverKey)
6260
if err != nil {
63-
log.WithError(err).Fatal("failed to load keys")
61+
log.Fatalf("failed to load keys: %v", err)
6462
}
6563

6664
certPool := x509.NewCertPool()
67-
ca, err := os.ReadFile(viper.GetString("tls_ca_cert"))
65+
ca, err := os.ReadFile(*caCert)
6866
if err != nil {
69-
log.WithError(err).Fatal("failed to read CA cert")
67+
log.Fatalf("failed to read CA cert: %v", err)
7068
}
7169

7270
if ok := certPool.AppendCertsFromPEM(ca); !ok {
@@ -114,6 +112,6 @@ func main() {
114112
defer cancel()
115113
err = httpServer.Shutdown(ctx)
116114
if err != nil {
117-
log.WithError(err).Error("http2 server Shutdown() failed")
115+
log.Fatal("http2 server Shutdown() failed")
118116
}
119117
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2018- The Pixie Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
19+
declare -A GO_IMAGE_DIGEST_MAP=(
20+
["1.18-alpine@sha256:77f25981bd57e60a510165f3be89c901aec90453fd0f1c5a45691f6cb1528807"]="v1.57.2"
21+
["1.19-alpine@sha256:0ec0646e208ea58e5d29e558e39f2e59fccf39b7bda306cb53bbaff91919eca5"]="v1.58.3"
22+
["1.20-alpine@sha256:e47f121850f4e276b2b210c56df3fda9191278dd84a3a442bfe0b09934462a8f"]="v1.58.3"
23+
["1.21-alpine@sha256:2414035b086e3c42b99654c8b26e6f5b1b1598080d65fd03c7f499552ff4dc94"]="v1.58.3"
24+
["1.22-alpine@sha256:1699c10032ca2582ec89a24a1312d986a3f094aed3d5c1147b19880afe40e052"]="v1.58.3"
25+
)
26+
version=1.0
27+
28+
IMAGES=()
29+
30+
for go_image_digest in "${!GO_IMAGE_DIGEST_MAP[@]}"; do
31+
go_version=${go_image_digest%%-*}
32+
tag="ghcr.io/pixie-io/golang_${go_version//./_}_grpc_server_with_buildinfo:$version"
33+
google_golang_grpc=${GO_IMAGE_DIGEST_MAP[$go_image_digest]}
34+
echo "Building and pushing image: $tag"
35+
docker build . --build-arg GO_IMAGE_DIGEST="${go_image_digest}" --build-arg GOOGLE_GOLANG_GRPC="${google_golang_grpc}" -t "${tag}"
36+
docker push "${tag}"
37+
sha=$(docker inspect --format='{{index .RepoDigests 0}}' "${tag}" | cut -f2 -d'@')
38+
IMAGES+=("${tag}@${sha}")
39+
done
40+
41+
echo ""
42+
echo "Images pushed!"
43+
echo "IMPORTANT: Now update //bazel/container_images.bzl with the following digest: $sha"
44+
echo "Images:"
45+
for image in "${IMAGES[@]}"; do
46+
echo " - $image"
47+
done

src/stirling/testing/demo_apps/go_https/server/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ go_library(
2424
name = "server_lib",
2525
srcs = ["https_server.go"],
2626
importpath = "px.dev/pixie/src/stirling/testing/demo_apps/go_https/server",
27-
deps = [
28-
"@com_github_spf13_pflag//:pflag",
29-
"@com_github_spf13_viper//:viper",
30-
],
3127
)
3228

3329
genrule(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2018- The Pixie Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
ARG GO_IMAGE_DIGEST
18+
FROM alpine:3.20@sha256:de4fe7064d8f98419ea6b49190df1abbf43450c1702eeb864fe9ced453c1cc5f AS certs
19+
20+
RUN apk add --no-cache openssl
21+
22+
WORKDIR /tmp/certs
23+
24+
# Generate private key
25+
RUN openssl ecparam -genkey -name secp384r1 -out server.key && \
26+
openssl req -new -x509 -sha256 \
27+
-key server.key \
28+
-subj "/C=US/ST=California/L=San Francisco/O=Pixie Labs Inc./CN=127.0.0.1:50101" \
29+
-out server.crt \
30+
-days 365
31+
32+
# Stage 2: Build Go app and include certs
33+
FROM golang:${GO_IMAGE_DIGEST} as build
34+
35+
ARG GOLANG_X_NET
36+
37+
WORKDIR /app
38+
39+
# Copy source and build
40+
COPY https_server.go .
41+
RUN go mod init https_server && \
42+
go get golang.org/x/net@${GOLANG_X_NET} && \
43+
go mod tidy
44+
RUN CGO_ENABLED=0 go build -o https_server .
45+
46+
FROM scratch
47+
COPY --from=build /app /app
48+
COPY --from=certs /tmp/certs/server.crt /etc/ssl/server.crt
49+
COPY --from=certs /tmp/certs/server.key /etc/ssl/server.key
50+
51+
ENTRYPOINT ["/app/https_server"]
52+
CMD ["--cert", "/etc/ssl/server.crt", "--key", "/etc/ssl/server.key"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Go HTTPS server for testing Go TLS tracing
2+
3+
This directory contains a Go HTTPS server for testing Pixie's Go TLS tracing capabilities. This application is built through bazel and by the `update_ghcr.sh` script contained in this directory. The reason for this is that as Go versions fall out of support, maintaining these in our bazel build hinders our ability to upgrade our go deps and to upgrade Pixie's Go version.
4+
5+
In addition to this, Pixie's upcoming opentelemetry-go-instrumentation offsetgen based tracing requires building binaries with Go's toolchain until https://github.com/bazel-contrib/rules_go/issues/3090 is resolved.
6+
7+
As new Go versions are released, the out of support versions should be removed from bazel and added to the `update_ghcr.sh` script in this directory. This will allow our builds to maintain test coverage for older Go versions without complicating our ability to upgrade Pixie's Go version and dependencies.
8+
9+
Run `update_ghcr.sh` in this directory to push the images for each Go version to the ghcr.io repo.

src/stirling/testing/demo_apps/go_https/server/https_server.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
package main
2020

2121
import (
22+
"flag"
2223
"fmt"
2324
"io"
2425
"log"
2526
"net/http"
26-
27-
"github.com/spf13/pflag"
28-
"github.com/spf13/viper"
2927
)
3028

3129
const (
@@ -58,14 +56,12 @@ func listenAndServe(port int) {
5856
}
5957

6058
func main() {
61-
pflag.String("cert", "", "Path to the .crt file.")
62-
pflag.String("key", "", "Path to the .key file.")
63-
pflag.Parse()
64-
65-
viper.BindPFlags(pflag.CommandLine)
59+
certPath := flag.String("cert", "", "Path to the .crt file.")
60+
keyPath := flag.String("key", "", "Path to the .key file.")
61+
flag.Parse()
6662

6763
http.HandleFunc("/", basicHandler)
6864

69-
go listenAndServeTLS(httpsPort, viper.GetString("cert"), viper.GetString("key"))
65+
go listenAndServeTLS(httpsPort, *certPath, *keyPath)
7066
listenAndServe(httpPort)
7167
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2018- The Pixie Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
19+
declare -A GO_IMAGE_DIGEST_MAP=(
20+
["1.18-alpine@sha256:77f25981bd57e60a510165f3be89c901aec90453fd0f1c5a45691f6cb1528807"]="v0.35.0"
21+
["1.19-alpine@sha256:0ec0646e208ea58e5d29e558e39f2e59fccf39b7bda306cb53bbaff91919eca5"]="v0.35.0"
22+
["1.20-alpine@sha256:e47f121850f4e276b2b210c56df3fda9191278dd84a3a442bfe0b09934462a8f"]="v0.35.0"
23+
["1.21-alpine@sha256:2414035b086e3c42b99654c8b26e6f5b1b1598080d65fd03c7f499552ff4dc94"]="v0.35.0"
24+
["1.22-alpine@sha256:1699c10032ca2582ec89a24a1312d986a3f094aed3d5c1147b19880afe40e052"]="v0.35.0"
25+
)
26+
version=1.0
27+
28+
IMAGES=()
29+
30+
for go_image_digest in "${!GO_IMAGE_DIGEST_MAP[@]}"; do
31+
go_version=${go_image_digest%%-*}
32+
tag="ghcr.io/pixie-io/golang_${go_version//./_}_https_server_with_buildinfo:$version"
33+
x_net_version=${GO_IMAGE_DIGEST_MAP[$go_image_digest]}
34+
echo "Building and pushing image: $tag"
35+
docker build . --build-arg GO_IMAGE_DIGEST="${go_image_digest}" --build-arg GOLANG_X_NET="${x_net_version}" -t "${tag}"
36+
docker push "${tag}"
37+
sha=$(docker inspect --format='{{index .RepoDigests 0}}' "${tag}" | cut -f2 -d'@')
38+
IMAGES+=("${tag}@${sha}")
39+
done
40+
41+
echo ""
42+
echo "Images pushed!"
43+
echo "IMPORTANT: Now update //bazel/container_images.bzl with the following digest: $sha"
44+
echo "Images:"
45+
for image in "${IMAGES[@]}"; do
46+
echo " - $image"
47+
done

0 commit comments

Comments
 (0)