From 4cb26457d1254c74f40c2358ce53baf360cc45bf Mon Sep 17 00:00:00 2001 From: Iliyan Vutov Date: Wed, 16 Oct 2024 18:29:02 +0300 Subject: [PATCH 01/10] U24 --- .python-version | 1 + app/app.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .python-version create mode 100644 app/app.py diff --git a/.python-version b/.python-version new file mode 100644 index 000000000..b6d8b7612 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.11.8 diff --git a/app/app.py b/app/app.py new file mode 100644 index 000000000..67e0180c0 --- /dev/null +++ b/app/app.py @@ -0,0 +1,14 @@ +import os + +from flask import Flask + +app = Flask(__name__) + + +@app.route("/") +def hello_world(): + return "Hello, World!" + + +if __name__ == "__main__": + app.run(port=os.environ.get("PORT", 3000), host="0.0.0.0") From 05cc45af275c51f499b8203da1d6b20ab95ef833 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 19:41:41 +0300 Subject: [PATCH 02/10] Practice 1 Dockerfile with python --- Dockerfile | 12 ++++++++++++ requirements.txt | 1 + 2 files changed, 13 insertions(+) create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..b7d9b34b8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:22.04 +RUN apt-get update -y && +RUN apt-get upgrade -y && +RUN apt-get install -y python3 +COPY requirements.txt requirements.txt +RUN `pip install -r requirements.txt` +RUN useradd -ms /bin/bash myuser +USER myuser +COPY app /app +WORKDIR /app +EXPOSE 5000 +CMD ["python3", "app.py"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..0f800fccf --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask==3.0.0 \ No newline at end of file From c20043421950e9e1c87920673ca23971e44a5453 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 19:47:00 +0300 Subject: [PATCH 03/10] Add missing escape for the pipes --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7d9b34b8..d29100469 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:22.04 -RUN apt-get update -y && -RUN apt-get upgrade -y && +RUN apt-get update -y && \ +RUN apt-get upgrade -y && \ RUN apt-get install -y python3 COPY requirements.txt requirements.txt RUN `pip install -r requirements.txt` From 5ba9f55ef90d32f7d963bac1fc081727bbdbcb57 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 19:48:57 +0300 Subject: [PATCH 04/10] Additional changes to RUN command --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d29100469..a077783e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:22.04 RUN apt-get update -y && \ -RUN apt-get upgrade -y && \ -RUN apt-get install -y python3 + apt-get upgrade -y && \ + apt-get install -y python3 COPY requirements.txt requirements.txt RUN `pip install -r requirements.txt` RUN useradd -ms /bin/bash myuser From dc712576cdce12f13e5ba015d893e4aa31ea55bd Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 19:55:20 +0300 Subject: [PATCH 05/10] Add python3-pip --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a077783e8..619b50497 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM ubuntu:22.04 RUN apt-get update -y && \ apt-get upgrade -y && \ - apt-get install -y python3 + apt-get install -y python3 && \ + apt-get install python3-pip COPY requirements.txt requirements.txt RUN `pip install -r requirements.txt` RUN useradd -ms /bin/bash myuser From 69d4ef65a358c28598d91e15139bb8559a998732 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 20:01:16 +0300 Subject: [PATCH 06/10] Add -y --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 619b50497..e1aeb7eae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:22.04 RUN apt-get update -y && \ apt-get upgrade -y && \ apt-get install -y python3 && \ - apt-get install python3-pip + apt-get install -y python3-pip COPY requirements.txt requirements.txt RUN `pip install -r requirements.txt` RUN useradd -ms /bin/bash myuser From 01f66ac53c5777c8acf0eb28489247918a479068 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 20:07:42 +0300 Subject: [PATCH 07/10] Refactor again --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e1aeb7eae..dc9a6cba4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,9 @@ RUN apt-get update -y && \ apt-get install -y python3 && \ apt-get install -y python3-pip COPY requirements.txt requirements.txt -RUN `pip install -r requirements.txt` RUN useradd -ms /bin/bash myuser USER myuser +RUN `pip install -r requirements.txt` COPY app /app WORKDIR /app EXPOSE 5000 From e934bddb41af233ae733b40e23595419ee1a0f2c Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 20:10:09 +0300 Subject: [PATCH 08/10] Refactor 2 --- Dockerfile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index dc9a6cba4..bc1eb138c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ FROM ubuntu:22.04 -RUN apt-get update -y && \ - apt-get upgrade -y && \ - apt-get install -y python3 && \ - apt-get install -y python3-pip -COPY requirements.txt requirements.txt -RUN useradd -ms /bin/bash myuser -USER myuser -RUN `pip install -r requirements.txt` -COPY app /app +RUN apt-get update && \ + apt-get install -y && \ + apt-get install python3 -y && \ + apt-get install pip -y && \ + groupadd -g 1234 notroot && \ + useradd -m -u 1234 -g notroot notroot +USER notroot WORKDIR /app +COPY requirements.txt . +RUN pip install -r requirements.txt +COPY app . EXPOSE 5000 CMD ["python3", "app.py"] \ No newline at end of file From de09d4a7512b123546d5af5caf7e7a2214102483 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 20:13:47 +0300 Subject: [PATCH 09/10] change port inside app.py to 5000 from 3000 --- app/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index 67e0180c0..1c2c83d55 100644 --- a/app/app.py +++ b/app/app.py @@ -11,4 +11,4 @@ def hello_world(): if __name__ == "__main__": - app.run(port=os.environ.get("PORT", 3000), host="0.0.0.0") + app.run(port=os.environ.get("PORT", 5000), host="0.0.0.0") From 6340897fc906d08b10295c6e21b211e0fee1f589 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 23 Oct 2024 20:43:50 +0300 Subject: [PATCH 10/10] Refactorring --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index bc1eb138c..8985d30b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ FROM ubuntu:22.04 RUN apt-get update && \ - apt-get install -y && \ - apt-get install python3 -y && \ - apt-get install pip -y && \ - groupadd -g 1234 notroot && \ - useradd -m -u 1234 -g notroot notroot + apt-get install -y \ + python3 -y \ + python3-pip -y && \ + groupadd -g 1234 notroot && \ + useradd -m -u 1234 -g notroot notroot USER notroot WORKDIR /app COPY requirements.txt .