Skip to content

Commit

Permalink
feat(tests/perf): add docker-compose for number-fact testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lffg committed Jun 21, 2024
1 parent 0ede304 commit acacc8d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tests/containers/html/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ FROM golang:1.22.3-alpine AS build
WORKDIR /app

COPY main.go .
RUN CGO_ENABLED=0 GOOS=linux go build -o myapp /app/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o html-app /app/main.go

FROM alpine:edge
WORKDIR /app

COPY tpl tpl
COPY --from=build /app/myapp .
COPY --from=build /app/html-app .

# Set the timezone and install CA certificates
RUN apk --no-cache add ca-certificates tzdata

ENTRYPOINT ["/app/myapp"]
ENTRYPOINT ["/app/html-app"]
15 changes: 15 additions & 0 deletions tests/containers/number-fact/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.22.3-alpine AS build
WORKDIR /app

COPY main.go .
RUN CGO_ENABLED=0 GOOS=linux go build -o number-fact /app/main.go

FROM alpine:edge
WORKDIR /app

COPY --from=build /app/number-fact .

# Set the timezone and install CA certificates
RUN apk --no-cache add ca-certificates tzdata

ENTRYPOINT ["/app/number-fact"]
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package main

import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"log"
"math/big"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -94,9 +98,36 @@ func factorHandler(w http.ResponseWriter, r *http.Request) {
}
}

func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, world! (responding for %v)", r.RemoteAddr)
}

func main() {
http.HandleFunc("/factors", factorHandler)
mux := http.NewServeMux()
mux.HandleFunc("/factors", factorHandler)
mux.HandleFunc("/hello", helloHandler)

port := os.Getenv("PORT")
if port == "" {
log.Fatal("must provide PORT environment variable")
}
srv := &http.Server{
Addr: fmt.Sprintf(":%s", port),
Handler: mux,
}

// Graceful shutdown
done := make(chan os.Signal)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-done
log.Println("shutting down server...")
if err := srv.Shutdown(context.Background()); err != nil {
log.Fatal("error during shutdown", err)
}
}()

fmt.Println("Server is listening on port 8080...")
log.Fatal(http.ListenAndServe(":8080", nil))
log.Printf("(%d) server listening at port %s", os.Getpid(), port)
srv.ListenAndServe()
}
19 changes: 19 additions & 0 deletions tests/perf-analysis/single-node/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
server01:
build: ../../containers/number-fact
hostname: html1
networks:
- tucano-cluster-net
ports:
- "8080:8080"
environment:
PORT: "8080"
deploy:
resources:
limits:
cpus: "1"
memory: "512MB"

networks:
tucano-cluster-net:
attachable: true

0 comments on commit acacc8d

Please sign in to comment.