Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.8
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:22.04

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3 \
python3-pip \
curl \
&& mkdir /app \
&& useradd -d /app app-user \
&& chown --recursive app-user /app

COPY app/requirements.txt /app/requirements.txt
RUN pip3 install -r app/requirements.txt

COPY app/app.py /app
WORKDIR /app

EXPOSE 5000

USER app-user

CMD [ "python3", "app.py" ]
49 changes: 49 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
- hosts: localhost
become: no

vars:
image_name: "mlutzkan/test-python-app"
image_tag: "v0.2"
application_directory: "/tmp/app"

tasks:
- name: Create {{ application_directory }} directory
file:
name: "{{ application_directory }}"
state: directory
mode: 0755

- name: Checkout repository
git:
repo: [email protected]:lutzkanov/devops-programme
dest: "{{ application_directory }}"
version: lutzkanov_docker_1
update: yes

- name: Build Docker image
docker_image:
build:
path: "{{ application_directory }}"
name: "{{ image_name }}"
tag: "{{ image_tag }}"
push: true
source: build
docker_host: "unix:///var/run/docker.sock"
state: present

- name: Run the built Docker image
docker_container:
name: "python-web"
image: "{{ image_name }}:{{ image_tag }}"
state: started
auto_remove: yes
ports:
- "5001:5001"
env:
PORT: "5001"
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:5001"]
interval: 10s
retries: 3
start_period: 5s
docker_host: "unix:///var/run/docker.sock"
14 changes: 14 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -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", 5000), host="0.0.0.0")
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ansible==10.3.0
ansible-compat==24.9.1
ansible-core==2.17.5
ansible-lint==24.9.2
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"