Skip to content

Instantly share code, notes, and snippets.

View nandotorres's full-sized avatar

Fernando Torres nandotorres

  • Avenue Code
  • Belo Horizonte, Brazil
View GitHub Profile
myrepo=my_repo_name
aws ecr list-images --repository-name $myrepo --query 'imageIds[?type(imageTag)!=`string`].[imageDigest]' --output text | while read line; do aws ecr batch-delete-image --repository-name $myrepo --image-ids imageDigest=$line; done
@nandotorres
nandotorres / default_spec.rb
Created December 14, 2016 01:01
Configure ChefSolo and specify platform on default_spec.rb
require 'spec_helper'
describe 'cookbook::default' do
context 'When applying cookbooks on an Ubuntu instance' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04')
runner.converge(described_recipe)
end
it 'converges successfully' do
@nandotorres
nandotorres / run_instance.sh
Created December 12, 2016 20:57
Run EC2 instance based on AMI created by packer
#!/bin/bash
EC2_NAME_SUFIX=`date "+%Y%m%d%H%M"`
# Query AWS if exists an AMI with TAG SHA1 = $CI_BUILD_REF
EXISTING_AMI=$(aws ec2 describe-images \
--filter="Name=tag-key,Values=SHA1,Name=tag-value,Values=$CI_BUILD_REF")
# Extract the AMI ID
AMI_ID=$(echo $EXISTING_AMI |jq ".Images[] .ImageId" |sed -e 's/^"//' -e 's/"$//')
@nandotorres
nandotorres / .gitlab-ci.yml
Created December 12, 2016 20:56
Pipeline definition for CI/CD of infrastructure
stages:
- quality
- unitTests
- compliance
- build
- deploy
rubocop:
stage: quality
script:
@nandotorres
nandotorres / packer_build.sh
Created December 12, 2016 17:54
Shell script to run packer command line tool and build an AMI with Chef cookbook
#!/bin/bash
rm -rf vendor/*
# Group all recipes and cookbooks for provisioning
chef exec berks vendor vendor/cookbooks
chef exec berks install
##########################################################
# Deregister any existing image for this commit revision
# Note: $CI_BUILD_REF is authomatically exported by GitLab
@nandotorres
nandotorres / packer.json
Last active December 12, 2016 17:56
Packer JSON input to create an AMI with amazon-ebs driver
{
"variables": {
"aws_access_key_id": "{{env `AWS_ACCESS_KEY_ID` }}",
"aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY` }}",
"aws_region": "{{env `AWS_REGION` }}",
"ebs_optimized": "{{env `AMI_EBS_OPTIMIZED` }}",
"source_ami": "{{env `AWS_SOURCE_AMI` }}",
"instance_type": "{{env `AMI_INSTANCE_TYPE` }}",
"associate_public_ip_address": "{{env `AMI_ASSOCIATE_PUBLIC_IP_ADDRESS` }}",
"vpc_id": "{{env `AMI_VPC_ID` }}",
@nandotorres
nandotorres / generate_certs.sh
Created December 12, 2016 17:49
Generate key.pem and cert.pem to use with packer
#!/bin/bash
KEY_NAME=$1
PEM_NAME="${KEY_NAME}-key.pem"
CERTIFICATE_NAME="${KEY_NAME}-certificate.pem"
openssl genrsa 2048 > $PEM_NAME
openssl req -new -x509 -nodes -sha1 -days 365 -key $PEM_NAME -outform PEM > $CERTIFICATE_NAME
@nandotorres
nandotorres / Gemfile
Created December 11, 2016 17:37
Gemfile for cookbook dependencies
source 'https://rubygems.org'
gem 'foodcritic'
gem 'rubocop'
gem 'kitchen-docker'
@nandotorres
nandotorres / metadata.rb
Created December 11, 2016 17:19
Metadata with foodcritic recommendations
name 'techtalk'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'all_rights'
description 'Installs/Configures techtalk'
long_description 'Installs/Configures techtalk'
version '0.1.0'
# If you upload to Supermarket you should set this so your cookbook
# gets a `View Issues` link
@nandotorres
nandotorres / default.rb
Last active December 11, 2016 17:04
Recipe to install docker and running ToDo App container
execute 'install docker' do
command 'curl -sSL https://get.docker.com/ | sh'
end
execute 'restart docker service' do
command 'sudo service docker restart'
end
execute 'run application container' do
command 'docker run -d -p 80:3000 --restart=always nandotorres/mean-todo'