From 0af787b6f52457c232cd04983c76a430b5e73232 Mon Sep 17 00:00:00 2001 From: Sam Alba <216487+samalba@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:24:59 -0700 Subject: [PATCH] test commit Signed-off-by: Sam Alba <216487+samalba@users.noreply.github.com> --- .github/workflows/dagger.yml | 33 +++++++++++++++++++++++++++++++++ Dockerfile | 14 ++++++++++++++ app.go | 35 +++++++++++++++++++++++++++++++++++ go.mod | 3 +++ go.sum | 0 templates/index.html.tmpl | 15 +++++++++++++++ 6 files changed, 100 insertions(+) create mode 100644 .github/workflows/dagger.yml create mode 100644 Dockerfile create mode 100644 app.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 templates/index.html.tmpl diff --git a/.github/workflows/dagger.yml b/.github/workflows/dagger.yml new file mode 100644 index 0000000..0e400cc --- /dev/null +++ b/.github/workflows/dagger.yml @@ -0,0 +1,33 @@ +name: dagger +on: + push: + branches: [main] + +jobs: + test: + name: test + runs-on: depot-ubuntu-22.04,dagger=0.13.6 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test + uses: dagger/dagger-for-github@v6 + with: + version: "0.13.6" + verb: call + module: github.com/kpenfound/dagger-modules/golang@v0.2.0 + args: test --source=. + build: + name: build + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Call Dagger Function + uses: dagger/dagger-for-github@v6 + with: + version: "latest" + verb: call + module: github.com/kpenfound/dagger-modules/golang@v0.2.0 + args: build-container --source=. --args=. publish --address=ttl.sh/my-app-$RANDOM:2h diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cb057e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.23 AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY *.go ./ +COPY ./templates ./templates +RUN CGO_ENABLED=0 GOOS=linux go build -o /app/app-bin + +FROM alpine:3.20 +COPY --from=builder /app/app-bin /app/app-bin +ENTRYPOINT ["/app/app-bin"] diff --git a/app.go b/app.go new file mode 100644 index 0000000..297eb5f --- /dev/null +++ b/app.go @@ -0,0 +1,35 @@ +package main + +import ( + "embed" + "html/template" + "log" + "net/http" + "os" + "strings" +) + +//go:embed templates/* +var resources embed.FS + +var t = template.Must(template.ParseFS(resources, "templates/*")) + +func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + + } + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + data := map[string]string{ + "text": os.Getenv("TEXT"), + "env": strings.Join(os.Environ(), "\n"), + } + + t.ExecuteTemplate(w, "index.html.tmpl", data) + }) + + log.Println("listening on", port) + log.Fatal(http.ListenAndServe(":"+port, nil)) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fcece7a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/fly-apps/go-example + +go 1.22 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/templates/index.html.tmpl b/templates/index.html.tmpl new file mode 100644 index 0000000..bc8c01a --- /dev/null +++ b/templates/index.html.tmpl @@ -0,0 +1,15 @@ + + +
+ + +{{.text}}+{{end}} +
+{{.env}} ++ +