demo-app/deploy/deploy.yml

71 lines
2.1 KiB
YAML
Raw Permalink Normal View History

---
# App ko VM par deploy karo. Idempotent hai - baar baar chalao, wahi nateeja.
- name: Deploy demo-app to VM
hosts: "{{ target | default('production') }}"
gather_facts: true
vars:
registry: "ns31240276.ip-51-195-4.eu:5000"
image_name: "swim/demo-app"
image_tag: "{{ lookup('env', 'IMAGE_TAG') | default('latest', true) }}"
container_name: "demo-app"
app_port: 8000
tasks:
- name: Registry me login
community.docker.docker_login:
registry_url: "{{ registry }}"
username: "{{ lookup('env', 'REG_USER') }}"
password: "{{ lookup('env', 'REG_PASS') }}"
no_log: true
- name: Nayi image pull karo
community.docker.docker_image:
name: "{{ registry }}/{{ image_name }}"
tag: "{{ image_tag }}"
source: pull
force_source: true
- name: Container chalao (purana apne aap replace hoga)
community.docker.docker_container:
name: "{{ container_name }}"
image: "{{ registry }}/{{ image_name }}:{{ image_tag }}"
state: started
restart_policy: unless-stopped
recreate: true
published_ports:
- "{{ app_port }}:8000"
env:
APP_VERSION: "{{ image_tag }}"
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://127.0.0.1:8000/health')"]
interval: 30s
timeout: 3s
retries: 3
- name: App ke healthy hone ka wait
ansible.builtin.uri:
url: "http://127.0.0.1:{{ app_port }}/health"
status_code: 200
register: health
retries: 12
delay: 5
until: health.status == 200
- name: Deploy hui version verify karo
ansible.builtin.uri:
url: "http://127.0.0.1:{{ app_port }}/version"
return_content: true
register: ver
- name: Nateeja dikhao
ansible.builtin.debug:
msg: "DEPLOYED -> {{ ver.json }}"
- name: Purani images saaf karo
community.docker.docker_prune:
images: true
images_filters:
dangling: false
until: 24h