Skip to content

Commit

Permalink
Updated docker file and fixed some issues in sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatdwarkani committed Nov 25, 2020
1 parent 3721f4e commit e485ee8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-alpine AS base
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base

# During time of preparing sample alphine image was not available
# It is better to use alphine as base for reducing image size

# FROM mcr.microsoft.com/dotnet/core/aspnet:5.0-alpine AS base

WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build

#Installing nodejs

Expand All @@ -19,7 +24,7 @@ RUN npm install -g gulp

WORKDIR /src

COPY ["src/sample-library-proj/sample-library-proj.csproj.csproj", "src/sample-library-proj/"]
COPY ["src/sample-library-proj/sample-library-proj.csproj", "src/sample-library-proj/"]
COPY ["src/mvc-sample-app/mvc-sample-app.csproj", "src/mvc-sample-app/"]
COPY ["src/mvc-sample-app/package.json", "src/mvc-sample-app/"]
COPY *.config .
Expand All @@ -35,7 +40,8 @@ RUN dotnet restore "src/mvc-sample-app/mvc-sample-app.csproj" --disable-parallel
COPY . .
WORKDIR "/src/src/mvc-sample-app"

#setting release mode for node packages and webpacking
# setting release mode for node packages and webpacking to use minified files for production
# set this to Debug if you need debug build
ENV NODE_ENV="Release"
RUN npm install -g webpack
RUN npm install -g webpack-cli
Expand All @@ -48,7 +54,9 @@ RUN dotnet publish "mvc-sample-app.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app


# Sample of environement variable which can be passed through docker. Note replace a json settings using double undersscore
# check appsettings.json file in project you will find similar settings.
# appsettings.json settings will be overridden by env variables passed from here
ENV ApplicationDetails__SecretKey=SecretKeyPassedThroughEnvironmentVariable
ENV AppSettings__EnableHTTPS="false"

Expand Down
22 changes: 0 additions & 22 deletions src/mvc-sample-app/Dockerfile

This file was deleted.

8 changes: 4 additions & 4 deletions src/mvc-sample-app/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - mvc_sample_app</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<environment names="Development">
<link href="~/css/common/site.css" rel="stylesheet" />
<link href="~/css/common/site.css" rel="stylesheet" />
</environment>

<environment names="Staging,Production">
Expand Down Expand Up @@ -48,8 +48,8 @@
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<environment names="Development">
<script src="~/js/common/hello-world.js"></script>
Expand Down
6 changes: 5 additions & 1 deletion src/mvc-sample-app/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHsts();
}

app.UseHttpsRedirection();
if (Configuration["AppSettings:EnableHTTPS"].ToLowerInvariant() == "true")
{
app.UseHttpsRedirection();
}

app.UseStaticFiles();

app.UseRouting();
Expand Down
6 changes: 6 additions & 0 deletions src/mvc-sample-app/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"ApplicationDetails": {
"SecretKey": "secretkey"
},
"AppSettings": {
"EnableHTTPS": "true"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down

0 comments on commit e485ee8

Please sign in to comment.