From bc8512edcfa4ea425137b7b1d7212b1334f80f48 Mon Sep 17 00:00:00 2001 From: "suguo.yao" Date: Wed, 10 May 2023 11:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=AE=B9=E5=99=A8=E7=BC=96?= =?UTF-8?q?=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Dockerfile | 27 +++++++++++++++++++++++++++ go.mod | 3 +++ main.go | 13 +++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 Dockerfile create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitignore b/.gitignore index f4d432a..b934526 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ +hello \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c3626c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM golang:1.18 as builder + +ENV GO111MODULE=on \ + GOPROXY=https://goproxy.io + +COPY . /app +WORKDIR /app + +RUN go get && go build -ldflags="-s -w" -installsuffix cgo -o hello + +FROM alpine:latest + +ENV TZ=Asia/Shanghai \ + LANG=C.UTF-8 \ + APP_DIR=/app + +COPY --from=builder /app/hello ${APP_DIR}/hello + +WORKDIR ${APP_DIR} + +RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \ + && echo ${TZ} > /etc/timezone \ + && chmod +x hello + +# EXPOSE 5678 + +CMD ["./hello"] \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4a2c9ba --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module myschools.me/suguo/hello + +go 1.20 diff --git a/main.go b/main.go new file mode 100644 index 0000000..a120def --- /dev/null +++ b/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + for { + fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "hello world.") + time.Sleep(time.Minute) + } +}