-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from crazy-max/test-update
test: update go example
- Loading branch information
Showing
4 changed files
with
15 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |