From 2f1668c75a6fe5530c75a859987fa2754fe79657 Mon Sep 17 00:00:00 2001 From: Anil Kumar Vishnoi Date: Thu, 14 Mar 2024 01:47:22 -0700 Subject: [PATCH] Add task for deploying the instruct-lab-bot Signed-off-by: Anil Kumar Vishnoi --- deploy/ansible/deploy-ec2.yml | 1 + deploy/ansible/deploy-lab/tasks/main.yml | 62 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/deploy/ansible/deploy-ec2.yml b/deploy/ansible/deploy-ec2.yml index 9b993b84..87e7e9d9 100644 --- a/deploy/ansible/deploy-ec2.yml +++ b/deploy/ansible/deploy-ec2.yml @@ -12,6 +12,7 @@ git_repo: git@github.com:instruct-lab/cli.git python_venv_path: "{{ ansible_env.HOME }}/venv" app_directory: "{{ ansible_env.HOME }}/cli" + ghbot_directory: "{{ ansible_env.HOME }}/instruct-lab-bot" models_directory: "{{ app_directory }}/models" new_model_path: "models/mistral-7b-instruct-v0.1.Q4_K_M.gguf" roles: diff --git a/deploy/ansible/deploy-lab/tasks/main.yml b/deploy/ansible/deploy-lab/tasks/main.yml index 062284f8..fd2a1805 100644 --- a/deploy/ansible/deploy-lab/tasks/main.yml +++ b/deploy/ansible/deploy-lab/tasks/main.yml @@ -31,6 +31,68 @@ state: present become: yes +- name: Install pm2 using npm + ansible.builtin.npm: + name: pm2 + global: yes + become: yes + +- name: Check if the instruct-lab-bot directory exists + stat: + path: {{ ghbot_directory }}/instruct-lab-bot + register: instruct_lab_bot_dir + +- name: Delete the instruct-lab-bot directory if it exists + file: + path: {{ ghbot_directory }}/instruct-lab-bot + state: absent + when: instruct_lab_bot_dir.stat.exists + +- name: Clone the instruct-lab-bot repository + git: + repo: https://github.com/redhat-et/instruct-lab-bot + dest: {{ ghbot_directory }}/instruct-lab-bot + clone: yes + update: yes + +- name: Install instruct lab bot dependencies + ansible.builtin.shell: | + cd {{ ghbot_directory }} + npm install + args: + executable: /bin/bash + +- name: Setup environment variables for instruct lab bot + ansible.builtin.shell: | + cd {{ ghbot_directory }} + echo "export GITHUB_TOKEN={{ github_token }}" > .env + args: + executable: /bin/bash + +- name: Setup environment variables for instruct lab bot + vars: + env_file_path: {{ ghbot_directory }}/.env + tasks: + - name: Ensure key-value pairs are in .env file + ansible.builtin.lineinfile: + path: "{{ env_file_path }}" + line: "{{ item.key }}={{ item.value }}" + insertafter: EOF + loop: + - { key: "WEBHOOK_PROXY_URL", value: ${{ secrets.WEBHOOK_PROXY_URL }} } + - { key: "APP_ID", value: ${{ secrets.APP_ID }} } + - { key: "PRIVATE_KEY", value: ${{ secrets.PRIVATE_KEY }} } + - { key: "WEBHOOK_SECRET", value: ${{ secrets.WEBHOOK_SECRET }} } + - { key: "GITHUB_CLIENT_ID", value: ${{ secrets.GITHUB_CLIENT_ID }} } + - { key: "GITHUB_CLIENT_SECRET", value: ${{ secrets.GITHUB_CLIENT_SECRET }} } + +- name: Run the instruct lab bot + ansible.builtin.shell: | + cd {{ ghbot_directory }} + pm2 start npm --name "ghbot" -- start + args: + executable: /bin/bash + - name: Check if the cli directory exists stat: path: /home/{{ ansible_user }}/cli