-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Deployment Logic #251
Changes from 25 commits
9de16bb
1c80c82
7bef63f
2edd70d
8d73056
8e81b31
15fcef5
9486b07
f1f9b2c
7acbcbb
e6144e1
61af039
b42022d
ccd9f1c
30d99a4
464e189
c3e8a14
ccd7680
e56a4bc
9430c8c
c387d1e
205047a
537d39f
3f66588
38fc0c5
c0cb55a
c76a4f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using ServerCore.DataModel; | ||
|
||
namespace ServerCore.Areas.Deployment | ||
{ | ||
public class DeploymentConfiguration | ||
{ | ||
internal static void ConfigureDatabase(IConfiguration configuration, IServiceCollection services, IHostingEnvironment env) | ||
{ | ||
// Use SQL Database if in Azure, otherwise, use localdb | ||
if (env.IsStaging() && Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") == "PuzzleServerTestDeploy") | ||
{ | ||
services.AddDbContext<PuzzleServerContext> | ||
(options => options.UseLazyLoadingProxies() | ||
.UseSqlServer(configuration.GetConnectionString("PuzzleServerSQLConnectionString"))); | ||
} | ||
else if (env.IsProduction() && Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") == "puzzlehunt") | ||
{ | ||
services.AddDbContext<PuzzleServerContext> | ||
(options => options.UseLazyLoadingProxies() | ||
.UseSqlServer(configuration.GetConnectionString("PuzzleServerSQLConnectionString"))); | ||
} | ||
else | ||
{ | ||
services.AddDbContext<PuzzleServerContext> | ||
(options => options.UseLazyLoadingProxies() | ||
//.UseSqlServer(configuration.GetConnectionString("PuzzleServerContextLocal"))); | ||
.UseSqlServer(configuration.GetConnectionString("TempDeploy"))); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Azure.Services.AppAuthentication; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Configuration.AzureKeyVault; | ||
|
||
namespace ServerCore | ||
{ | ||
|
@@ -11,8 +14,23 @@ public static void Main(string[] args) | |
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
WebHost.CreateDefaultBuilder(args) | ||
//.ConfigureAppConfiguration((ctx, builder) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be cleaned up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'll be recreated if I pick "add KeyVault" again in the future, so should be safe to delete. |
||
//{ | ||
// var keyVaultEndpoint = GetKeyVaultEndpoint(); | ||
// if (!string.IsNullOrEmpty(keyVaultEndpoint)) | ||
// { | ||
// var azureServiceTokenProvider = new AzureServiceTokenProvider(); | ||
// var keyVaultClient = new KeyVaultClient( | ||
// new KeyVaultClient.AuthenticationCallback( | ||
// azureServiceTokenProvider.KeyVaultTokenCallback)); | ||
// builder.AddAzureKeyVault( | ||
// keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager()); | ||
// } | ||
//}) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
// private static string GetKeyVaultEndpoint() => "https://PuzzleServerTestKeyVault.vault.azure.net"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
This file is used by the publish/package process of your Web project. You can customize the behavior of this process | ||
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<WebPublishMethod>MSDeploy</WebPublishMethod> | ||
<ResourceId>/subscriptions/3ffc52f4-eed1-4312-8170-9caf82ff0949/resourcegroups/PuzzleServerTestDeploy/providers/Microsoft.Web/sites/PuzzleServerTestDeploy</ResourceId> | ||
<ResourceGroup>PuzzleServerTestDeploy</ResourceGroup> | ||
<PublishProvider>AzureWebSite</PublishProvider> | ||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> | ||
<LastUsedPlatform>Any CPU</LastUsedPlatform> | ||
<SiteUrlToLaunchAfterPublish>https://puzzleservertestdeploy.azurewebsites.net</SiteUrlToLaunchAfterPublish> | ||
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> | ||
<ExcludeApp_Data>False</ExcludeApp_Data> | ||
<ProjectGuid>67b91cce-4e3d-4f0f-8a76-eafd37c5f949</ProjectGuid> | ||
<MSDeployServiceURL>puzzleservertestdeploy.scm.azurewebsites.net:443</MSDeployServiceURL> | ||
<DeployIisAppPath>PuzzleServerTestDeploy</DeployIisAppPath> | ||
<RemoteSitePhysicalPath /> | ||
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer> | ||
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod> | ||
<EnableMSDeployBackup>True</EnableMSDeployBackup> | ||
<UserName>$PuzzleServerTestDeploy</UserName> | ||
<_SavePWD>True</_SavePWD> | ||
<_DestinationType>AzureWebSite</_DestinationType> | ||
<InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension> | ||
<KeyVaultUri>https://PuzzleServerTestKeyVault.vault.azure.net</KeyVaultUri> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this change with the region change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, but we're not using it anyway. |
||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<SelfContained>false</SelfContained> | ||
<_IsPortable>true</_IsPortable> | ||
</PropertyGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<publishData> | ||
<publishProfile profileName="puzzlehunt - Web Deploy" publishMethod="MSDeploy" publishUrl="puzzlehunt.scm.azurewebsites.net:443" msdeploySite="puzzlehunt" userName="$puzzlehunt" userPWD="saaiNEoRlu8vKA5bzoi9w3x9yqPvDGs0bQthExxc6GPjeqxxY2r3bz2Ah8Qu" destinationAppUrl="http://puzzlehunt.azurewebsites.net" SQLServerDBConnectionString="Data Source=tcp:puzzleserverprod.database.windows.net,1433;Initial Catalog=puzzleserver;User Id=PuzzleServerAdmin@puzzleserverprod.database.windows.net;Password=PuzzlehuntPuzzledayNew!;" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100"> | ||
<databases> | ||
<add name="defaultConnection" connectionString="Data Source=tcp:puzzleserverprod.database.windows.net,1433;Initial Catalog=puzzleserver;User Id=PuzzleServerAdmin@puzzleserverprod.database.windows.net;Password=PuzzlehuntPuzzledayNew!;" providerName="System.Data.SqlClient" type="Sql" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100" /> | ||
<add name="PuzzleServerSQLConnectionString" connectionString="Server=tcp:puzzleserverprod.database.windows.net,1433;Initial Catalog=puzzleserver;Persist Security Info=False;User ID=PuzzleServerAdmin;Password=PuzzlehuntPuzzledayNew!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" type="Sql" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100" /> | ||
</databases> | ||
</publishProfile> | ||
<publishProfile profileName="puzzlehunt - FTP" publishMethod="FTP" publishUrl="ftp://waws-prod-dm1-103.ftp.azurewebsites.windows.net/site/wwwroot" ftpPassiveMode="True" userName="puzzlehunt\$puzzlehunt" userPWD="saaiNEoRlu8vKA5bzoi9w3x9yqPvDGs0bQthExxc6GPjeqxxY2r3bz2Ah8Qu" destinationAppUrl="http://puzzlehunt.azurewebsites.net" SQLServerDBConnectionString="Data Source=tcp:puzzleserverprod.database.windows.net,1433;Initial Catalog=puzzleserver;User Id=PuzzleServerAdmin@puzzleserverprod.database.windows.net;Password=PuzzlehuntPuzzledayNew!;" mySQLDBConnectionString="" hostingProviderForumLink="" controlPanelLink="http://windows.azure.com" webSystem="WebSites" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100"> | ||
<databases> | ||
<add name="defaultConnection" connectionString="Data Source=tcp:puzzleserverprod.database.windows.net,1433;Initial Catalog=puzzleserver;User Id=PuzzleServerAdmin@puzzleserverprod.database.windows.net;Password=PuzzlehuntPuzzledayNew!;" providerName="System.Data.SqlClient" type="Sql" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100" /> | ||
<add name="PuzzleServerSQLConnectionString" connectionString="Server=tcp:puzzleserverprod.database.windows.net,1433;Initial Catalog=puzzleserver;Persist Security Info=False;User ID=PuzzleServerAdmin;Password=PuzzlehuntPuzzledayNew!;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" type="Sql" targetDatabaseEngineType="sqlazuredatabase" targetServerVersion="Version100" /> | ||
</databases> | ||
</publishProfile> | ||
</publishData> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using System; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Authorization; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using ServerCore.Areas.Deployment; | ||
using ServerCore.Areas.Identity.UserAuthorizationPolicy; | ||
using ServerCore.DataModel; | ||
|
||
namespace ServerCore | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
private IHostingEnvironment hostingEnvironment; | ||
|
||
public Startup(IConfiguration configuration, IHostingEnvironment env) | ||
{ | ||
Configuration = configuration; | ||
hostingEnvironment = env; | ||
} | ||
|
||
public Startup(IHostingEnvironment env) | ||
{ | ||
// Set up to use Azure settings | ||
IConfigurationBuilder configBuilder = new ConfigurationBuilder() | ||
.SetBasePath(env.ContentRootPath) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) | ||
.AddEnvironmentVariables(); | ||
Configuration = configBuilder.Build(); | ||
|
||
hostingEnvironment = env; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
@@ -39,9 +56,8 @@ public void ConfigureServices(IServiceCollection services) | |
options.Conventions.AuthorizeFolder("/ModelBases"); | ||
}); | ||
|
||
services.AddDbContext<PuzzleServerContext> | ||
(options => options.UseLazyLoadingProxies() | ||
.UseSqlServer(Configuration.GetConnectionString("PuzzleServerContext"))); | ||
DeploymentConfiguration.ConfigureDatabase(Configuration, services, hostingEnvironment); | ||
FileManager.ConnectionString = Configuration.GetConnectionString("AzureStorageConnectionString"); | ||
|
||
services.AddAuthentication().AddMicrosoftAccount(microsoftOptions => | ||
{ | ||
|
@@ -87,12 +103,23 @@ public void ConfigureServices(IServiceCollection services) | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
if (env.IsDevelopment() && String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))) | ||
{ | ||
app.UseBrowserLink(); | ||
app.UseDeveloperExceptionPage(); | ||
PuzzleServerContext.UpdateDatabase(app); | ||
} | ||
else if (env.IsStaging() && Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") == "PuzzleServerTestDeploy") | ||
{ | ||
app.UseBrowserLink(); | ||
app.UseDeveloperExceptionPage(); | ||
morganbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PuzzleServerContext.UpdateDatabase(app); | ||
} | ||
else if (env.IsProduction() && Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") == "Puzzlehunt") | ||
morganbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
app.UseBrowserLink(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't need this in production or staging |
||
app.UseDeveloperExceptionPage(); | ||
morganbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Error"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:44319/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"PuzzleServerContextLocal": "Server=(localdb)\\MSSQLLocalDB;Database=PuzzleServer;Trusted_Connection=True;MultipleActiveResultSets=true", | ||
"AzureStorageConnectionString": "UseDevelopmentStorage=true" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "https://puzzlehunt.azurewebsites.net", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"PuzzleServerContext": "", | ||
"AzureStorageConnectionString": "", | ||
"PuzzleServerSQLConnectionString": "" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "https://puzzleservertestdeploy.azurewebsites.net", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"PuzzleServerContext": "", | ||
"AzureStorageConnectionString": "", | ||
"PuzzleServerSQLConnectionString": "" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking site name instead of just the environment for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because when I did only the environment I had problems.