Skip to content

Commit

Permalink
Dockerize solution for Windows and Linux Containers (#85)
Browse files Browse the repository at this point in the history
* Dockerize solution for windows and linux docker container

* Add new lines at the end on files.
Fix merge mistake in a Startup.cs

* Fix project file
  • Loading branch information
svoitovych0218 committed May 26, 2020
1 parent dd34e8c commit 3936f1c
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/DockerCompose/Linux/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.7"

services:

coderr-server-web:
image: "coderrio/coderrserverweb:latest"
container_name: coderr-server-web
hostname: coderr-server-web
ports:
- "2500:80"
networks:
- coderr_network

volumes:
esdata:
driver: local

networks:
coderr_network:
name: coderr_network
1 change: 1 addition & 0 deletions src/DockerCompose/Linux/run example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose run -p 2500:80 -e "ConnectionStrings:Db"="Data Source=host.docker.internal,1433;Initial Catalog=Coderr99;User Id=sa; Password=Pass@word; Connect Timeout=15;" coderr-server-web
14 changes: 14 additions & 0 deletions src/DockerCompose/Windows/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.7"

services:

coderr-server-web:
image: "coderrio/win_coderrserverweb:latest"
container_name: coderr-server-web
hostname: coderr-server-web
ports:
- "2500:80"

volumes:
esdata:
driver: local
1 change: 1 addition & 0 deletions src/DockerCompose/Windows/run example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose run -p 2500:80 -e "ConnectionStrings:Db"="Data Source=172.**.**.1,1433;Initial Catalog=Coderr99;User Id=sa; Password=Pass@word; Connect Timeout=15;" coderr-server-web
26 changes: 26 additions & 0 deletions src/Server/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,29 @@
# files
Dockerfile*
#**/*.md

**/.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
25 changes: 25 additions & 0 deletions src/Server/BuildAndPushLinuxImage.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
COPY docker-compose_linux.yml docker-compose.yml
COPY docker-compose_linux.override.yml docker-compose.override.yml
CD Coderr.Server.Web
COPY Dockerfile_Linux Dockerfile

CD ..

CALL BuildFrontend.bat

docker-compose build

ECHO built successfully

docker push coderrio/coderrserverweb

ECHO successfully pushed to dockerhub

CD Coderr.Server.Web
DEL Dockerfile
CD ..
DEL docker-compose.yml
DEL docker-compose.override.yml

ECHO Completed!
PAUSE
25 changes: 25 additions & 0 deletions src/Server/BuildAndPushWinImage.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
COPY docker-compose_windows.yml docker-compose.yml
COPY docker-compose_windows.override.yml docker-compose.override.yml
CD Coderr.Server.Web
COPY Dockerfile_Windows Dockerfile

CD ..

CALL BuildFrontend.bat

docker-compose build

ECHO built successfully

docker push coderrio/win_coderrserverweb

ECHO successfully pushed to dockerhub

CD Coderr.Server.Web
DEL Dockerfile
CD ..
DEL docker-compose.yml
DEL docker-compose.override.yml

ECHO Completed!
PAUSE
6 changes: 6 additions & 0 deletions src/Server/BuildFrontend.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CD Coderr.Server.Web

call npm ci
call node node_modules/webpack/bin/webpack.js --config webpack.config.prod.js --mode=production

CD ..
35 changes: 35 additions & 0 deletions src/Server/Coderr.Server.Web/Dockerfile_Linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#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:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["Coderr.Server.Web/Coderr.Server.Web.csproj", "Coderr.Server.Web/"]
COPY ["Coderr.Server.Abstractions/Coderr.Server.Abstractions.csproj", "Coderr.Server.Abstractions/"]
COPY ["Coderr.Server.Api/Coderr.Server.Api.csproj", "Coderr.Server.Api/"]
COPY ["Coderr.Server.Infrastructure/Coderr.Server.Infrastructure.csproj", "Coderr.Server.Infrastructure/"]
COPY ["Coderr.Server.App/Coderr.Server.App.csproj", "Coderr.Server.App/"]
COPY ["Coderr.Server.ReportAnalyzer.Abstractions/Coderr.Server.ReportAnalyzer.Abstractions.csproj", "Coderr.Server.ReportAnalyzer.Abstractions/"]
COPY ["Coderr.Server.Domain/Coderr.Server.Domain.csproj", "Coderr.Server.Domain/"]
COPY ["Coderr.Server.ReportAnalyzer/Coderr.Server.ReportAnalyzer.csproj", "Coderr.Server.ReportAnalyzer/"]
COPY ["Coderr.Server.SqlServer/Coderr.Server.SqlServer.csproj", "Coderr.Server.SqlServer/"]
RUN dotnet restore "Coderr.Server.Web/Coderr.Server.Web.csproj"
COPY . .
WORKDIR "/src/Coderr.Server.Web"
RUN dotnet build "Coderr.Server.Web.csproj" -c Release -o /app/build

WORKDIR /src
COPY Coderr.Server.Web/wwwroot Coderr.Server.Web/wwwroot


WORKDIR "/src/Coderr.Server.Web"

FROM build AS publish
RUN dotnet publish "Coderr.Server.Web.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Coderr.Server.Web.dll"]
40 changes: 40 additions & 0 deletions src/Server/Coderr.Server.Web/Dockerfile_Windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY ["Coderr.Server.Web/Coderr.Server.Web.csproj", "Coderr.Server.Web/"]
COPY ["Coderr.Server.Abstractions/Coderr.Server.Abstractions.csproj", "Coderr.Server.Abstractions/"]
COPY ["Coderr.Server.Api/Coderr.Server.Api.csproj", "Coderr.Server.Api/"]
COPY ["Coderr.Server.Infrastructure/Coderr.Server.Infrastructure.csproj", "Coderr.Server.Infrastructure/"]
COPY ["Coderr.Server.App/Coderr.Server.App.csproj", "Coderr.Server.App/"]
COPY ["Coderr.Server.ReportAnalyzer.Abstractions/Coderr.Server.ReportAnalyzer.Abstractions.csproj", "Coderr.Server.ReportAnalyzer.Abstractions/"]
COPY ["Coderr.Server.Domain/Coderr.Server.Domain.csproj", "Coderr.Server.Domain/"]
COPY ["Coderr.Server.ReportAnalyzer/Coderr.Server.ReportAnalyzer.csproj", "Coderr.Server.ReportAnalyzer/"]
COPY ["Coderr.Server.SqlServer/Coderr.Server.SqlServer.csproj", "Coderr.Server.SqlServer/"]

