Skip to content

Commit 9b3a0b7

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

File tree

5 files changed

+118
-10
lines changed

5 files changed

+118
-10
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ go_library(
2525
srcs = ["https_server.go"],
2626
importpath = "px.dev/pixie/src/stirling/testing/demo_apps/go_https/server",
2727
deps = [
28-
"@com_github_spf13_pflag//:pflag",
29-
"@com_github_spf13_viper//:viper",
28+
"@org_golang_x_net//http2",
3029
],
3130
)
3231

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_VERSION
18+
FROM alpine:3.20 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_VERSION}-alpine 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: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@
1919
package main
2020

2121
import (
22+
"flag"
2223
"fmt"
2324
"io"
2425
"log"
2526
"net/http"
2627

27-
"github.com/spf13/pflag"
28-
"github.com/spf13/viper"
28+
"golang.org/x/net/http2"
2929
)
3030

3131
const (
3232
httpPort = 50100
3333
httpsPort = 50101
3434
)
3535

36+
// Import the http2 package to ensure golang.org/x/net exists within the binary's
37+
// buildinfo.
38+
var s http2.Server //nolint:unused
39+
3640
func basicHandler(w http.ResponseWriter, r *http.Request) {
3741
w.Header().Add("Content-Type", "application/json")
3842
_, err := io.WriteString(w, `{"status":"ok"}`)
@@ -58,14 +62,12 @@ func listenAndServe(port int) {
5862
}
5963

6064
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)
65+
certPath := flag.String("cert", "", "Path to the .crt file.")
66+
keyPath := flag.String("key", "", "Path to the .key file.")
67+
flag.Parse()
6668

6769
http.HandleFunc("/", basicHandler)
6870

69-
go listenAndServeTLS(httpsPort, viper.GetString("cert"), viper.GetString("key"))
71+
go listenAndServeTLS(httpsPort, *certPath, *keyPath)
7072
listenAndServe(httpPort)
7173
}
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"]="v0.35.0"
21+
["1.19"]="v0.35.0"
22+
["1.20"]="v0.35.0"
23+
["1.21"]="v0.35.0"
24+
["1.22"]="v0.35.0"
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//./_}_https_server_with_buildinfo:$version"
32+
x_net_version=${GO_VERSIONS[$go_version]}
33+
echo "Building and pushing image: $tag"
34+
docker build . --build-arg GO_VERSION="${go_version}" --build-arg GOLANG_X_NET="${x_net_version}" -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)