Skip to content

Instantly share code, notes, and snippets.

View victorpaulo's full-sized avatar
🏠
Working from home

Victor P. Almeida victorpaulo

🏠
Working from home
View GitHub Profile
@victorpaulo
victorpaulo / kind-with-registry.sh
Created August 12, 2020 14:09
KinD cluster creation
#!/bin/sh
set -o errexit
# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5000'
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "${reg_port}:5000" --name "${reg_name}" \
@victorpaulo
victorpaulo / hpa-ace.yaml
Created August 31, 2019 22:46
Horizontal Pod Autoscale for IBM ACE
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: ace-dev-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-ace-dev-ibm-ace-server-dev
@victorpaulo
victorpaulo / Makefile
Last active August 31, 2019 21:09
Docker Registry Operations
APP=ace-dev
VERSION=v1.0
DOCKER_REGISTRY=registry.local.tld:5000
CURL_DIGEST:=$(shell curl -v --silent -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
-X GET http://$(DOCKER_REGISTRY)/v2/$(APP)/manifests/$(VERSION) 2>&1 | grep Docker-Content-Digest | awk '{print $$3}')
.PHONY: build
build:
docker build --rm -t $(DOCKER_REGISTRY)/$(APP):$(VERSION) .
@victorpaulo
victorpaulo / grafana_dashboard.json
Created August 28, 2019 23:10
Grafana Dashboard
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
@victorpaulo
victorpaulo / prometheus-config.yaml
Last active August 28, 2019 23:01
Prometheus configMap
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-server-conf
labels:
name: prometheus-server-conf
namespace: monitoring
data:
prometheus.rules: |-
groups:
@victorpaulo
victorpaulo / acme_product_microservice.js
Created August 28, 2019 20:54
ACME product microservice for IBM Watson Assistant
'use strict';
const express = require('express');
const Prometheus = require('prom-client')
const client = require('prom-client');
const bodyParser = require('body-parser');
var mongo = require('./mongo.js');
//Prometheus
const counterProductAll = new client.Counter({
@victorpaulo
victorpaulo / bind_k8s_secret_to_env.yaml
Created August 26, 2019 21:59
Helm chart Deployment Example Secret bind to Env
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
# name: {{ template "fullname" . }}
name: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
labels:
draft: {{ default "draft-app" .Values.draft }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
replicas: {{ .Values.replicaCount }}
@victorpaulo
victorpaulo / aws_s3_promises.js
Created August 26, 2019 18:29
AWS S3 library
const AWS = require('aws-sdk');
require('dotenv').config();
module.exports = {
uploadToS3: function (file) {
let s3bucket = new AWS.S3({
accessKeyId: process.env.IAM_USER_KEY,
secretAccessKey: process.env.IAM_USER_SECRET,
Bucket: process.env.BUCKET_NAME,
@victorpaulo
victorpaulo / TextToSpeech_Twilio.js
Last active August 26, 2019 18:07
Text-to-Speech WhatsApp Twilio and AWS
require('dotenv').config();
var AssistantV1 = require('ibm-watson/assistant/v1');
var TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const clientTwilio = require('twilio')(process.env.accountSid, process.env.authToken);
const express = require('express');
const bodyParser = require('body-parser');
var awsS3 = require('./aws_s3')
// Constants
const port = process.env.PORT || 8080;
@victorpaulo
victorpaulo / watson_twilio.js
Last active August 28, 2019 20:10
IBM Watson Assistant & Twilio Sandbox
require('dotenv').config();
var AssistantV1 = require('ibm-watson/assistant/v1');
const clientTwilio = require('twilio')(process.env.accountSid, process.env.authToken);
const express = require('express');
const bodyParser = require('body-parser');
// Constants
const port = process.env.PORT || 8080;
// App