Skip to content

Instantly share code, notes, and snippets.

View fabidick22's full-sized avatar
🦖
Working from home

Dickson A. fabidick22

🦖
Working from home
View GitHub Profile
from tabulate import tabulate
def get_fargate_spot_cost(region, vcpu_cost=None, gb_cost=None):
"""
If vcpu_cost and vcpu_cost are 'None', the current value is retrived from AWS
"""
import requests
endpoint = "https://dftu77xade0tc.cloudfront.net/fargate-spot-prices.json"
try:
if vcpu_cost is not None and gb_cost is not None:
vcpu_used_by_instance = 1 # Resource used by sh-runner-small-teamS-ruby
gb_used_by_instance = 4 # Resource used by sh-runner-small-teamS-ruby
vcpu_hourly_rate = 0.04048 # Cost per vCPU hour
gb_hourly_rate = 0.004445 # Cost per GB-hour of RAM
workflow_executions = 150 # Number of monthly executions
jobs_per_execution = 30 # Number of jobs per execution
job_duration_hours = 0.0667 # Duration of each job in hours (4 min)
start_time_hours = 0.0333 # Start time in hours (2 min)
optimization_percentage = 0.72 # Start time optimization percentage
hourly_cost_fargate_instance = (vcpu_hourly_rate * vcpu) + (gb_hourly_rate * gb)
import plotly.graph_objects as go
import sqlite3
conn = sqlite3.connect('ecs_data_v1.sqlite')
conn_v2 = sqlite3.connect('ecs_data_v2.sqlite')
cursor = conn.cursor()
cursor_v2 = conn_v2.cursor()
import boto3
import sqlite3
from datetime import datetime
from dateutil import tz
CLUSTER = 'sh-runners'
REGION = 'us-east-1'
ecs_client = boto3.client('ecs', region_name=REGION)
name: SOCI
on: [push]
env:
NERDCTL_VERSION: "1.6.2"
SOCI_VERSION: "0.4.0"
jobs:
build-push:
name: Build and push image
runs-on: ubuntu-latest
steps:
export AWS_REGION=us-east-1
export REGISTRY_USER=AWS
export REGISTRY_PASSWORD=$(aws ecr get-login-password --region $AWS_REGION)
export REGISTRY=000000000000.dkr.ecr.$AWS_REGION.amazonaws.com
# needed the SOCI snapshotter which runs as root
echo $REGISTRY_PASSWORD | sudo nerdctl login -u $REGISTRY_USER --password-stdin $REGISTRY
# Pull and push image
sudo nerdctl pull docker.io/library/rabbitmq:latest
@fabidick22
fabidick22 / docsAsCode.md
Last active August 26, 2022 14:20
Documentation as code - state of the art

Free Tools

Terraform

  • terraform-docs:
    1. Generate documentation from Terraform modules in various output formats.
    2. Can be imported in your project as a library (Go).
    3. GitHub Actions available (terraform-docs/gh-actions@main)
  • mkdocs-terraform-monorepo-plugin
    1. This plugin enables you to build multiple sets of documentation in a single Mkdocs
@fabidick22
fabidick22 / CROSSCLOUD.md
Last active August 5, 2022 05:23
Cross-Cloud Tools

Cross-Cloud Uniform Infra Automation

Hybrid Cloud

  1. K8s, MicroK8s and Netmaker
Type Limitation Solution
Etcd It is the brain of your cluster and is not latency tolerant. MicroK8s
Networking Nodes need to be able to talk to each other directly and securely. Netmaker
Latency High latency is unacceptable for enterprise applications. Netmaker
@fabidick22
fabidick22 / gh-runner-token.py
Last active May 27, 2022 18:49
Script to get a github actions runner token (no dependencies)
#!/usr/bin/env python3
import urllib.request
import urllib.parse as req_parse
import os
import json
GITHUB_API = os.getenv("GITHUB_API", "https://api.github.com/{}")
RUNNER_SCOPE = os.getenv("GITHUB_API", "repo")
GITHUB_OWNER = os.getenv("GITHUB_OWNER")
mkdir /home/ubuntu/sobreplanos
aws s3 cp s3://sobreplanos-boilerplate/artifacts/sobreplanos.zip /home/ubuntu/sobreplanos.zip
cd /home/ubuntu/
unzip sobreplanos.zip -d sobreplanos
rm -rf sobreplanos.zip
cd sobreplanos
chown -R ubuntu:ubuntu /home/ubuntu
export PATH="/usr/share/rvm/rubies/ruby-2.6.8/lib/ruby/gems/2.6.0:/usr/share/rvm/gems/ruby-2.6.8@sobreplanos:/usr/share/rvm/gems/ruby-2.6.8@global/bin:/usr/share/rvm/rubies/ruby-2.6.8/bin:/usr/share/rvm/bin:/home/ubuntu/.nvm/versions/node/v14.15.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/sobreplanos/bin:$PATH"
echo "##### INSTALL"
RAILS_ENV=production bundle install