Skip to content

Instantly share code, notes, and snippets.

View anderson-marques's full-sized avatar
🤖
Hacking as usual...

Anderson Carvalho anderson-marques

🤖
Hacking as usual...
View GitHub Profile
@anderson-marques
anderson-marques / pyenv.sh
Created February 19, 2021 11:45
MACos Pyenv setup
PYENV_PYTHON_VERSION=3.1
brew install pyenv
pyenv install $PYENV_PYTHON_VERSION
pyenv global $PYENV_PYTHON_VERSION
pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
@anderson-marques
anderson-marques / dockerizing_dotnet_init.sh
Created February 20, 2021 13:45
Creates a new .NET Project in the host using Docker
project_name=dockerized-dotnet
init_command="dotnet new webapi -o ${project_name} --no-https"
docker_image=mcr.microsoft.com/dotnet/sdk:3.1-alpine
docker run --rm -td --name "${project_name}-init" "${docker_image}" sh -c "${init_command} && sleep 60"
sleep 20
docker cp ${project_name}-init:/${project_name} .
@anderson-marques
anderson-marques / Dockerfile
Created February 20, 2021 14:27
dockerized-dotnet-Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:3.1-alpine AS step1
WORKDIR /src
COPY dockerized-dotnet.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c release -o /app
FROM mcr.microsoft.com/dotnet/aspnet:3.1-alpine
WORKDIR /app
COPY --from=step1 /app .
@anderson-marques
anderson-marques / Dockerfile
Created February 20, 2021 14:43
Dockerized .NET - Development Image
FROM mcr.microsoft.com/dotnet/sdk:3.1-alpine
ENV WORKDIR /app
WORKDIR ${WORKDIR}
COPY dockerized-dotnet.csproj .
RUN dotnet restore
COPY . .
@anderson-marques
anderson-marques / Makefile
Last active February 20, 2021 16:15
Dockerized .NET - Makefile
build-dev:
@docker build -f ./docker/dev/Dockerfile -t dockerized-dotnet:dev .
tag=1.0.0
build-prod:
@docker build -f ./docker/prod/Dockerfile -t dockerized-dotnet:${tag} .
@docker tag dockerized-dotnet:${tag} dockerized-dotnet:latest
console: build-dev
@docker run --rm -it dockerized-dotnet:dev sh
@anderson-marques
anderson-marques / tag_untagged_ecr_images.sh
Created February 22, 2021 17:07
TAG Untagged ECR Images
# This script tags a untagged ECR Images using its diggest
ECR_REPO=my-ecr-repo-name
IMAGE_DIGEST="sha256:ab6DSA4f1f940df430062009fdfb02d3ede74b48e39ada939047c2e7d0ee3ac50d8"
TAG=my-tag
# ---
MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPO --image-ids imageDigest=$IMAGE_DIGEST --query 'images[].imageManifest' --output text)
aws ecr put-image --repository-name $ECR_REPO --image-tag $TAG --image-manifest "$MANIFEST"
@anderson-marques
anderson-marques / oauth2_device_flow.py
Created March 11, 2021 17:42
oauth2_device_flow.py
"""
OAuth2 Device Flow adaptation from Implicit Flow - Useful for CLIs
"""
from http.server import SimpleHTTPRequestHandler, HTTPServer
import os
from os.path import expanduser
import json
callback_html = """
<body style="font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif">
@anderson-marques
anderson-marques / gcloud_service_account_print_access_token.py
Created March 12, 2021 20:13
gcloud_service_account_print_access_token
# Python script to programmatically generate the access token from a service-account key
# It does what the following commands does:
# - gcloud auth activate-service-account
# - gcloud auth print-access-token
import google.auth
import google.auth.transport.requests
from google.oauth2 import service_account
from os.path import expanduser
@anderson-marques
anderson-marques / k8s_force_namespace_deletion.sh
Created March 18, 2021 10:05
k8s_force_namespace_deletion.sh
NAMESPACE=apigee
kubectl proxy &
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' >temp.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
@anderson-marques
anderson-marques / parse_dotenv.bash
Created March 18, 2021 11:50 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)