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

feat: add softwares for cloud-data #10

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
25 changes: 25 additions & 0 deletions .github/workflows/update-softwares.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
schedule:
- cron: '15 */1 * * *'

jobs:
update-softwares:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8 🐍
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies 📦
run: |
pip install -r cloud-data/requirements.txt
- run: python -m cloud-data.importer
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: '🤖 Update softwares'
add: 'softwares/*'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
scripts/vendor
/repositories
/temp_repositories
*.pyc
.DS_Store
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Copyright (c) 2018-2021 Presidenza del Consiglio dei Ministri
Copyright (c) 2018-2022 Presidenza del Consiglio dei Ministri

The version control system provides attribution for specific lines of code.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ build.

## License

Copyright (c) 2018-2021 - Presidenza del Consiglio dei Ministri
Copyright (c) 2018-2022 - Presidenza del Consiglio dei Ministri

The source code is released under the BSD license (SPDX code: `BSD-3-Clause`).
80 changes: 80 additions & 0 deletions cloud-data/importer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import pathlib
import shutil
import yaml
import json
from github import Github
from git import Repo


REPO_FOLDER = "repositories"
TEMP_REPO_FOLDER = "temp_repositories"
SOFTWARES_FOLDER = "softwares"

pathlib.Path(REPO_FOLDER).mkdir(parents=True, exist_ok=True)

github_client = Github(os.environ.get("GH_ACCESS_TOKEN"))


def _write_json_file(software_name, payload):
dest = os.path.join(SOFTWARES_FOLDER, f"{software_name}.json")
with open(dest, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False, indent=4)


def _get_data_from_software(base_directory, software, provider, softwares):
desc_yml_path = os.path.join(base_directory, "desc.yml")
if os.path.isfile(desc_yml_path):
if software not in softwares:
softwares[software] = {}
softwares[software]["providers"] = {}
if provider not in softwares[software]["providers"]:
softwares[software]["providers"][provider] = {}
with open(desc_yml_path, "r") as stream:
try:
yaml_data = yaml.safe_load(stream)
softwares[software]["providers"][provider] = yaml_data[
"deployment_option"
]
except yaml.YAMLError as exc:
print(exc)


def fetch_providers():
softwares = {}
if os.path.exists(TEMP_REPO_FOLDER):
shutil.rmtree(TEMP_REPO_FOLDER)
if os.path.exists(SOFTWARES_FOLDER):
shutil.rmtree(SOFTWARES_FOLDER)
pathlib.Path(TEMP_REPO_FOLDER).mkdir(parents=True, exist_ok=True)
pathlib.Path(SOFTWARES_FOLDER).mkdir(parents=True, exist_ok=True)
for repo in github_client.search_repositories("org:w0rkb3nch"):
if repo.name.startswith("cloud-"):
print(f"🗃 Cloning {repo.clone_url}..", end="")
software_direcotry = os.path.join(REPO_FOLDER, repo.name)
temp_software_directory = os.path.join(TEMP_REPO_FOLDER, repo.name)
Repo.clone_from(repo.clone_url, temp_software_directory)
shutil.rmtree(os.path.join(temp_software_directory, ".git"))
shutil.copytree(
temp_software_directory, software_direcotry, dirs_exist_ok=True
)
print("Done!")
print(f"📃 Fetching data from {repo.name}..", end="")
for software in os.listdir(software_direcotry):
_get_data_from_software(
os.path.join(software_direcotry, software),
software,
repo.name,
softwares,
)
print("Done!")

softwares_collection = []
for software_name, software_data in softwares.items():
software = {"slug": software_name, **software_data}
_write_json_file(software_name, software)
softwares_collection.append(software)
_write_json_file("all", softwares_collection)


