From 85ba47f19da239b30320d8da8be2ddb132d5b4e4 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Mon, 9 Sep 2024 19:04:05 +0530 Subject: [PATCH] Add playbooks for setting up docker and stack orchestrator --- nitro-contracts-setup/README.md | 4 +- nitro-nodes-setup/README.md | 2 +- stack-orchestrator-setup/.gitignore | 1 + stack-orchestrator-setup/README.md | 1 + stack-orchestrator-setup/setup-docker.yml | 92 +++++++++++++++++++ stack-orchestrator-setup/setup-laconic-so.yml | 47 ++++++++++ 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 stack-orchestrator-setup/.gitignore create mode 100644 stack-orchestrator-setup/README.md create mode 100644 stack-orchestrator-setup/setup-docker.yml create mode 100644 stack-orchestrator-setup/setup-laconic-so.yml diff --git a/nitro-contracts-setup/README.md b/nitro-contracts-setup/README.md index 6a93e05..6e3c95d 100644 --- a/nitro-contracts-setup/README.md +++ b/nitro-contracts-setup/README.md @@ -8,10 +8,10 @@ To get started, follow the [installation](../README.md#installation) guide to se The following commands have to be executed in the [`nitro-contracts-setup`](./) directory: -- Copy the `contract-vars-example.yml` vars file +- Copy the `contract-vars.example.yml` vars file ```bash - cp contract-vars-example.yml contract-vars.yml + cp contract-vars.example.yml contract-vars.yml ``` - Edit [`contract-vars.yml`](./contract-vars.yml) and fill in the following values diff --git a/nitro-nodes-setup/README.md b/nitro-nodes-setup/README.md index 33eb5af..8d86ba9 100644 --- a/nitro-nodes-setup/README.md +++ b/nitro-nodes-setup/README.md @@ -16,7 +16,7 @@ To run the playbook on a remote host: The following commands have to be executed in [`nitro-nodes-setup`](./) directory -- Copy the `nitro-vars-example.yml` vars file +- Copy the `nitro-vars.example.yml` vars file ```bash cp nitro-vars.example.yml nitro-vars.yml diff --git a/stack-orchestrator-setup/.gitignore b/stack-orchestrator-setup/.gitignore new file mode 100644 index 0000000..788482a --- /dev/null +++ b/stack-orchestrator-setup/.gitignore @@ -0,0 +1 @@ +hosts.ini diff --git a/stack-orchestrator-setup/README.md b/stack-orchestrator-setup/README.md new file mode 100644 index 0000000..b50b423 --- /dev/null +++ b/stack-orchestrator-setup/README.md @@ -0,0 +1 @@ +# stack-orchestrator-setup diff --git a/stack-orchestrator-setup/setup-docker.yml b/stack-orchestrator-setup/setup-docker.yml new file mode 100644 index 0000000..fcd770b --- /dev/null +++ b/stack-orchestrator-setup/setup-docker.yml @@ -0,0 +1,92 @@ +- name: Set up Docker + hosts: remote_host + become: yes + vars: + docker_gpg_key_url: "https://download.docker.com/linux/ubuntu/gpg" + docker_gpg_key_path: "/etc/apt/keyrings/docker.asc" + + tasks: + - name: Check if Docker is installed + command: which docker + register: is_docker_present + ignore_errors: yes + + - name: Check if docker is present + debug: + var: "Output of `which docker` is {{ is_docker_present }}" + + - block: + - name: Exit if docker is present + debug: + msg: "Docker already on host, ending play" + - meta: end_play + when: is_docker_present.rc == 0 + + - name: Update apt cache + apt: + update_cache: yes + + - name: Install prerequisites + apt: + name: + - ca-certificates + - curl + state: present + + - name: Ensure keyrings directory exists + file: + path: "/etc/apt/keyrings" + state: directory + mode: '0755' + + - name: Download Docker GPG key + get_url: + url: "{{ docker_gpg_key_url }}" + dest: "{{ docker_gpg_key_path }}" + mode: '0644' + + - name: Get system architecture + shell: dpkg --print-architecture + register: system_arch + + - name: Add Docker repository + apt_repository: + repo: "deb [arch={{ system_arch.stdout }} signed-by={{ docker_gpg_key_path }}] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable" + state: present + filename: docker + + - name: Update apt cache + apt: + update_cache: yes + + - name: Install Docker packages + apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: latest + notify: Restart Docker + + - name: Verify Docker installation by running the hello world image + command: docker run hello-world + register: hello_world_output + ignore_errors: true + + - name: Display hello-world output + debug: + var: hello_world_output.stdout_lines + + - name: Add user to docker group + user: + name: "{{ ansible_user }}" + groups: docker + append: true + + handlers: + - name: Restart Docker + service: + name: docker + state: restarted diff --git a/stack-orchestrator-setup/setup-laconic-so.yml b/stack-orchestrator-setup/setup-laconic-so.yml new file mode 100644 index 0000000..e8e8f67 --- /dev/null +++ b/stack-orchestrator-setup/setup-laconic-so.yml @@ -0,0 +1,47 @@ +- name: Install Docker if it isn't present + import_playbook: setup-docker.yml + +- name: Set up Stack Orchestrator + hosts: remote_host + vars: + + tasks: + - name: Install jq + apt: + name: jq + state: present + update_cache: yes + become: yes + + - name: Ensure that directory ~/bin exists and is writable + file: + path: "{{ ansible_env.HOME }}/bin" + state: directory + mode: '0755' + + - name: Download the laconic-so binary + get_url: + url: https://git.vdb.to/cerc-io/stack-orchestrator/releases/download/latest/laconic-so + dest: "{{ ansible_env.HOME }}/bin/laconic-so" + mode: '0755' + force: yes + + - name: Ensure ~/bin is on the PATH in .zshrc + lineinfile: + path: "{{ ansible_env.HOME }}/.zshrc" + regexp: '^export PATH=.*{{ ansible_env.HOME }}/bin' + line: 'export PATH="{{ ansible_env.HOME }}/bin:$PATH"' + state: present + + - name: Ensure ~/.laconic-so directory exists + file: + path: "{{ ansible_env.HOME }}/.laconic-so" + state: directory + mode: '0755' + + - name: Save the distribution url to ~/.laconic-so directory + copy: + dest: "{{ ansible_env.HOME }}/.laconic-so/config.yml" + content: | + distribution-url: https://git.vdb.to/cerc-io/stack-orchestrator/releases/download/latest/laconic-so + mode: '0644'