diff --git a/Dockerfile b/Dockerfile index 654e7b70..98ef6528 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,11 @@ -# This is a multi-stage build. First we are going to compile and then -# create a small image for runtime. -FROM golang:1.11.1 as builder +FROM public.ecr.aws/docker/library/python:3 -RUN mkdir -p /go/src/github.com/eks-workshop-sample-api-service-go -WORKDIR /go/src/github.com/eks-workshop-sample-api-service-go -RUN useradd -u 10001 app -COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . +COPY create.py / +COPY /templates/. /templates -FROM scratch - -COPY --from=builder /go/src/github.com/eks-workshop-sample-api-service-go/main /main -COPY --from=builder /etc/passwd /etc/passwd -USER app +RUN pip install Flask +RUN pip install boto3 EXPOSE 8080 -CMD ["/main"] + +ENTRYPOINT ["python", "create.py"] diff --git a/create.py b/create.py new file mode 100644 index 00000000..a72e3d36 --- /dev/null +++ b/create.py @@ -0,0 +1,15 @@ +from flask import Flask +from flask import Flask, render_template +import boto3 + + +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('index.html') + + + +if __name__ == '__main__': + app.run(host="0.0.0.0", port=8080) diff --git a/main.go b/main.go deleted file mode 100644 index 2ff83f10..00000000 --- a/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "os" - "sort" - "strings" -) - -func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - - f := fib() - - res := &response{Message: "Hello World"} - - for _, e := range os.Environ() { - pair := strings.Split(e, "=") - res.EnvVars = append(res.EnvVars, pair[0]+"="+pair[1]) - } - sort.Strings(res.EnvVars) - - for i := 1; i <= 90; i++ { - res.Fib = append(res.Fib, f()) - } - - // Beautify the JSON output - out, _ := json.MarshalIndent(res, "", " ") - - // Normally this would be application/json, but we don't want to prompt downloads - w.Header().Set("Content-Type", "text/plain") - - io.WriteString(w, string(out)) - - fmt.Println("Hello world - the log message") - }) - http.ListenAndServe(":8080", nil) -} - -type response struct { - Message string `json:"message"` - EnvVars []string `json:"env"` - Fib []int `json:"fib"` -} - -func fib() func() int { - a, b := 0, 1 - return func() int { - a, b = b, a+b - return a - } -} diff --git a/static/style.css b/static/style.css new file mode 100644 index 00000000..ef2206f0 --- /dev/null +++ b/static/style.css @@ -0,0 +1,4 @@ +body { + background: red; + color: yellow; +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 00000000..bbe96723 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,8 @@ + +
+ + + +