Created
February 22, 2021 08:59
-
-
Save Formergg/ce5fa129c1fe2de724357d7c5cb8fed7 to your computer and use it in GitHub Desktop.
Case 1:使用代码构建,部署失败 - 服务无法正常拉起
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
# Use the official golang image to create a build artifact | |
FROM golang:1.13 as builder | |
# Create app directory | |
RUN mkdir /app | |
# Add file to /app/ | |
ADD . /app/ | |
# Build the binary | |
WORKDIR /app | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . | |
# Run service on container startup | |
FROM alpine:latest | |
WORKDIR /app | |
COPY --from=builder /app/main . | |
CMD ["/app/main"] |
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
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
log.Print("Received a request.") | |
fmt.Fprintf(w, "Hello, Welcome to CloudBase!\n") | |
} | |
func main() { | |
panic("this is fail demo test") // this is show panic error !!! | |
log.Print("Server started.") | |
http.HandleFunc("/", handler) | |
port := os.Getenv("PORT") | |
if port == "" { | |
port = "80" | |
} | |
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment