SlideShare a Scribd company logo
1 of 49
Download to read offline
From Zero to Cloud in
12 Easy Factors
Fire Exit Announcement
Please note the locations of the surrounding emergency exits & located the nearest lit EXIT sign to you
In the event of a fire alarm or other emergency, please calmly exit to the public concourse area
Emergency exit stairwells leading to the outside of this facility are located along the public concourse
For your safety in an emergency, please follow the directions of the Public Safety Staff
Ed King - Pivotal
@edking2
Jatin Naik - Pivotal
@tinygrasshopper
Now This Is a Story All About …
SLOGRAM!
(Sort of like Instagram)
Current status
> Deployed on a shared IIS instance
> Uses the local filesystem for storage
> Risky, error-prone deployments
> Strict networking requirements
> Unable to scale effectively
> Not ready for the cloud
The 12 Factors
> A methodology for building Software as a Service applications
> Originated from engineers working at Heroku
> A focus on stateless applications suitable for modern cloud platforms
The 12 Factors
> Codebase
> Dependencies
> Config
> Backing services
> Build, release, run
> Processes
> Port binding
> Concurrency
> Disposability
> Dev/prod parity
> Logs
> Admin processes
Codebase
What
> Each codebase must be stored in version control
> One-to-one relationship between application and codebase
> One-to-many relationship between codebase and deploys
Why
> To support collaboration between developers and teams
> To enable proper versioning
How
> Git, Subversion, Mercurial, etc.
cf push
Build, Release, Run
What
> Strictly separate the build, release and run stages
Why
> To prevent changes to code and/or configuration at runtime …
> … which in turn lowers the number of unexpected failures
How
> cf push
Dependencies
What
> Explicitly declare and isolate application dependencies
> Use a declaration manifest that’s stored with the codebase
> Use a dependency isolation tool during application execution
Why
> Provides consistency between dev/prod environments
> Simplifies setup for developers new to the application
> Supports portability between cloud platforms
How
> Nuget
# slogram.csproj - “declaration manifest”
<Project Sdk=“Microsoft.NET.Sdk.Web”>
// …


<ItemGroup>

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />

</ItemGroup>
// …



</Project>

# slogram.csproj - “declaration manifest”
<Project Sdk=“Microsoft.NET.Sdk.Web”>
// …


<ItemGroup>

<PackageReference Include="Microsoft.AspNetCore.All" Version=“…” />
<PackageReference Include=“SixLabors.ImageSharp" Version=“…” />

</ItemGroup>
// …



</Project>

# Program.cs
namespace slogram

{

public class Program

{

public static void Main(string[] args)

{

var hostBuilder = new WebHostBuilder()

.UseKestrel()

.UseContentRoot(Directory.GetCurrentDirectory())

.UseStartup<Startup>()

.UseUrls("http://0.0.0.0:9000")

.Build();



hostBuilder.Run();

}

}

}

hardcoded config
Config
What
> Ensure strict separation between code and configuration
> Store configuration in environment variables
Why
> Modify application behaviour without making code changes
> Simplifies deployment to multiple environments
> Reduce risk of leaking credentials and passwords
How
> Extract all application config to environment variables
> cf set-env
# Startup.cs
namespace slogram

{

public class Startup

{

public Startup(IConfiguration configuration, IHostingEnvironment env)

{

var builder = new ConfigurationBuilder()

.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)

.AddJsonFile($"appsettings.{ env.EnvironmentName}.json", optional: true)

.AddEnvironmentVariables();



Configuration = builder.Build();

Configuration = configuration;

}

}
}
config from env
cf scale
Before
Load Balancer
slogram-0
DB
filesystem
Load Balancer
slogram-0
DB
filesystem
After
slogram-1
DB
filesystem
Processes
What
> Execute the app as one or more stateless processes
> Ensure all stateful data is stored in a backing service
Why
> Reduce deployment complexity
> Reduce operational complexity
> Allow for much simpler scaling
How
> Store any stateful data in backing services
> Do not use sticky sessions or the local filesystem!
Backing Services
What
> Treat backing services (E.g. MySQL) as attached resources
> Make no distinction between local and third party services
> Attach resources via URLs stored in the app’s config
Why
> Provides loose coupling between service and deployment
> No code changes required to update backing services
> Allows operators to swap services out as they see fit
How
> cf marketplace, cf create/bind-service
Scaling concerns
1. Local database -> injected database service (MySQL)
2. Local storage -> remote storage (azure blobstore)
3. Data protection keys -> store in azure blobstore
# Startup.cs
namespace slogram

{

public class Startup

{

public void ConfigureServices(IServiceCollection services)

{

services.AddMvc();



services.AddDbContext<SlogramContext>(options =>

options.UseSqlite("Data Source=slogram.db”));

}



// …

}

using local filesystem
hardcoded config
Local database -> injected database service (MySQL)
public static void ProcessImage(int photoId, string rootPath)

{

using (var db = new MvcPhotoContext())

{

var photo = db.Find<Photo>(photoId);

var savedImageFullPath = Path.Combine(Path.Combine(rootPath, photo.RawUrl));

var processedFullPath = Path.Combine(Path.Combine(rootPath, photo.ProcessedUrl));



using (Image<Rgba32> image = Image.Load(savedImageFullPath))

{

image.Mutate(ctx => ctx.Polaroid());

image.Save(processedFullPath);

}
// …

}

}
using local filesystem
hardcoded config
Local storage -> remote storage (azure blobstore)
Data protection keys -> store in azure blobstore
%LOCALAPPDATA%ASP.NETDataProtection-Keys
cf {create,bind}-service
# slogram.csproj - “declaration manifest”
<Project Sdk=“Microsoft.NET.Sdk.Web”>
// …


<ItemGroup>

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0003" />
<PackageReference Include=“Pomelo.EntityFrameworkCore.MySql” Version=“2.0.1" />
<PackageReference Include=“Steeltoe.CloudFoundry.Connector.EFCore” Version="2.0.0" />
<PackageReference Include=“Steeltoe.Extensions.Configuration.CloudFoundryCore” Version="2.0.0" />

</ItemGroup>
// …



</Project>

public class MvcPhotoContext : DbContext

{



public DbSet<slogram.Models.Photo> Photo { get; set; }



protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

{

var configuration = new ConfigurationBuilder()

.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)

.AddEnvironmentVariables()

.AddCloudFoundry()

.Build();

optionsBuilder.UseMySql(configuration);

}

}



namespace slogram.Adapters

{

public static class Azure

{

public static CloudBlockBlob Blob(string blobpath)

{

var cloudStorageAccount =
CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("storageconnectionstring"));

var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();



var container = cloudBlobClient.GetContainerReference("slogramblobcontainer");

return container.GetBlockBlobReference(blobpath);

}

}

}





# Startup.cs
namespace slogram

{

public class Startup

{

public Startup(IConfiguration configuration)

{
// …


services.AddDataProtection()

.PersistKeysToAzureBlobStorage(Azure.Blob("encrypt_token"));



// …
}

}
}
Disposability
What
> Maximise robustness via fast startup and graceful shutdown
> Treat app instances as cattle, not pets
> Be resilient to unexpected and sudden shutdowns (SIGKILL)
Why
> To facilite fast, elastic scaling
> To allow for rapid deployment of new code/config changes
> Provide robustness in production deployments
How
> Minimise work on startup, don’t depend on shutdown hooks
Concurrency
What
> Scale out via the process model
> Treat processes as first class citizens
> Do not daemonize processes or attempt to write PID files
Why
> Allows for easy, horizontal scaling
How
> Split app into separate, runnable processes
> Scale independently
photo.RawUrl = oldBlob.StorageUri.PrimaryUri.AbsoluteUri;



FileStream fileStream = new FileStream(savedImageFullPath,
FileMode.OpenOrCreate);

file.CopyTo(fileStream);

fileStream.Close();



_context.Add(photo);

await _context.SaveChangesAsync();



Task.Run(() => ProcessImageAsync(photo.ID));



return RedirectToAction(nameof(Index));

}

return View(photo);

}

using Hangfire;

....
_context.Add(photo);


await _context.SaveChangesAsync();

var jobId = BackgroundJob.Enqueue(() => ProcessImageAsync(photo.ID));



return RedirectToAction(nameof(Index));

}

