V2
This commit is contained in:
2
main.yml
2
main.yml
@@ -5,4 +5,4 @@
|
|||||||
build_root_abspath: "/home/dietpi/build/{{ ansible_date_time.iso8601_basic_short }}"
|
build_root_abspath: "/home/dietpi/build/{{ ansible_date_time.iso8601_basic_short }}"
|
||||||
demobackend_version: "latest"
|
demobackend_version: "latest"
|
||||||
roles:
|
roles:
|
||||||
- role: build_fastapi
|
- role: build_fastapi
|
||||||
|
|||||||
54
roles/build_fastapi/tasks/main.yml
Normal file
54
roles/build_fastapi/tasks/main.yml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
- name: show remote host
|
||||||
|
debug:
|
||||||
|
msg: "the remote server is {{ ansible_host }}"
|
||||||
|
- name: create build dir if not exists
|
||||||
|
file:
|
||||||
|
path: "{{ build_root_abspath }}"
|
||||||
|
state: directory
|
||||||
|
- name: git clone
|
||||||
|
git:
|
||||||
|
repo: "https://pvggitea.duckdns.org/GiteaTeam/demo-fastapi.git"
|
||||||
|
dest: "{{ build_root_abspath }}"
|
||||||
|
remote: "origin"
|
||||||
|
version: "main"
|
||||||
|
- name: Create Python virtual environment
|
||||||
|
command:
|
||||||
|
cmd: /usr/bin/python3 -m venv "{{ build_root_abspath }}/venv"
|
||||||
|
creates: "{{ build_root_abspath }}/venv"
|
||||||
|
- name: install fastapi
|
||||||
|
command:
|
||||||
|
cmd: source "{{ build_root_abspath }}/venv/bin/activate"
|
||||||
|
cmd: pip install "fastapi[all]"
|
||||||
|
#- name: Make sure requirements are met to run vmware_guest_snapshot module
|
||||||
|
# become: true
|
||||||
|
# pip:
|
||||||
|
# name: fastapi[all]
|
||||||
|
# state: present
|
||||||
|
- name: hello-world
|
||||||
|
docker_image:
|
||||||
|
name: helloworld-fastapi
|
||||||
|
source: build
|
||||||
|
build:
|
||||||
|
path: "{{ build_root_abspath }}"
|
||||||
|
pull: false
|
||||||
|
tag: "{{ demobackend_version }}"
|
||||||
|
- name: run docker
|
||||||
|
docker_container:
|
||||||
|
name: demobackend
|
||||||
|
state: started
|
||||||
|
recreate: yes
|
||||||
|
image: "helloworld-fastapi:{{ demobackend_version }}"
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
- name: wait for the api ready
|
||||||
|
wait_for:
|
||||||
|
host: 0.0.0.0
|
||||||
|
port: 8080
|
||||||
|
delay: 10
|
||||||
|
- name: testing api locally
|
||||||
|
shell: "curl -k localhost:8080"
|
||||||
|
register: reg_curl_result
|
||||||
|
- name: show curl result
|
||||||
|
debug:
|
||||||
|
msg: "{{ reg_curl_result.stdout }}"
|
||||||
Reference in New Issue
Block a user