Skip to content

Instantly share code, notes, and snippets.

View rcbop's full-sized avatar

Rogerio Peixoto rcbop

  • Spain
View GitHub Profile
#!/bin/bash
docker images --no-trunc --format '{{.ID}} {{.CreatedSince}}' | grep months | awk '$2 > 3 { print $1 }' | xargs -r docker rmi
@rcbop
rcbop / create-ec2-swarm-cluster.sh
Created May 11, 2018 01:37
creates docker swarm cluster using aws ec2
#!/bin/bash
#/ Description:
#/ Creates a docker swarm ec2 cluster
#/ Examples:
#/ DEBUG=true ./create-ec2-swarm-cluster.sh (Enable debug messages)
#/ NO_COLORS=true ./create-ec2-swarm-cluster.sh (Disable colors)
#/ --------------------------------------------------------------------------------
#/ Author: Rogério Castelo Branco Peixoto (rcbpeixoto@gmail.com)
#/ --------------------------------------------------------------------------------
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
@rcbop
rcbop / show-cloudfront-configuration.sh
Created February 5, 2018 23:14
Jq query to find cloudfront distribution by substring of comments sub-element
aws cloudfront list-distributions --profile my-profile --output json | jq '.DistributionList.Items[] | select(.Comment | contains("my-project-key"))'
@rcbop
rcbop / cleanup-s3-artifacts.sh
Created January 25, 2018 20:34
Cleanup s3 bucket from build packages and keep only the last 30 items of each project Raw
#!/bin/bash
AWS_BUCKET_NAME="<insert_bucket>"
AWS_BUCKET_REGION="<insert_region>"
AWS_KEY="<insert_key>"
AWS_SECRET="<insert_secret>"
MAX_COUNT_TO_KEEP=30
PROFILE="<insert_profile>"
log() { echo -e "["$(date "+%Y%m%dT%H%M%S")"] $1"; }
echo_blu(){ log "${BLUE}$1${NC}"; }
@rcbop
rcbop / install-ansible.sh
Created December 27, 2017 22:37
try to detect linux distro and install ansible, at last if does not succeed tries to install using git
#!/bin/bash
#/ Usage: ./install-ansible.sh
#/ Description: AWESOME INSTALL SCRIPT
#/ Author: Rogério Peixoto (rcbpeixoto@gmail.com)
#/ Options:
#/ --help: Display this help message
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
expr "$*" : ".*--help" > /dev/null && usage
echo "Using $TERM terminal"
@rcbop
rcbop / jenkinsfile.groovy
Created December 21, 2017 14:44
Jenkinsfile for REST API + Oracle instant client download + Docker image build
// ##########################################################################
// # REST API jenkinsfile + oracle client
// ##########################################################################
// # Mantainer rcbpeixoto@gmail.com
// ##########################################################################
env.DOCKER_TAG="${params.BRANCH}"
env.BRANCH="${params.BRANCH}"
env.DOCKER_IMAGE="${env.JOB_BASE_NAME}"
env.DOCKER_NAME="${env.DOCKER_IMAGE}:${env.DOCKER_TAG}"
env.AWS_ENV="${env.DOCKER_IMAGE}-${env.DOCKER_TAG}"
#!/bin/bash
projType=$1
projectName=$2
buildNumber=$3
if [[ "$projectName" == "" && "$buildNumber" == "" && "$projType" == "" ]]; then
echo Need to provide project type, name and build number
exit 1
fi
echo $projectName
echo $buildNumber
#!/bin/bash
which jq 2>/dev/null || { echo >&2 "jq json processor is required but it's not installed. Aborting."; exit 1; }
if [[ ($FRONTEND_PROJECTS == "") || ($BUILD_NUMBER == "") || ($PACKAGE_API == "") || ($DELIVERY_PACKAGE_ENVIRONMENT == "" ) ]]; then
echo "ERROR missing arguments" && exit 1;
fi
rm -f manifest.json
rm -f manifest.json.tmp
rm -f webprojects.json.tmp
@rcbop
rcbop / delete-obsolete-ecr-images.sh
Last active June 18, 2017 03:59
Removes old aws ecr docker images that are not tagged keeping the latests given number (default 5)
#!/bin/bash
# removes old ecr images keeping the latests given number
# do not removes images with tag
# mantainer rogerio.c.peixoto (rcbpeixoto@gmail.com)
#####################################################
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
MAGENTA='\033[35m'
@rcbop
rcbop / docker-cleanup.groovy
Last active January 9, 2024 20:40
Jenkins pipeline script for Docker cleanup (remove dangling images and exited containers) in a given build agent
node("${params.BUILD_AGENT}") {
stage('Dangling Containers') {
sh 'docker ps -q -f status=exited | xargs --no-run-if-empty docker rm'
}
stage('Dangling Images') {
sh 'docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi'
}