return View(photo);

using System;

using System.Threading;

using Hangfire;



namespace worker

{

class Program

{

static void Main(string[] args)

{

GlobalConfiguration.Configuration.UseSqlServerStorage(“....”);



using (var server = new BackgroundJobServer())

{

Thread.Sleep(Timeout.Infinite);

}



}

}

}



The 12 Factors
> Codebase
> Dependencies
> Config
> Backing services
> Build, release, run
> Processes
> Port binding
> Concurrency
> Disposability
> Dev/prod parity
> Logs
> Admin processes
Thanks for listening!

More Related Content

What's hot

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンharuki ueno
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentationsourabh aggarwal
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回haruki ueno
 
webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)Hendrik Ebbers
 
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...Andrea Dottor
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Maarten Balliauw
 
WebLogic authentication debugging
WebLogic authentication debuggingWebLogic authentication debugging
WebLogic authentication debuggingMaarten Smeets
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVCDzmitry Naskou
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkRaveendra R
 
Advanced Debugging Techniques
Advanced Debugging TechniquesAdvanced Debugging Techniques
Advanced Debugging TechniquesDavid Szöke
 

What's hot (20)

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
 
Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回Spring boot入門ハンズオン第二回
Spring boot入門ハンズオン第二回
 
Beoynd Vaadin 7
Beoynd Vaadin 7Beoynd Vaadin 7
Beoynd Vaadin 7
 
webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)
 
Web Space10 Overview
Web Space10 OverviewWeb Space10 Overview
Web Space10 Overview
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
GlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and FutureGlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and Future
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
Come sta la nostra applicazione? Un viaggio alla scoperta degli Health Check ...
 
Servlets lecture1
Servlets lecture1Servlets lecture1
Servlets lecture1
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...
 
WebLogic authentication debugging
WebLogic authentication debuggingWebLogic authentication debugging
WebLogic authentication debugging
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Advanced Debugging Techniques
Advanced Debugging TechniquesAdvanced Debugging Techniques
Advanced Debugging Techniques
 

Similar to From Zero to Cloud in 12 Easy Factors

Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoringOracle Korea
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsJack-Junjie Cai
 
Java Development on Bluemix
Java Development on BluemixJava Development on Bluemix
Java Development on BluemixRam Vennam
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesJakarta_EE
 
How to build a cloud adapter
How to build a cloud adapterHow to build a cloud adapter
How to build a cloud adapterMaarten Smeets
 
GE Predix 新手入门 赵锴 物联网_IoT
GE Predix 新手入门 赵锴 物联网_IoTGE Predix 新手入门 赵锴 物联网_IoT
GE Predix 新手入门 赵锴 物联网_IoTKai Zhao
 
Revised Adf security in a project centric environment
Revised Adf security in a project centric environmentRevised Adf security in a project centric environment
Revised Adf security in a project centric environmentJean-Marc Desvaux
 
App development and deployment in microsoft azure
App development and deployment in microsoft azureApp development and deployment in microsoft azure
App development and deployment in microsoft azureAkhil Mavurapu
 
TDC2016SP - Construindo Microserviços usando Spring Cloud
TDC2016SP - Construindo Microserviços usando Spring CloudTDC2016SP - Construindo Microserviços usando Spring Cloud
TDC2016SP - Construindo Microserviços usando Spring Cloudtdc-globalcode
 
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster NodesWSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster NodesWSO2
 
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...Kasun Gajasinghe
 
Simplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring CloudSimplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring CloudRamnivas Laddad
 
Silicon Valley CloudStack User Group - Designing CloudStack Clouds
Silicon Valley CloudStack User Group - Designing CloudStack CloudsSilicon Valley CloudStack User Group - Designing CloudStack Clouds
Silicon Valley CloudStack User Group - Designing CloudStack CloudsShapeBlue
 
All About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksAll About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksMohammad Asif Siddiqui
 
Azure presentation nnug dec 2010
Azure presentation nnug  dec 2010Azure presentation nnug  dec 2010
Azure presentation nnug dec 2010Ethos Technologies
 
SpringBoot and Spring Cloud Service for MSA
SpringBoot and Spring Cloud Service for MSASpringBoot and Spring Cloud Service for MSA
SpringBoot and Spring Cloud Service for MSAOracle Korea
 
