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 ae1daf88d06f2d900bc1b650f9966192246e661b Mon Sep 17 00:00:00 2001 From: Iliyan Vutov Date: Wed, 23 Oct 2024 19:23:42 +0300 Subject: [PATCH 02/10] Add requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..047e9501a --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask==3.0.0 From 63b2492b829944f58a8ffd2e2a5d7d8295b72f8e Mon Sep 17 00:00:00 2001 From: Iliyan Vutov Date: Wed, 23 Oct 2024 19:24:30 +0300 Subject: [PATCH 03/10] Add requirements.txt --- requirements.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 047e9501a..b5ba78cca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,9 @@ -Flask==3.0.0 +blinker==1.6.3 ; python_version >= "3.10" and python_version < "4.0" +click==8.1.7 ; python_version >= "3.10" and python_version < "4.0" +colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows" +flask==3.0.0 ; python_version >= "3.10" and python_version < "4.0" +itsdangerous==2.1.2 ; python_version >= "3.10" and python_version < "4.0" +jinja2==3.1.2 ; python_version >= "3.10" and python_version < "4.0" +markupsafe==2.1.3 ; python_version >= "3.10" and python_version < "4.0" +werkzeug==3.0.0 ; python_version >= "3.10" and python_version < "4.0" + From 0c3ce3f930bdcdd9b1a8ae0e035afdc3a0666024 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Oct 2024 19:51:39 +0300 Subject: [PATCH 04/10] re-adding text file to my forked branch from OG repo --- dockerfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 dockerfile diff --git a/dockerfile b/dockerfile new file mode 100644 index 000000000..fac87a9de --- /dev/null +++ b/dockerfile @@ -0,0 +1,5 @@ +FROM ubuntu:24.04 +WORKDIR /ap +COPY requirements.txt ./ + + From bbdc9ee11ddb4190852a066f3fead2a51e001937 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Oct 2024 20:23:13 +0300 Subject: [PATCH 05/10] Dockerfile edited. --- dockerfile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dockerfile b/dockerfile index fac87a9de..e590a48ec 100644 --- a/dockerfile +++ b/dockerfile @@ -1,5 +1,18 @@ FROM ubuntu:24.04 -WORKDIR /ap +WORKDIR /app COPY requirements.txt ./ +RUN apt-get update && \ +apt-get upgrade -y && \ +apt-get install -y \ +python3\ +python-pip +COPY app/ /app + + + +COPY requirements.txt +RUN pip install --break-system-packages -r requirements.txt + +CMD ["python3" , "-m" ,"flask" , "run" , "--host=0.0.0.0" ] From d7c12fb79ef6982c455aa5ba694aa30aafb0d44b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Oct 2024 20:49:56 +0300 Subject: [PATCH 06/10] final updates; docker image configured and tested --- dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dockerfile b/dockerfile index e590a48ec..d5f4d93b8 100644 --- a/dockerfile +++ b/dockerfile @@ -5,14 +5,14 @@ COPY requirements.txt ./ RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y \ -python3\ -python-pip +python3 \ +python3-pip COPY app/ /app -COPY requirements.txt +COPY requirements.txt ./ RUN pip install --break-system-packages -r requirements.txt - +# EXPOSE 5000 CMD ["python3" , "-m" ,"flask" , "run" , "--host=0.0.0.0" ] From 5762d2bcfd707f2ed087d25b777def2f77272898 Mon Sep 17 00:00:00 2001 From: Atanas Petrov Date: Wed, 23 Oct 2024 21:16:32 +0300 Subject: [PATCH 07/10] User added to dockerfile --- dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dockerfile b/dockerfile index d5f4d93b8..96f47f05c 100644 --- a/dockerfile +++ b/dockerfile @@ -1,18 +1,20 @@ FROM ubuntu:24.04 WORKDIR /app -COPY requirements.txt ./ +COPY --chown=user1 requirements.txt ./ -RUN apt-get update && \ +# no need to have " / " + +RUN useradd user1 +apt-get update && \ apt-get upgrade -y && \ apt-get install -y \ python3 \ python3-pip -COPY app/ /app +RUN pip install --break-system-packages -r requirements.txt +COPY --chown=user1 app/ /app -COPY requirements.txt ./ -RUN pip install --break-system-packages -r requirements.txt # EXPOSE 5000 CMD ["python3" , "-m" ,"flask" , "run" , "--host=0.0.0.0" ] From bee0c3ba5b76b23423f998b30e288faa2b7d5644 Mon Sep 17 00:00:00 2001 From: Atanas Petrov Date: Fri, 1 Nov 2024 19:24:42 +0200 Subject: [PATCH 08/10] Initial commit with empty ansible playbook --- ansDockerPy.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ansDockerPy.yml diff --git a/ansDockerPy.yml b/ansDockerPy.yml new file mode 100644 index 000000000..645febb06 --- /dev/null +++ b/ansDockerPy.yml @@ -0,0 +1,7 @@ +--- +- name: Build Docker container with my Python app + hosts: localhost + become: yes + + tasks: + -name: From b51146f8c71e857c7e4c4b94f746092cbbb3fb18 Mon Sep 17 00:00:00 2001 From: Atanas Petrov Date: Sun, 3 Nov 2024 13:53:18 +0200 Subject: [PATCH 09/10] ansDockerPy.yml is the main file, initial issues with sources were resolved and Dockerfile was checked as well. var for docker username was added, however currently it is set to static. may include in inventory or secrets file (vault file) instead (?) --- Dockerfile | 20 ++++++++++++++++++++ ansDockerPy.yml | 37 +++++++++++++++++++++++++++++++++++-- dockerfile | 20 -------------------- test.yml | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 Dockerfile delete mode 100644 dockerfile create mode 100644 test.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..40833b198 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:22.04 +WORKDIR /app +COPY --chown=user1 requirements.txt ./ + +# no need to have " / " + +RUN useradd user1 && \ + apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y \ + python3 \ + python3-pip + + +RUN pip3 install --no-cache-dir -r requirements.txt + +COPY --chown=user1 app/ /app + +# EXPOSE 5000 +CMD ["python3" , "-m" ,"flask" , "run" , "--host=0.0.0.0" ] diff --git a/ansDockerPy.yml b/ansDockerPy.yml index 645febb06..4e0e5516d 100644 --- a/ansDockerPy.yml +++ b/ansDockerPy.yml @@ -1,7 +1,40 @@ --- - name: Build Docker container with my Python app hosts: localhost - become: yes + vars: + image_name: "pythonapp" + image_tag: "v1" + listen_port: 5000 + dockerhub_uname: "dxs01" + + tasks: - -name: + - name: build docker image + docker_image: + name: "{{ image_name }}" + tag: "{{ image_tag }}" + source: build + build: + path: "." + state: present + + - name: Dockerhub login + shell: docker login + + - name: push docker image + docker_image: + name: "{{ image_name }}" + repository: "{{ dockerhub_uname }}/{{ image_name }}" + tag: "{{ image_tag }}" + push: yes + source: local + state: present + - name: run docker image + docker_container: + detach: yes + name: old_excercise_python_app + image: "{{ image_name }}:{{ image_tag }}" + state: started + published_ports: "{{ listen_port }}:{{ listen_port }}" + diff --git a/dockerfile b/dockerfile deleted file mode 100644 index 96f47f05c..000000000 --- a/dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM ubuntu:24.04 -WORKDIR /app -COPY --chown=user1 requirements.txt ./ - -# no need to have " / " - -RUN useradd user1 -apt-get update && \ -apt-get upgrade -y && \ -apt-get install -y \ -python3 \ -python3-pip - - -RUN pip install --break-system-packages -r requirements.txt - -COPY --chown=user1 app/ /app - -# EXPOSE 5000 -CMD ["python3" , "-m" ,"flask" , "run" , "--host=0.0.0.0" ] diff --git a/test.yml b/test.yml new file mode 100644 index 000000000..ce810eaa4 --- /dev/null +++ b/test.yml @@ -0,0 +1,37 @@ +--- +- name: Build, Push and Run Docker Image for Python Application + hosts: localhost + vars: + image_name: "dxs01/python-app" # Change this to your Docker Hub username and app name + image_tag: "v0.2" + listen_port: 5000 + docker_socket: "unix://{{ ansible_env.HOME }}/.docker/run/docker.sock" # Change path if using Rancher Desktop + + tasks: + - name: Ensure Docker is installed + ansible.builtin.command: docker --version + register: docker_installed + changed_when: false + + - name: Build Docker Image + community.docker.docker_image: + name: "{{ image_name }}" + tag: "{{ image_tag }}" + path: "{{ playbook_dir }}" + state: present + + - name: Push Docker Image to Docker Hub + community.docker.docker_image: + name: "{{ image_name }}" + tag: "{{ image_tag }}" + push: true + + - name: Run Docker Container + community.docker.docker_container: + name: python_app_container + image: "{{ image_name }}:{{ image_tag }}" + state: started + published_ports: + - "{{ listen_port }}:{{ listen_port }}" + env: + PORT: "{{ listen_port }}" From ed61c7e3bc267d97ff88db42f71e1d5ebb3b25ba Mon Sep 17 00:00:00 2001 From: Atanas Petrov Date: Wed, 6 Nov 2024 15:44:30 +0200 Subject: [PATCH 10/10] Edited readme to test github actions --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d19dfd95a..54292b8a8 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# devops-programme \ No newline at end of file +# devops-programme + +introduced change to test github actions