fetch_providers()
3 changes: 3 additions & 0 deletions cloud-data/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PyGithub==1.55
GitPython==3.1.27
PyYAML==6.0
151 changes: 151 additions & 0 deletions softwares/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[
{
"slug": "m_it-vvfosprojects-sovvf",
"providers": {
"cloud-general": {
"single_tier": {
"generic_description": {
"en": "My role included **supervising** the marketing team and leading **publicity**.\n",
"it": "### Template Single Tier\nPuoi eseguire la soluzione {{include.page.publiccode.name}} in base al consumo, avviandola e interrompendola a livello di codice. Questa soluzione è preconfigurata e pronta per l'uso su una qualsiasi delle piattaforme seguenti.\n- Distribuisci rapidamente le tue applicazioni nel cloud e rendile disponibili online\n- Pagamento a consumo, paghi solo per le risorse che utilizzi\n"
},
"launch_description": {
"en": "My role included **supervising** the marketing team and leading **publicity**.\n",
"it": "### Lancia un template Single Tier\nScegli una piattaforma tra quelle proposte per lanciare un template Single Tier che si adatti alle tue esigenze.\n"
},
"links": [
{
"title": {
"en": "Link 1",
"it": "Collegamento 1"
},
"url": "/it/piattaforme"
}
]
},
"multi_tier": {
"generic_description": {
"en": "My role included **supervising** the marketing team and leading **publicity**.\n",
"it": "Il mio ruolo includeva la **supervisione** del team di marketing e la guida della **pubblicità**.\n"
},
"launch_description": {
"en": "My role included **supervising** the marketing team and leading **publicity**.\n",
"it": "Il mio ruolo includeva la **supervisione** del team di marketing e la guida della **pubblicità**.\n"
},
"links": [
{
"title": {
"en": "Link 1",
"it": "Collegamento 1"
},
"url": "/it/piattaforme"
}
]
},
"docker": {
"generic_description": {
"en": "My role included **supervising** the marketing team and leading **publicity**.\n",
"it": "Il mio ruolo includeva la **supervisione** del team di marketing e la guida della **pubblicità**.\n"
},
"launch_description": {
"en": "My role included **supervising** the marketing team and leading **publicity**.\n",
"it": "Il mio ruolo includeva la **supervisione** del team di marketing e la guida della **pubblicità**.\n"
},
"links": [
{
"title": {
"en": "Link 1",
"it": "Collegamento 1"
},
"url": "/it/piattaforme"
}
]
}
},
"cloud-amazon": {
"single_tier": {
"solution_name": "AWS",
"deploy_url": "https://www.vigilfuoco.it/",
"demo": "https://gitlab.it",
"op_level": 4
},
"multi_tier": {
"solution_name": "AWS",
"deploy_url": "https://www.vigilfuoco.it/",
"demo": "https://www.vigilfuoco.it/",
"op_level": 4
}
},
"cloud-local": {
"docker": {
"command": "docker-compose up"
}
},
"cloud-google": {
"single_tier": {
"solution_name": "Google Cloud",
"deploy_url": "https://vvff.it",
"demo": "https://vvff.it",
"op_level": 4
},
"multi_tier": {
"solution_name": "Google Cloud",
"deploy_url": "https://vvff.it",
"demo": "https://vvff.it",
"op_level": 4
}
}
}
},
{
"slug": "gitlab",
"providers": {
"cloud-amazon": {
"single_tier": {
"deploy_url": "https://gitlab.it",
"demo": "https://gitlab.it",
"monthly_cost": "5 dollars",
"op_level": 4
},
"multi_tier": {
"deploy_url": "https://gitlab.com",
"demo": "https://gitlab.com",
"monthly_cost": "3 dollars",
"op_level": 4
}
}
}
},
{
"slug": "sigla",
"providers": {
"cloud-amazon": {
"single_tier": {
"deploy_url": "https://developersitalia.it",
"demo": "https://developersitalia.it",
"monthly_cost": "35 dollars",
"op_level": 2
},
"multi_tier": {
"deploy_url": "https://amazon.com",
"demo": "https://amazon.com",
"monthly_cost": "15 dollars",
"op_level": 2
}
},
"cloud-google": {
"single_tier": {
"deploy_url": "https://developersitalia.it",
"demo": "https://developersitalia.it",
"monthly_cost": "32 dollars",
"op_level": 2
},
"multi_tier": {
"deploy_url": "https://google.com",
"demo": "https://google.com",
"monthly_cost": "12 dollars",
"op_level": 5
}
}
}
}
]
19 changes: 19 additions & 0 deletions softwares/gitlab.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"slug": "gitlab",
"providers": {
"cloud-amazon": {
"single_tier": {
"deploy_url": "https://gitlab.it",
"demo": "https://gitlab.it",
"monthly_cost": "5 dollars",
"op_level": 4
},
"multi_tier": {
"deploy_url": "https://gitlab.com",
"demo": "https://gitlab.com",
"monthly_cost": "3 dollars",
"op_level": 4
}
}
}
}
Loading