From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- .../containers/text_generation/handlers/main.yml | 29 +++++++ .../containers/text_generation/tasks/main.yml | 89 ++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 roles/services/containers/text_generation/handlers/main.yml create mode 100644 roles/services/containers/text_generation/tasks/main.yml (limited to 'roles/services/containers/text_generation') diff --git a/roles/services/containers/text_generation/handlers/main.yml b/roles/services/containers/text_generation/handlers/main.yml new file mode 100644 index 0000000..7aab823 --- /dev/null +++ b/roles/services/containers/text_generation/handlers/main.yml @@ -0,0 +1,29 @@ +- name: login to docker registry + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_login: + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + registry_url: "{{ docker_registry_url }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + +- name: build text-generation image + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_image: + name: "{{ docker_registry_url }}/{{ docker_registry_username }}/text-generation:latest" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + build: + path: /srv/docker/text-generation/src + source: build + push: yes + force_source: yes + +- name: restart nginx + service: + name: nginx + state: restarted diff --git a/roles/services/containers/text_generation/tasks/main.yml b/roles/services/containers/text_generation/tasks/main.yml new file mode 100644 index 0000000..80988a6 --- /dev/null +++ b/roles/services/containers/text_generation/tasks/main.yml @@ -0,0 +1,89 @@ +- name: set image fact + set_fact: + image: gitea.chudnick.com/sam/text-generation:latest + +- name: set other facts + vars: + array: "{{ image.split('/', 1) }}" + set_fact: + repo_tag: "{{ array.1 }}" + custom_registry: "{{ docker_registry_url + '/' + docker_registry_username }}" + +- name: create text-generation directory + file: + path: "{{ docker_home }}/text-generation" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: create models directory + file: + path: "{{ docker_home }}/text-generation/models" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: clone text-generation repository + notify: + - login to docker registry + - build text-generation image + git: + repo: https://gitea.chudnick.com/sam/text-generation-docker + dest: "{{ docker_home }}/text-generation/src" + +- meta: flush_handlers + +- name: create text-generation network + become: yes + become_user: "{{ docker_username }}" + docker_network: + name: "{{ text_generation_network_name }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + driver: bridge + ipam_config: + - subnet: "{{ text_generation_subnet }}" + gateway: "{{ text_generation_gateway }}" + +- name: create and deploy text-generation container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "text-generation" + hostname: "text-generation" + image: "{{ image }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ text_generation_network_name }}" + ipv4_address: "{{ text_generation_ipv4 }}" + volumes: + - "{{ docker_home }}/text-generation/models:/models" + ports: + - "127.0.0.1:{{ text_generation_external_port }}:7860" + - "127.0.0.1:{{ text_generation_api_port }}:5005" + - "127.0.0.1:{{ text_generation_api_stream_port }}:5000" + command: "--cpu --listen --listen-port 7860 --chat --auto-devices --mlock" + state: 'started' + recreate: yes + restart_policy: unless-stopped + +- name: deploy nginx configuration + notify: restart nginx + template: + src: "{{ text_generation_nginx_config }}" + dest: /etc/nginx/sites-available/text-generation.conf + owner: root + group: root + mode: '0644' + +- name: symlink site + file: + src: /etc/nginx/sites-available/text-generation.conf + dest: /etc/nginx/sites-enabled/text-generation.conf + owner: root + group: root + state: link -- cgit v1.2.3