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

Clean up e2e Dockerfiles #1393

Merged
merged 14 commits into from
Dec 13, 2024
4 changes: 2 additions & 2 deletions .github/workflows/e2e/k8s/sample-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ spec:
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c"]
# send SIGTERM to otel-go-instrumentation once the sample app has generated data so the job completes.
args: ["(/sample-app/start.sh || /sample-app/main) && kill -TERM $(pidof otel-go-instrumentation)"]
args: ["/usr/local/bin/app; kill -TERM $(pidof otel-go-instrumentation)"]
- name: auto-instrumentation
image: otel-go-instrumentation
imagePullPolicy: IfNotPresent
command: ["/otel-go-instrumentation", "-global-impl", "-log-level=debug"]
env:
- name: OTEL_GO_AUTO_TARGET_EXE
value: /sample-app/main
value: /usr/local/bin/app
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://test-opentelemetry-collector:4318"
- name: OTEL_SERVICE_NAME
Expand Down
10 changes: 5 additions & 5 deletions internal/test/e2e/autosdk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ COPY sdk/ /usr/src/go.opentelemetry.io/auto/sdk/
COPY internal/test/e2e/autosdk/go.mod internal/test/e2e/autosdk/go.sum ./
RUN go mod download && go mod verify

COPY internal/test/e2e/autosdk/main.go .
RUN go build -v -o /sample-app/main
COPY internal/test/e2e/autosdk/*.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

WORKDIR /sample-app

CMD ["/sample-app/main"]
ENTRYPOINT ["/usr/local/bin/app"]
16 changes: 13 additions & 3 deletions internal/test/e2e/databasesql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /sample-app
COPY . .
RUN go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/databasesql
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

ENTRYPOINT ["/usr/local/bin/app"]
16 changes: 13 additions & 3 deletions internal/test/e2e/gin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /sample-app
COPY . .
RUN go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/gin
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

ENTRYPOINT ["/usr/local/bin/app"]
16 changes: 13 additions & 3 deletions internal/test/e2e/grpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /sample-app
COPY . .
RUN go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/grpc
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

ENTRYPOINT ["/usr/local/bin/app"]
28 changes: 20 additions & 8 deletions internal/test/e2e/kafka-go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37 AS builder
WORKDIR /sample-app
COPY . .
RUN CGO_ENABLED=0 go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/kafka-go
COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 go build -v -o /usr/local/bin/app .

FROM bitnami/kafka:latest@sha256:978583d0859444d3bc6b6592b38b5af5a834d473db51441071a20e67e0afb945

Expand All @@ -12,9 +21,12 @@ ENV KAFKA_CFG_LISTENERS=PLAINTEXT://127.0.0.1:9092,CONTROLLER://:9093
ENV KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
ENV [email protected]:9093
ENV KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
WORKDIR /sample-app
COPY --from=builder /sample-app/main .
COPY --from=builder /usr/local/bin/app /usr/local/bin/app

# Add script target of /usr/local/bin/app
WORKDIR /opt/kafka/
COPY start.sh .
RUN chmod +x start.sh
WORKDIR /
ENTRYPOINT ["/sample-app/start.sh"]
RUN chmod +x /opt/kafka/start.sh

ENTRYPOINT ["/usr/local/bin/app"]
CMD ["-setup=/opt/kafka/start.sh"]
16 changes: 16 additions & 0 deletions internal/test/e2e/kafka-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ package main

import (
"context"
"flag"
"fmt"
"os"
"os/exec"
"time"

kafka "github.com/segmentio/kafka-go"
Expand Down Expand Up @@ -73,6 +76,19 @@ func reader(readChan chan bool) {
}

func main() {
setup := flag.String("setup", "./start.sh", "Kafka setup script")
flag.Parse()

cmd := exec.Command(*setup)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
fmt.Println("starting Kafka...")
if err := cmd.Run(); err != nil {
fmt.Printf("failed to start Kafka: %v\n", err)
os.Exit(1)
}
fmt.Println("started Kafka")

kafkaWriter := getKafkaWriter()
defer kafkaWriter.Close()

Expand Down
3 changes: 0 additions & 3 deletions internal/test/e2e/kafka-go/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ while ! kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --topic hc --create --
echo "kafka is not available yet. Retrying in 1 second..."
sleep 1
done

# # Run the Go application
/sample-app/main
16 changes: 13 additions & 3 deletions internal/test/e2e/nethttp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /sample-app
COPY . .
RUN go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/nethttp
COPY go.mod ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

ENTRYPOINT ["/usr/local/bin/app"]
16 changes: 13 additions & 3 deletions internal/test/e2e/nethttp_custom/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /sample-app
COPY . .
RUN go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/nethttp_custom
COPY go.mod ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

ENTRYPOINT ["/usr/local/bin/app"]
16 changes: 13 additions & 3 deletions internal/test/e2e/otelglobal/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
WORKDIR /sample-app
COPY . .
RUN go build -o main

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/otelglobal
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .

ENTRYPOINT ["/usr/local/bin/app"]
Loading