RUN dotnet restore "Coderr.Server.Web/Coderr.Server.Web.csproj"

COPY . .
WORKDIR "/src/Coderr.Server.Web"
RUN dotnet build "Coderr.Server.Web.csproj" -c Release -o /app/build

WORKDIR /src

COPY Coderr.Server.Web/wwwroot Coderr.Server.Web/wwwroot

WORKDIR "/src/Coderr.Server.Web"

FROM build AS publish
RUN dotnet publish "Coderr.Server.Web.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Coderr.Server.Web.dll"]
8 changes: 6 additions & 2 deletions src/Server/Coderr.Server.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public class Startup

public Startup(IConfiguration configuration)
{
Configuration = configuration;
_moduleStarter = new ModuleStarter(configuration);
Configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddConfiguration(configuration)
.Build();

_moduleStarter = new ModuleStarter(Configuration);
}

public static IConfiguration Configuration { get; private set; }
Expand Down
15 changes: 15 additions & 0 deletions src/Server/docker-compose_linux.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.7'

services:
coderr.server.web:
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=50473
networks:
- coderr_network
ports:
- "2500:80"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
18 changes: 18 additions & 0 deletions src/Server/docker-compose_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.7'

services:
coderr.server.web:
image: coderrio/coderrserverweb
build:
context: .
dockerfile: Coderr.Server.Web/Dockerfile
networks:
- coderr_network

volumes:
esdata:
driver: local

networks:
coderr_network:
name: coderr_network
14 changes: 14 additions & 0 deletions src/Server/docker-compose_windows.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.7'

services:
coderr.server.web:
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=50473
networks:
- coderr_network_win
ports:
- "2500:80"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
18 changes: 18 additions & 0 deletions src/Server/docker-compose_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.7'

services:
coderr.server.web:
image: coderrio/win_coderrserverweb
build:
context: .
dockerfile: Coderr.Server.Web/Dockerfile
networks:
- coderr_network_win

volumes:
esdata:
driver: local

networks:
coderr_network_win:
name: coderr_network_win

0 comments on commit 3936f1c

Please sign in to comment.