Skip to content

Instantly share code, notes, and snippets.

View endofcake's full-sized avatar
🌱

Alexander Savchuk endofcake

🌱
View GitHub Profile
@endofcake
endofcake / docker.sh
Last active May 20, 2018 01:42
Pass base image version as an argument
docker build --build-arg VERSION=${version} .
@endofcake
endofcake / tree.sh
Last active May 20, 2018 04:22
Typical Terraform project
|-- .editorconfig
|-- .gitattributes
|-- .gitignore
|-- Jenkinsfile
|-- README.md
|-- scripts
| |-- run_terraform_deployer.sh
`-- src
|-- config.tf
|-- data_sources.tf
@endofcake
endofcake / sample.tf
Last active May 20, 2018 05:00
Environment maps in Terraform
variable "instance_type" {
type = "map"
default = {
test = "m4.large"
uat = "m4.large"
prod = "m4.xlarge"
}
}
// <...>
@endofcake
endofcake / .gitattributes
Created May 20, 2018 04:46
Set LF line endings, otherwise bash scripts fail during the deployment
# Always LF for bash scripts
*.sh text eol=lf
@endofcake
endofcake / get_image_tags.py
Created May 22, 2018 21:22
An external data source for Terraform that returns the versions of all images in an ECS task definition
''' Return image tags specified in ECS task definition '''
import json
import sys
import boto3
ECR_CLIENT = boto3.client('ecr')
ECS_CLIENT = boto3.client('ecs')
def main(cluster_name, service_name):
@endofcake
endofcake / cfn.tf
Created May 23, 2018 08:45
Auto Scaling group managed in CloudFormation and wrapped in Terraform
resource "aws_cloudformation_stack" "autoscaling_group" {
name = "${var.cfn_stack_name}"
template_body = <<EOF
Description: "${var.cfn_stack_description}"
Resources:
ASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: ["${join("\",\"", var.subnets)}"]
@endofcake
endofcake / .gitattributes
Created May 27, 2018 04:14
Always LF for bash scripts
# Always LF
*.sh text eol=lf
@endofcake
endofcake / .editorconfig
Created May 27, 2018 04:14
Display settings for bash scripts
[*.sh]
end_of_line = lf
indent_size = 2
@endofcake
endofcake / Jenkinsfile
Last active May 27, 2018 04:20
Using a shared library to reduce the boilerplate code in our pipeline definitions
#!/usr/bin/env groovy
infraPipeline()
@endofcake
endofcake / run.sh
Created May 28, 2018 22:59
Run an ECS task and grab its output
#!/bin/bash
set -euo pipefail
# some env vars here
STARTED_BY="$(date +"%T") - $USERNAME"
AWS_DEFAULT_REGION="${REGION}"
TASK_ID=""