Skip to content

Instantly share code, notes, and snippets.

View brafales's full-sized avatar

Bernat Ràfales brafales

View GitHub Profile
@brafales
brafales / Dockerfile
Created September 29, 2019 10:12
Rails Dockerfile with jemalloc
FROM ruby:2.6
RUN apt-get update && apt-get install libjemalloc1 && rm -rf /var/lib/apt/lists/*
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1
service: pipeline-notifications
custom:
pipeline_name: "staging"
provider:
name: aws
runtime: ruby2.5
stage: 'staging'
require 'json'
require 'aws-sdk-ecs'
require 'aws-sdk-rds'
def stop(event:, context:)
rds_client.stop_db_instance(
db_instance_identifier: ENV['DB_NAME']
)
service_names.each do |service_name|
ecs_client.update_service(
service: stopAndStartStaging
custom:
db_name: bloomandwild-staging
cluster_name: staging
provider:
name: aws
runtime: ruby2.5
require 'json'
require 'aws-sdk-ecs'
def restart_service(event:, context:)
event['Records'].each { |record| process_record(record) }
{ statusCode: 200, body: JSON.generate('OK') }
end
def process_record(record)
record = Record.new(record)
@brafales
brafales / fargate-restart-serverless.yml
Last active August 16, 2019 10:55
Serverless Framework example to restart fargate services based on memory usage
service: restartFargateServices
custom:
# SNS topic where the CloudWatch alarms will send messages when triggered
# We need the full Arn for the CloudFormation snippet that creates the alarms
snsTopic: "${self:service}-fargate-memory-alarms"
snsTopicArn: { "Fn::Join" : ["", ["arn:aws:sns:${self:provider.region}:", { "Ref" : "AWS::AccountId" }, ":${self:custom.snsTopic}" ] ] }
# Cluster and Service Fargate names that we want to monitor and restart
cluster_name: "my-cluster"
service_name: "my-service"
{
"containerDefinitions": [
{
"entryPoint": [
"./docker/start-sidekiq.sh"
],
"portMappings": [],
"command": [
"config/sidekiq.yml"
],
require "sidekiq"
Sidekiq.configure_server do |config|
# Touch a file so we know Sidekiq worker has started.
# Useful for health checks
config.on(:startup) do
FileUtils.touch(Rails.root.join("tmp", "pids", "sidekiq_started"))
end
# Delete the touched file so we know Sidekiq worker has stopped.
# Useful for health checks
{
"family": "redis-datadog",
"networkMode": "awsvpc",
"containerDefinitions": [
{
"name": "redis",
"image": "redis:latest",
"essential": true,
"dockerLabels": {
"com.datadoghq.ad.instances": "[{\"host\": \"%%host%%\", \"port\": 6379}]",
class NilClass
def method_missing
raise StandardError "Ha, ha! Loser"
end
end