Designing CloudStack Clouds
Designing CloudStack CloudsDesigning CloudStack Clouds
Designing CloudStack CloudsShapeBlue
 
Live Coding 12 Factor App
Live Coding 12 Factor AppLive Coding 12 Factor App
Live Coding 12 Factor AppEmily Jiang
 

Similar to From Zero to Cloud in 12 Easy Factors (20)

Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoring
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applications
 
Java Development on Bluemix
Java Development on BluemixJava Development on Bluemix
Java Development on Bluemix
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native Microservices
 
How to build a Oracle cloud adapter SOA, Integration & API's
How to build a Oracle cloud adapter  SOA, Integration & API'sHow to build a Oracle cloud adapter  SOA, Integration & API's
How to build a Oracle cloud adapter SOA, Integration & API's
 
How to build a cloud adapter
How to build a cloud adapterHow to build a cloud adapter
How to build a cloud adapter
 
GE Predix 新手入门 赵锴 物联网_IoT
GE Predix 新手入门 赵锴 物联网_IoTGE Predix 新手入门 赵锴 物联网_IoT
GE Predix 新手入门 赵锴 物联网_IoT
 
TDC 2016 - Arquitetura Java - Spring Cloud
TDC 2016 - Arquitetura Java - Spring CloudTDC 2016 - Arquitetura Java - Spring Cloud
TDC 2016 - Arquitetura Java - Spring Cloud
 
Revised Adf security in a project centric environment
Revised Adf security in a project centric environmentRevised Adf security in a project centric environment
Revised Adf security in a project centric environment
 
App development and deployment in microsoft azure
App development and deployment in microsoft azureApp development and deployment in microsoft azure
App development and deployment in microsoft azure
 
TDC2016SP - Construindo Microserviços usando Spring Cloud
TDC2016SP - Construindo Microserviços usando Spring CloudTDC2016SP - Construindo Microserviços usando Spring Cloud
TDC2016SP - Construindo Microserviços usando Spring Cloud
 
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster NodesWSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
 
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
 
Simplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring CloudSimplify Cloud Applications using Spring Cloud
Simplify Cloud Applications using Spring Cloud
 
Silicon Valley CloudStack User Group - Designing CloudStack Clouds
Silicon Valley CloudStack User Group - Designing CloudStack CloudsSilicon Valley CloudStack User Group - Designing CloudStack Clouds
Silicon Valley CloudStack User Group - Designing CloudStack Clouds
 
All About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksAll About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice Frameworks
 
Azure presentation nnug dec 2010
Azure presentation nnug  dec 2010Azure presentation nnug  dec 2010
Azure presentation nnug dec 2010
 
SpringBoot and Spring Cloud Service for MSA
SpringBoot and Spring Cloud Service for MSASpringBoot and Spring Cloud Service for MSA
SpringBoot and Spring Cloud Service for MSA
 
Designing CloudStack Clouds
Designing CloudStack CloudsDesigning CloudStack Clouds
Designing CloudStack Clouds
 
Live Coding 12 Factor App
Live Coding 12 Factor AppLive Coding 12 Factor App
Live Coding 12 Factor App
 

