From 8026f03b111d65ffbac7f11fc056abef430a77f8 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sat, 9 May 2020 14:48:51 -0700 Subject: add dockerfile and makefile --- .Dockerignore | 1 + Dockerfile | 25 +++++++++++++++++++++++++ Makefile | 11 +++++++++++ api/routes.go | 2 +- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .Dockerignore create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.Dockerignore b/.Dockerignore new file mode 100644 index 0000000..10d4fb7 --- /dev/null +++ b/.Dockerignore @@ -0,0 +1 @@ +frontend \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5a14889 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +## Build stage +FROM golang:alpine AS builder +ENV GO111MODULE=on + +# Copy files to image +COPY . /app/src +WORKDIR /app/src + +RUN apk add git ca-certificates +RUN go mod download + +# Build image +RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/app + +## Image creation stage +FROM scratch + +# Copy app +COPY --from=builder /go/bin/app /go/bin/app + +# Expose ports, change port to whatever you need to expose +EXPOSE 8080 + +# Run app +ENTRYPOINT ["/go/bin/app"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..23c4374 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +run: + go run . +lint: + golangci-lint run +docker-build: + docker build -t jzhao2k19/ctrl-v:latest . +docker-run: + docker run -p 8080:8080 jzhao2k19/ctrl-v:latest +docker-all: docker-build docker-run +docker-push: + docker push jzhao2k19/ctrl-v:latest \ No newline at end of file diff --git a/api/routes.go b/api/routes.go index 6f9c17b..103de04 100644 --- a/api/routes.go +++ b/api/routes.go @@ -19,7 +19,7 @@ func insertFunc(w http.ResponseWriter, r *http.Request) { content := r.FormValue("content") // get ip - ip, _ := getIP(r) + ip := getIP(r) log.Infof("got content '%s' and ip '%s'", content, ip) -- cgit v1.2.3