Skip to content

Commit

Permalink
Ci/heroku deploy (#501)
Browse files Browse the repository at this point in the history
* #113: Add docker deploy.

* #113: Update scripts to deploy to Heroku.

* #113: Fix config.

* #13: Add Docker to config.

* #113: Install Docker for real.

* #113: Remove sudo.

* #113: Run apt-get without prompt.

* #113: Change order of yes command.

* #113: Only copy files as it has already been published.

* #113: Add Heroko package.

* #113: Remove port 443 binding.

* #113: Use Heroku dynamic port.

* #113: Don't use HTTPS redirection if environment doesn't support it.

* #113: Only publish once merge request has completed.
  • Loading branch information
kwokkan authored Dec 31, 2019
1 parent 3956cca commit e3d7513
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,51 @@ jobs:
at: .
- run: |
dotnet publish << pipeline.parameters.publish-project >> --configuration << pipeline.parameters.configuration >> --output publish
- save_cache:
key: publish-{{ .Environment.CIRCLE_WORKFLOW_WORKSPACE_ID }}
paths:
- publish
- store_artifacts:
path: publish

go-live:
docker:
- image: node:13.5.0-buster
steps:
- setup_remote_docker
- attach_workspace:
at: .
- restore_cache:
keys:
- yarn-cache-v3-{{ arch }}-{{ checksum "<< pipeline.parameters.node-project >>/yarn.lock" }}
- yarn-cache-v3-{{ arch }}-
- restore_cache:
keys:
- publish-{{ .Environment.CIRCLE_WORKFLOW_WORKSPACE_ID }}
- run: |
apt-get -y update
apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
apt-get -y update
apt-get -y install docker-ce docker-ce-cli containerd.io
docker -v
- run: |
cd publish
yarn global add heroku
docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
docker build . -t card-hero/frontend -f Dockerfile
heroku container:push web -a card-hero
heroku container:release web -a card-hero
npm-build:
docker:
- image: node:13.5.0-buster
Expand Down Expand Up @@ -170,3 +212,7 @@ workflows:
branches:
only:
- master

- go-live:
requires:
- dotnet-publish
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>..\..\analyzers\stylecop.ruleset</CodeAnalysisRuleSet>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
<UserSecretsId>271edc19-9986-45f1-b982-12947fca677c</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,6 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.4.43">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -44,6 +48,12 @@
<ProjectReference Include="..\..\src\CardHero.Core.SqlServer\CardHero.Core.SqlServer.csproj" />
<ProjectReference Include="..\..\src\CardHero.Data.SqlServer.DependencyInjection\CardHero.Data.SqlServer.DependencyInjection.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Dockerfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="NSwag" AfterTargets="Build">
<Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
Expand Down
7 changes: 7 additions & 0 deletions apps/CardHero.NetCoreApp.TypeScript/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
COPY . .
CMD ASPNETCORE_URLS=http://*:$PORT dotnet CardHero.NetCoreApp.TypeScript.dll
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
}
}
13 changes: 12 additions & 1 deletion apps/CardHero.NetCoreApp.TypeScript/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ namespace CardHero.NetCoreApp.TypeScript
{
public class Startup
{
private static class CardHeroEnvironmentVariables
{
public const string DisableHttps = "CH_DISABLE_HTTPS";
}

private readonly IConfiguration _configuration;
private readonly IWebHostEnvironment _environment;

Expand Down Expand Up @@ -158,11 +163,17 @@ 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, IWebHostEnvironment env)
{
app.UseForwardedHeaders();

app.UseJsonException();

// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();

if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(CardHeroEnvironmentVariables.DisableHttps)))
{
app.UseHttpsRedirection();
}

app.UseResponseCompression();

Expand Down

0 comments on commit e3d7513

Please sign in to comment.