Skip to content

Commit a3646c0

Browse files
committed
test: update go example
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent 5c3465b commit a3646c0

File tree

4 files changed

+15
-83
lines changed

4 files changed

+15
-83
lines changed

test/go/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
FROM golang:1.19-alpine AS base
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:alpine AS base
24
ENV CGO_ENABLED=0
35
RUN apk add --no-cache file git
46
WORKDIR /src
57

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

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

15-
FROM alpine:3.17 AS image
16+
FROM alpine AS image
1617
COPY --from=build /usr/bin/app /bin/app
18+
EXPOSE 8080
19+
ENTRYPOINT ["/bin/app"]

test/go/go.mod

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
11
module github.com/docker/build-push-action/test/go
22

33
go 1.18
4-
5-
require github.com/labstack/echo/v4 v4.9.1
6-
7-
require (
8-
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
9-
github.com/labstack/gommon v0.4.0 // indirect
10-
github.com/mattn/go-colorable v0.1.11 // indirect
11-
github.com/mattn/go-isatty v0.0.14 // indirect
12-
github.com/valyala/bytebufferpool v1.0.0 // indirect
13-
github.com/valyala/fasttemplate v1.2.1 // indirect
14-
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
15-
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
16-
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
17-
golang.org/x/text v0.3.7 // indirect
18-
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
19-
)

test/go/go.sum

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/go/main.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
package main
22

33
import (
4+
"fmt"
5+
"log"
46
"net/http"
5-
"os"
6-
7-
"github.com/labstack/echo/v4"
8-
"github.com/labstack/echo/v4/middleware"
97
)
108

119
func main() {
12-
e := echo.New()
13-
14-
e.Use(middleware.Logger())
15-
e.Use(middleware.Recover())
16-
17-
e.GET("/", func(c echo.Context) error {
18-
return c.HTML(http.StatusOK, "Hello World")
10+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
11+
fmt.Fprintf(w, "Hello, Go!")
1912
})
20-
21-
e.GET("/ping", func(c echo.Context) error {
22-
return c.JSON(http.StatusOK, struct{ Status string }{Status: "OK"})
23-
})
24-
25-
httpPort := os.Getenv("HTTP_PORT")
26-
if httpPort == "" {
27-
httpPort = "8080"
28-
}
29-
30-
e.Logger.Fatal(e.Start(":" + httpPort))
13+
log.Fatal(http.ListenAndServe(":8080", nil))
3114
}

0 commit comments

Comments
 (0)