Skip to content

Commit 2117bfa

Browse files
committed
Add demo_apps/go_grpc_tls_pl Dockerfile to ease deprecating Go versions and for offsetgen testing
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 9b3a0b7 commit 2117bfa

File tree

5 files changed

+127
-16
lines changed

5 files changed

+127
-16
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_VERSION
18+
FROM alpine:3.20 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_VERSION}-alpine 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"]

src/stirling/testing/demo_apps/go_grpc_tls_pl/server/README.md

Whitespace-only changes.

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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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_VERSIONS=(
20+
["1.18"]="v1.57.2"
21+
["1.19"]="v1.58.3"
22+
["1.20"]="v1.58.3"
23+
["1.21"]="v1.58.3"
24+
["1.22"]="v1.58.3"
25+
)
26+
version=1.0
27+
28+
IMAGES=()
29+
30+
for go_version in "${!GO_VERSIONS[@]}"; do
31+
tag="ghcr.io/pixie-io/golang_${go_version//./_}_grpc_server_with_buildinfo:$version"
32+
google_golang_grpc=${GO_VERSIONS[$go_version]}
33+
echo "Building and pushing image: $tag"
34+
docker build . --build-arg GO_VERSION="${go_version}" --build-arg GOOGLE_GOLANG_GRPC="${google_golang_grpc}" -t "${tag}"
35+
docker push "${tag}"
36+
sha=$(docker inspect --format='{{index .RepoDigests 0}}' "${tag}" | cut -f2 -d'@')
37+
IMAGES+=("${tag}@${sha}")
38+
done
39+
40+
echo ""
41+
echo "Images pushed!"
42+
echo "IMPORTANT: Now update //bazel/container_images.bzl with the following digest: $sha"
43+
echo "Images:"
44+
for image in "${IMAGES[@]}"; do
45+
echo " - $image"
46+
done

0 commit comments

Comments
 (0)