Skip to content

Instantly share code, notes, and snippets.

@Formergg
Created February 22, 2021 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Formergg/ce5fa129c1fe2de724357d7c5cb8fed7 to your computer and use it in GitHub Desktop.
Save Formergg/ce5fa129c1fe2de724357d7c5cb8fed7 to your computer and use it in GitHub Desktop.
Case 1:使用代码构建,部署失败 - 服务无法正常拉起
# 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"]
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