Recently uploaded

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Recently uploaded (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

From Zero to Cloud in 12 Easy Factors

  • 1. From Zero to Cloud in 12 Easy Factors
  • 2. Fire Exit Announcement Please note the locations of the surrounding emergency exits & located the nearest lit EXIT sign to you In the event of a fire alarm or other emergency, please calmly exit to the public concourse area Emergency exit stairwells leading to the outside of this facility are located along the public concourse For your safety in an emergency, please follow the directions of the Public Safety Staff
  • 3. Ed King - Pivotal @edking2 Jatin Naik - Pivotal @tinygrasshopper
  • 4. Now This Is a Story All About …
  • 6.
  • 7. Current status > Deployed on a shared IIS instance > Uses the local filesystem for storage > Risky, error-prone deployments > Strict networking requirements > Unable to scale effectively > Not ready for the cloud
  • 8. The 12 Factors > A methodology for building Software as a Service applications > Originated from engineers working at Heroku > A focus on stateless applications suitable for modern cloud platforms
  • 9. The 12 Factors > Codebase > Dependencies > Config > Backing services > Build, release, run > Processes > Port binding > Concurrency > Disposability > Dev/prod parity > Logs > Admin processes
  • 10. Codebase What > Each codebase must be stored in version control > One-to-one relationship between application and codebase > One-to-many relationship between codebase and deploys Why > To support collaboration between developers and teams > To enable proper versioning How > Git, Subversion, Mercurial, etc.
  • 12. Build, Release, Run What > Strictly separate the build, release and run stages Why > To prevent changes to code and/or configuration at runtime … > … which in turn lowers the number of unexpected failures How > cf push
  • 13.
  • 14. Dependencies What > Explicitly declare and isolate application dependencies > Use a declaration manifest that’s stored with the codebase > Use a dependency isolation tool during application execution Why > Provides consistency between dev/prod environments > Simplifies setup for developers new to the application > Supports portability between cloud platforms How > Nuget
  • 15. # slogram.csproj - “declaration manifest” <Project Sdk=“Microsoft.NET.Sdk.Web”> // … 
 <ItemGroup>
 <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
 </ItemGroup> // …
 
 </Project>

  • 16. # slogram.csproj - “declaration manifest” <Project Sdk=“Microsoft.NET.Sdk.Web”> // … 
 <ItemGroup>
 <PackageReference Include="Microsoft.AspNetCore.All" Version=“…” /> <PackageReference Include=“SixLabors.ImageSharp" Version=“…” />
 </ItemGroup> // …
 
 </Project>

  • 17.
  • 18.
  • 19.
  • 20. # Program.cs namespace slogram
 {
 public class Program
 {
 public static void Main(string[] args)
 {
 var hostBuilder = new WebHostBuilder()
 .UseKestrel()
 .UseContentRoot(Directory.GetCurrentDirectory())
 .UseStartup<Startup>()
 .UseUrls("http://0.0.0.0:9000")
 .Build();
 
 hostBuilder.Run();
 }
 }
 }
 hardcoded config
  • 21. Config What > Ensure strict separation between code and configuration > Store configuration in environment variables Why > Modify application behaviour without making code changes > Simplifies deployment to multiple environments > Reduce risk of leaking credentials and passwords How > Extract all application config to environment variables > cf set-env
  • 22. # Startup.cs namespace slogram
 {
 public class Startup
 {
 public Startup(IConfiguration configuration, IHostingEnvironment env)
 {
 var builder = new ConfigurationBuilder()
 .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
 .AddJsonFile($"appsettings.{ env.EnvironmentName}.json", optional: true)
 .AddEnvironmentVariables();
 
 Configuration = builder.Build();
 Configuration = configuration;
 }
 } } config from env
  • 23.
  • 24.
  • 26.
  • 28. Processes What > Execute the app as one or more stateless processes > Ensure all stateful data is stored in a backing service Why > Reduce deployment complexity > Reduce operational complexity > Allow for much simpler scaling How > Store any stateful data in backing services > Do not use sticky sessions or the local filesystem!
  • 29. Backing Services What > Treat backing services (E.g. MySQL) as attached resources > Make no distinction between local and third party services > Attach resources via URLs stored in the app’s config Why > Provides loose coupling between service and deployment > No code changes required to update backing services > Allows operators to swap services out as they see fit How > cf marketplace, cf create/bind-service
  • 30. Scaling concerns 1. Local database -> injected database service (MySQL) 2. Local storage -> remote storage (azure blobstore) 3. Data protection keys -> store in azure blobstore
  • 31. # Startup.cs namespace slogram
 {
 public class Startup
 {
 public void ConfigureServices(IServiceCollection services)
 {
 services.AddMvc();
 
 services.AddDbContext<SlogramContext>(options =>
 options.UseSqlite("Data Source=slogram.db”));
 }
 
 // …
 }
 using local filesystem hardcoded config Local database -> injected database service (MySQL)
  • 32. public static void ProcessImage(int photoId, string rootPath)
 {
 using (var db = new MvcPhotoContext())
 {
 var photo = db.Find<Photo>(photoId);
 var savedImageFullPath = Path.Combine(Path.Combine(rootPath, photo.RawUrl));
 var processedFullPath = Path.Combine(Path.Combine(rootPath, photo.ProcessedUrl));
 
 using (Image<Rgba32> image = Image.Load(savedImageFullPath))
 {
 image.Mutate(ctx => ctx.Polaroid());
 image.Save(processedFullPath);
 } // …
 }
 } using local filesystem hardcoded config Local storage -> remote storage (azure blobstore)
  • 33. Data protection keys -> store in azure blobstore %LOCALAPPDATA%ASP.NETDataProtection-Keys
  • 35.
  • 36. # slogram.csproj - “declaration manifest” <Project Sdk=“Microsoft.NET.Sdk.Web”> // … 
 <ItemGroup>
 <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0003" /> <PackageReference Include=“Pomelo.EntityFrameworkCore.MySql” Version=“2.0.1" /> <PackageReference Include=“Steeltoe.CloudFoundry.Connector.EFCore” Version="2.0.0" /> <PackageReference Include=“Steeltoe.Extensions.Configuration.CloudFoundryCore” Version="2.0.0" />
 </ItemGroup> // …
 
 </Project>

  • 37. public class MvcPhotoContext : DbContext
 {
 
 public DbSet<slogram.Models.Photo> Photo { get; set; }
 
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
 var configuration = new ConfigurationBuilder()
 .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
 .AddEnvironmentVariables()
 .AddCloudFoundry()
 .Build();
 optionsBuilder.UseMySql(configuration);
 }
 }
 

  • 38. namespace slogram.Adapters
 {
 public static class Azure
 {
 public static CloudBlockBlob Blob(string blobpath)
 {
 var cloudStorageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("storageconnectionstring"));
 var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
 
 var container = cloudBlobClient.GetContainerReference("slogramblobcontainer");
 return container.GetBlockBlobReference(blobpath);
 }
 }
 }
 
 

  • 39. # Startup.cs namespace slogram
 {
 public class Startup
 {
 public Startup(IConfiguration configuration)
 { // … 
 services.AddDataProtection()
 .PersistKeysToAzureBlobStorage(Azure.Blob("encrypt_token"));
 
 // … }
 } }
  • 40.
  • 41. Disposability What > Maximise robustness via fast startup and graceful shutdown > Treat app instances as cattle, not pets > Be resilient to unexpected and sudden shutdowns (SIGKILL) Why > To facilite fast, elastic scaling > To allow for rapid deployment of new code/config changes > Provide robustness in production deployments How > Minimise work on startup, don’t depend on shutdown hooks
  • 42. Concurrency What > Scale out via the process model > Treat processes as first class citizens > Do not daemonize processes or attempt to write PID files Why > Allows for easy, horizontal scaling How > Split app into separate, runnable processes > Scale independently
  • 43.
  • 44. photo.RawUrl = oldBlob.StorageUri.PrimaryUri.AbsoluteUri;
 
 FileStream fileStream = new FileStream(savedImageFullPath, FileMode.OpenOrCreate);
 file.CopyTo(fileStream);
 fileStream.Close();
 
 _context.Add(photo);
 await _context.SaveChangesAsync();
 
 Task.Run(() => ProcessImageAsync(photo.ID));
 
 return RedirectToAction(nameof(Index));
 }
 return View(photo);
 }

  • 45. using Hangfire;
 .... _context.Add(photo); 
 await _context.SaveChangesAsync();
 var jobId = BackgroundJob.Enqueue(() => ProcessImageAsync(photo.ID));
 
 return RedirectToAction(nameof(Index));
 }
 return View(photo);

  • 46. using System;
 using System.Threading;
 using Hangfire;
 
 namespace worker
 {
 class Program
 {
 static void Main(string[] args)
 {
 GlobalConfiguration.Configuration.UseSqlServerStorage(“....”);
 
 using (var server = new BackgroundJobServer())
 {
 Thread.Sleep(Timeout.Infinite);
 }
 
 }
 }
 }
 

  • 47.
  • 48. The 12 Factors > Codebase > Dependencies > Config > Backing services > Build, release, run > Processes > Port binding > Concurrency > Disposability > Dev/prod parity > Logs > Admin processes