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

Homework/m1 3 ansible #30

Open
wants to merge 7 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
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# devops-programme
# devops-programme

introduced change to test github actions
40 changes: 40 additions & 0 deletions ansDockerPy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
- name: Build Docker container with my Python app
hosts: localhost

vars:
image_name: "pythonapp"
image_tag: "v1"
listen_port: 5000
dockerhub_uname: "dxs01"


tasks:
- 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 }}"

37 changes: 37 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -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 }}"