Skip to content

Commit

Permalink
Merge pull request #61 from Constellation-Labs/feature/adding-custom-…
Browse files Browse the repository at this point in the history
…playbooks-local-execution

Adding custom Dockerfile to metagraph-base-image
  • Loading branch information
IPadawans authored Jul 30, 2024
2 parents a5ad7bb + 31ed781 commit 0534afa
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 277 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ This directory contains infrastructure related to the running of Euclid.
- **local**: Used for start and stop the nodes locally.
- **remote**: Used for configuring and deploying to remote hosts

#### Custom Metagraph Base Image Dockerfile
You can customize your `metagraph-base-image` Dockerfile by creating a new file called `Dockerfile` under the `infra/docker/custom/metagraph-base-image` directory. This allows the build process to load and use your custom Dockerfile, enabling you to add additional features, such as external databases or tools.

This customization feature allows you to tailor your base image to include the specific features you require. Ensure that your custom Dockerfile continues to meet the primary goals of the original file: creating directories, building JARs, and moving the necessary files for execution, such as `genesis.snapshot`.

### Scripts
Thats the "home" of hydra script, here you'll find the `hydra` and `hydra-update (deprecated)` scripts.

Expand Down
46 changes: 46 additions & 0 deletions infra/ansible/local/playbooks/destroy/containers/nodes.ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- name: Destroy Containers and Network
hosts: localhost
vars:
nodes: "{{ nodes | from_json }}"
infra_path: "{{ infra_path }}"

tasks:
- name: Destroy Containers
block:
- name: Destroy Containers
docker_container:
name: "{{ item.name }}"
state: absent
loop: "{{ nodes }}"
loop_control:
label: "{{ item.name }}"

- name: Destroy Container Grafana
block:
- name: Destroy container grafana
docker_container:
name: grafana
state: absent

- name: Destroy Container Prometheus
block:
- name: Destroy container prometheus
docker_container:
name: prometheus
state: absent

- name: Remove Genesis Files
file:
path: "{{ item }}"
state: absent
loop:
- "{{ infra_path }}/docker/shared/genesis/genesis.address"
- "{{ infra_path }}/docker/shared/genesis/genesis.snapshot"

- name: Destroy Network custom-network
block:
- name: Remove network custom-network
docker_network:
name: custom-network
state: absent

This file was deleted.

48 changes: 45 additions & 3 deletions infra/ansible/local/playbooks/start/containers/nodes.ansible.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
---
- name: Install dependencies
hosts: localhost
connection: local
vars_files:
- ../../vars.ansible.yml
tasks:
- name: Check if pip3 is installed
shell: command -v pip3
register: pip3_installed
ignore_errors: yes
changed_when: false

- name: Install pip3 on Debian/Ubuntu
apt:
name: python3-pip
state: present
when:
- ansible_os_family == "Debian"
- pip3_installed.rc != 0
become: true

- name: Install pip3 on macOS
homebrew:
name: python3
state: present
when:
- ansible_os_family == "Darwin"
- pip3_installed.rc != 0
become: no

- name: Install requests module
pip:
name: requests
state: present

- name: Check if community.docker collection is installed
stat:
path: "$HOME/.ansible/collections/ansible_collections/community/docker"
register: collection_status

- name: Install community.docker collection if not installed
ansible.builtin.command:
cmd: ansible-galaxy collection install community.docker --force
when: not collection_status.stat.exists

- name: Start Docker containers
hosts: localhost
connection: local
Expand All @@ -8,9 +53,6 @@
- name: Get all nodes from euclid.json
set_fact:
all_nodes: "{{ lookup('env', 'NODES') }}"

- name: Install dependencies
include_tasks: dependencies.ansible.yml

- name: Create custom network
docker_network:
Expand Down
11 changes: 11 additions & 0 deletions infra/ansible/local/playbooks/start/global-l0/genesis.ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
cl_cli_http_port: "{{ (base_global_l0_cli_port | int ) }}"
node_ip: "{{ base_prefix_ip }}{{ offset }}"

- name: (Global L0) Cleaning older directories if exists
community.docker.docker_container_exec:
container: "{{ node_info.name }}"
command: |
/bin/bash -c '
cd global-l0 &&
if [ -d "data" ]; then rm -r data; fi &&
if [ -d "logs" ]; then rm -r logs; fi
'
when: force_genesis_bool

- name: (Global L0) Start Global L0 - Genesis
community.docker.docker_container_exec:
container: "{{ node_info.name }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
lead_node_ip: "{{ base_prefix_ip }}{{ offset }}"
gl0_lead_node_public_port: "{{ base_global_l0_public_port | int }}"

- name: (Metagraph-L0) Cleaning older directories if exists
community.docker.docker_container_exec:
container: "{{ node_info.name }}"
command: |
/bin/bash -c '
cd metagraph-l0 &&
if [ -d "data" ]; then rm -r data; fi &&
if [ -d "logs" ]; then rm -r logs; fi
'
- name: (Metagraph-L0) Create genesis files
community.docker.docker_container_exec:
container: "{{ node_info.name }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
tasks:
- name: (Monitoring) Stopping monitoring
shell: |
cd {{ lookup('env', 'INFRA_PATH') }}/docker/monitoring
cd {{ lookup('env', 'INFRA_PATH') }}/docker/grafana
{{ lookup('env', 'DOCKER_COMPOSE') }} down
33 changes: 33 additions & 0 deletions infra/ansible/local/playbooks/stop/containers/nodes.ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Stop Containers
hosts: localhost
vars:
nodes: "{{ nodes | from_json }}"
infra_path: "{{ infra_path }}"

tasks:
- name: Stop Nodes
block:
- name: Stop Nodes
docker_container:
name: "{{ item.name }}"
state: stopped
loop: "{{ nodes }}"
loop_control:
label: "{{ item.name }}"

- name: Stop Container Grafana
block:
- name: Stop container grafana
docker_container:
name: grafana
state: stopped
ignore_errors: true

- name: Stop Container Prometheus
block:
- name: Stop container prometheus
docker_container:
name: prometheus
state: stopped
ignore_errors: true
Empty file.
2 changes: 1 addition & 1 deletion infra/docker/metagraph-base-image/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ services:
image: "metagraph-base-image"
build:
context: ../../../source
dockerfile: ../infra/docker/metagraph-base-image/Dockerfile
dockerfile: ${METAGRAPH_BASE_IMAGE_DOCKERFILE}
Loading

0 comments on commit 0534afa

Please sign in to comment.