Skip to content

Commit

Permalink
test: update go example
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Apr 9, 2023
1 parent c5f5149 commit d4d5e64
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 83 deletions.
17 changes: 10 additions & 7 deletions test/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
FROM golang:1.19-alpine AS base
# syntax=docker/dockerfile:1

FROM golang:alpine AS base
ENV CGO_ENABLED=0
RUN apk add --no-cache file git
WORKDIR /src

FROM base as build
COPY go.mod go.sum ./
RUN go mod download -x
COPY . .
RUN go build -ldflags "-s -w" -o /usr/bin/app .
FROM base AS build
RUN --mount=type=bind,target=/src \
--mount=type=cache,target=/root/.cache/go-build \
go build -ldflags "-s -w" -o /usr/bin/app .

FROM scratch AS binary
COPY --from=build /usr/bin/app /bin/app

FROM alpine:3.17 AS image
FROM alpine AS image
COPY --from=build /usr/bin/app /bin/app
EXPOSE 8080
ENTRYPOINT ["/bin/app"]
16 changes: 0 additions & 16 deletions test/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
module github.com/docker/bake-action/test/go

go 1.18

require github.com/labstack/echo/v4 v4.9.1

require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
)
38 changes: 0 additions & 38 deletions test/go/go.sum

This file was deleted.

27 changes: 5 additions & 22 deletions test/go/main.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
package main

import (
"fmt"
"log"
"net/http"
"os"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)

func main() {
e := echo.New()

e.Use(middleware.Logger())
e.Use(middleware.Recover())

e.GET("/", func(c echo.Context) error {
return c.HTML(http.StatusOK, "Hello World")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, Go!")
})

e.GET("/ping", func(c echo.Context) error {
return c.JSON(http.StatusOK, struct{ Status string }{Status: "OK"})
})

httpPort := os.Getenv("HTTP_PORT")
if httpPort == "" {
httpPort = "8080"
}

e.Logger.Fatal(e.Start(":" + httpPort))
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit d4d5e64

Please sign in to comment.