Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Martin Lutzkanov - Docker exercise 1 #25

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
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"
2 changes: 1 addition & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +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"

werkzeug==3.0.0 ; python_version >= "3.10" and python_version < "4.0"