From c3cc2fa9cd9b731e8ada652131768051dda5ae1b Mon Sep 17 00:00:00 2001
From: Pierre Michiels <pierre.michiels.etu@univ-lille.fr>
Date: Sun, 8 Nov 2020 15:57:10 +0100
Subject: [PATCH] 08.11.20 15:57

---
 TP5_06.11.20/Dockerfile                     | 11 +++--
 TP5_06.11.20/DockerfileWithPython.NoWorking | 50 +++++++++++++++++++++
 TP5_06.11.20/main.go                        | 16 +++++++
 TP5_06.11.20/requirements.txt               |  1 +
 TP5_06.11.20/server.py                      |  3 +-
 5 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 TP5_06.11.20/DockerfileWithPython.NoWorking
 create mode 100644 TP5_06.11.20/main.go
 create mode 100644 TP5_06.11.20/requirements.txt
 mode change 100644 => 100755 TP5_06.11.20/server.py

diff --git a/TP5_06.11.20/Dockerfile b/TP5_06.11.20/Dockerfile
index 1a09661..150f1b0 100644
--- a/TP5_06.11.20/Dockerfile
+++ b/TP5_06.11.20/Dockerfile
@@ -1,3 +1,8 @@
-FROM python:3 
-ADD server.py /
-CMD ["python3","./server.py"]
+FROM golang:alpine AS builder
+COPY main.go /app/
+WORKDIR /app
+RUN CGO_ENABLED=0 go build -ldflags="-w -s" main.go
+
+FROM scratch AS runner
+COPY --from=builder /app/main /app/main
+ENTRYPOINT ["/app/main"]
\ No newline at end of file
diff --git a/TP5_06.11.20/DockerfileWithPython.NoWorking b/TP5_06.11.20/DockerfileWithPython.NoWorking
new file mode 100644
index 0000000..f4396cc
--- /dev/null
+++ b/TP5_06.11.20/DockerfileWithPython.NoWorking
@@ -0,0 +1,50 @@
+# FROM python:3.7-alpine AS builder
+# COPY server.py /app/
+# WORKDIR /app
+# CMD ["python3","./server.py"]
+
+# FROM python:3.7-alpine as builder
+# COPY server.py /compiled/
+# WORKDIR /compiled
+# RUN python3 -m compileall server.py
+
+# RUN mkdir /install
+# WORKDIR /install
+# COPY requirements.txt /requirements.txt
+# RUN pip install --install-option="--prefix=/install" -r /requirements.txt
+
+# FROM builder
+# COPY --from=builder /install /usr/local
+# RUN mkdir app
+# COPY server.py /app
+# WORKDIR /app
+# CMD ["gunicorn", "-w 4", "server:app"]
+
+
+# FROM scratch AS runner
+# ENTRYPOINT ["/app"] 
+# FROM scratch AS runner
+# #COPY --from=builder /compiled/__pycache__ /runnable/
+# RUN mkdir /run
+# COPY server.py /run/
+# CMD ["sh", "/run/server.py"]
+#CMD ["/runnable/server.cpython-38.pyc"]
+
+
+# FROM python:3.7-alpine as base
+# FROM base as builder
+# RUN mkdir /install
+# WORKDIR /install
+# COPY requirements.txt /requirements.txt
+# RUN pip install --install-option="--prefix=/install" -r /requirements.txt
+# FROM base
+# COPY --from=builder /install /usr/local
+# COPY server.py /app
+# WORKDIR /app
+# CMD ["gunicorn", "-w 4", "main:app"]
+
+# Version fonctionnelle avec donnant une image de 41MB
+FROM python:3.7-alpine AS builder
+COPY server.py /app/
+WORKDIR /app
+CMD ["python3","./server.py"]
\ No newline at end of file
diff --git a/TP5_06.11.20/main.go b/TP5_06.11.20/main.go
new file mode 100644
index 0000000..d8f4758
--- /dev/null
+++ b/TP5_06.11.20/main.go
@@ -0,0 +1,16 @@
+package main
+
+import(
+	"fmt"
+	"net/http"
+	"os"
+)
+
+func main(){
+	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
+		r.Header.Set("Content-type", "text/html")
+		fmt.Fprintf(w, "<h1>Hello hostname: %s</h1>", os.Getenv("HOSTNAME"))
+	})
+
+	http.ListenAndServe(":80", nil)
+}
\ No newline at end of file
diff --git a/TP5_06.11.20/requirements.txt b/TP5_06.11.20/requirements.txt
new file mode 100644
index 0000000..e2e2dc9
--- /dev/null
+++ b/TP5_06.11.20/requirements.txt
@@ -0,0 +1 @@
+gunicorn>=19,<20
\ No newline at end of file
diff --git a/TP5_06.11.20/server.py b/TP5_06.11.20/server.py
old mode 100644
new mode 100755
index 4a0004d..212dd68
--- a/TP5_06.11.20/server.py
+++ b/TP5_06.11.20/server.py
@@ -1,3 +1,4 @@
+
 import http.server
 import socketserver
 import os
@@ -13,4 +14,4 @@ Handler = http.server.SimpleHTTPRequestHandler
 
 with socketserver.TCPServer(("", PORT), Handler) as httpd:
     print("serving at port", PORT)
-    httpd.serve_forever()
\ No newline at end of file
+    httpd.serve_forever()
-- 
GitLab