Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple script to install binaries in Ubuntu & Debian #1

Merged
merged 10 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Run Molecule

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
molecule:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: "${{ github.repository }}"
- uses: gofrolist/molecule-action@v2
28 changes: 28 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Run PreCommit

on:
push
jobs:
pre-commit:
if: github.event.pull_request.draft == false
name: pre-commit checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Refresh source list
run: |
sudo apt update
- name: Install precommit
run: |
python -m pip install pre-commit
- name: Install hooks
run: |
pre-commit install --install-hooks
- name: Run Pre-Commit
run: >
pre-commit run
--all-files
--show-diff-on-failure
-v
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
repos:
- repo: https://github.com/ansible/ansible-lint
rev: v24.10.0
hooks:
- id: ansible-lint
19 changes: 19 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Ivynet Client installation

The role installs ivynet client binary in an Ubuntu OS.
Additinally it install Docker CE.

## Supported system

The role can be used with:
- Ubuntu LTS (22.04, 22.04)
- Debian (12)

### Other

Ivynet client should work with any Linux distribution (which has with libssl3 and libcrypto libraries).
The role works only with deb package, because of docker installation from the apt repository.

## Testing

Simple molecule check that the binaries are installed.
12 changes: 12 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# The name of the bucket to download file from
ivynet_client_bucket: "https://storage.googleapis.com/ivynet-share"

# Where to save the file
ivynet_client_install_path: "/opt/ivynet"

# Version of the file
ivynet_client_version: "0.3.0"

# Name of the file
ivynet_client_file: "ivynet"
25 changes: 25 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
galaxy_info:
role_name: ivynet_client
namespace: ivynet
author: Wawrzek Niewodniczański
description: Install IvyNet Client (and Docker CE)
company: "IvyNet"
license: Apache-2.0
min_ansible_version: "2.17"
platforms:
- name: Debian
versions:
- bookworm
- name: Ubuntu
versions:
- noble
- jammy
galaxy_tags:
- blockchain
- ethereum
- web3
- monitoring
- observability

dependencies: []
22 changes: 22 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Used to be Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y gpg python3-debian sudo bash ca-certificates iproute2 && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3 sudo python3-devel python3-dnf bash iproute && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi
6 changes: 6 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
gather_facts: true
roles:
- role: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
26 changes: 26 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint
flake8
platforms:
- name: ubuntu24.04
image: ubuntu:noble
- name: ubuntu22.04
image: ubuntu:jammy
- name: debian12
image: debian:bookworm
provisioner:
name: ansible
playbooks:
converge: converge.yml
config_options:
defaults:
fact_caching: jsonfile
fact_caching_connection: /tmp/ansible_fact_cache
fact_caching_timeout: 86400
verifier:
name: ansible
4 changes: 4 additions & 0 deletions molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
collections:
- name: community.docker
version: ">=3.10.2"
20 changes: 20 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Verify
hosts: all
vars:
ivynet_client_path: /opt/ivynet/bin/ivynet
tasks:
- name: Get file stats
ansible.builtin.stat:
path: "{{ ivynet_client_path }}"
register:
ivynet_bin
- name: Show
ansible.builtin.debug:
msg: "{{ ivynet_bin }}"
- name: Assert the file is download
ansible.builtin.assert:
that:
- ivynet_bin.stat.isreg is defined
- ivynet_bin.stat.isreg == True
- ivynet_bin.stat.size > 2**20
42 changes: 42 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: Prepare directories
ansible.builtin.file:
path: "{{ ivynet_client_install_path }}/{{ item }}"
state: directory
owner: root
group: root
mode: "0755"
loop:
- ''
- bin
- resources
tags:
- ivynet_client

- name: Download third party tools (docker, gcloud)
ansible.builtin.import_tasks:
file: third_party.yml

- name: Download ivynet-cli
ansible.builtin.get_url:
# yamllint disable-line rule:line-length
url: "{{ ivynet_client_bucket }}/{{ ivynet_client_file }}-{{ ivynet_client_version }}"
# yamllint disable-line rule:line-length
checksum: "sha256:{{ ivynet_client_bucket }}/{{ ivynet_client_file }}-{{ ivynet_client_version }}.sha256"
dest: "{{ ivynet_client_install_path }}/bin/{{ ivynet_client_file }}"
owner: root
group: root
mode: "0755"
tags:
- ivynet_client
- download

- name: Add ivynet bin dir to system-wide $PATH.
ansible.builtin.copy:
dest: /etc/profile.d/ivy-path.sh
content: "PATH=$PATH:{{ ivynet_client_install_path }}/bin"
owner: root
group: root
mode: "0644"
tags:
- ivynet_client
30 changes: 30 additions & 0 deletions tasks/third_party.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Add Docker Module Repository
ansible.builtin.deb822_repository:
name: docker
types: [deb]
uris: "https://download.docker.com/linux/{{ ansible_distribution | lower }}"
# yamllint disable-line rule:line-length
signed_by: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
suites: ["{{ ansible_distribution_release | lower }}"]
components: [stable]
state: present
enabled: true
tags:
- ivynet_client
- docker

- name: Install packages (for docker and google)
ansible.builtin.apt:
name: "{{ item }}"
update_cache: true
loop:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
tags:
- ivynet_client
- docker
- download