Skip to content
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

Added docker support for debugging #2298

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set default behavior to automatically normalize line endings.
* text=auto

# Always convert bash script line endings to LF on checkout.
*.sh text eol=lf
12 changes: 12 additions & 0 deletions AllReadyApp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.dockerignore
.env
.git
.gitignore
.vs
.vscode
docker-compose.yml
docker-compose.*.yml
*/bin
*/obj
!obj/Docker/publish/*
!obj/Docker/empty/
24 changes: 24 additions & 0 deletions AllReadyApp/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug in Docker",
"type": "coreclr",
"request": "launch",
"program": "/app/Web-App/AllReady/bin/Debug/netcoreapp2.0/AllReady.dll",
"cwd": "/app/Web-App/AllReady",
"sourceFileMap": {
"/app": "${workspaceRoot}"
},
"pipeTransport": {
"pipeProgram": "docker",
"pipeCwd": "${workspaceRoot}",
"pipeArgs": [
"exec -i allreadyweb"
],
"quoteArgs": false,
"debuggerPath": "/root/vsdbg/vsdbg"
}
}
]
}
30 changes: 30 additions & 0 deletions AllReadyApp/Web-App/AllReady/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM microsoft/aspnetcore-build:2.0

#Install debugger
RUN apt-get update
RUN apt-get install curl -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg

# Install npm packages
WORKDIR /app/Web-App/AllReady
COPY Web-App/AllReady/package.json .
COPY Web-App/AllReady/package-lock.json .
RUN ["npm", "install"]

# Run dotnet restore
WORKDIR /app
COPY *.sln ./
COPY Web-App/AllReady/AllReady.csproj Web-App/AllReady/
COPY AllReady.Core/AllReady.Core.csproj AllReady.Core/
RUN dotnet restore AllReadyWebOnly.sln
COPY . .
WORKDIR /app/Web-App/AllReady

# Build project
RUN ["dotnet","build"]

# Run gulp tasks
RUN gulp clean && gulp min
EXPOSE 80/tcp
RUN chmod +x ../../entrypoint.sh
CMD /bin/bash ../../entrypoint.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CMD /bin/bash ../../entrypoint.sh
CMD /bin/bash "dotnet ef database update && dotnet AllReady.dll"

Instead of having a whole separate file (entrypoint.sh) I believe we could just simply chain the migration and the app start. That we we can drop the .sh file and also the end-of-line issues discussed in the PR comments.

12 changes: 12 additions & 0 deletions AllReadyApp/Web-App/AllReady/Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM microsoft/aspnetcore-build:2.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mk0sojo This whole dockerfile seems to do nothing more than just install the vs debugger and then on startup just keep the process running. What purpose does it serve?

RUN mkdir app

#Install debugger
RUN apt-get update
RUN apt-get install curl -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg

EXPOSE 80/tcp

#Keep the debugger container on
ENTRYPOINT ["tail", "-f", "/dev/null"]
3 changes: 1 addition & 2 deletions AllReadyApp/Web-App/AllReady/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)

//Hangfire
services.AddHangfire(configuration => configuration.UseSqlServerStorage(Configuration["Data:HangfireConnection:ConnectionString"]));

services.AddScoped<IAllReadyUserManager, AllReadyUserManager>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems to only have whitespace changes - perhaps it could be excluded/rolled-back from the PR (i.e. github checkout origin/master -- AllReadyApp/Web-App/AllReady/Startup.cs)

services.AddScoped<IUserAuthorizationService, UserAuthorizationService>();
services.AddScoped<IAuthorizableEventBuilder, AuthorizableEventBuilder>();
Expand All @@ -184,7 +184,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, AllReady
{
// Put first to avoid issues with OPTIONS when calling from Angular/Browser.
app.UseCors("allReady");

app.UseSession();

// Add the following to the request pipeline only in development environment.
Expand Down
2 changes: 1 addition & 1 deletion AllReadyApp/Web-App/AllReady/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=AllReady;Integrated Security=true;MultipleActiveResultsets=true;"
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=AllReady;Integrated Security=true;MultipleActiveResultsets=true;"
},
"HangfireConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=AllReady;Integrated Security=true;MultipleActiveResultsets=true;"
Expand Down
28 changes: 28 additions & 0 deletions AllReadyApp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3"
services:
web:
build:
context: .
dockerfile: Web-App/AllReady/Dockerfile
container_name: allreadyweb
environment:
ASPNETCORE_ENVIRONMENT: Development
Data__DefaultConnection__ConnectionString: "Server=db,1433;Initial Catalog=master;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
Data__HangfireConnection__ConnectionString: "Server=db,1433;Initial Catalog=master;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
ports:
- "8000:80"
depends_on:
- db

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the db container takes a bit of time to spin up, I'd suggest adding

restart: on-failure

So that docker could retry starting the app if the db is not yet up and running.

db:
image: "microsoft/mssql-server-linux:2017-CU3"
container_name: allreadysqlserver
volumes:
- sql-server-data:/var/opt/mssql
ports:
- "1433:1433"
environment:
SA_PASSWORD: "yourStrong(!)Password"
ACCEPT_EULA: "Y"

volumes:
sql-server-data:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I could not see where is the logic that actually creates the database table AllReady like done in the appveyor run script

allReady/appveyor.yml

Lines 46 to 47 in 37833fc

- ps: cd (Join-Path $env:APPVEYOR_BUILD_FOLDER "AllReadyApp\Web-App\AllReady")
- ps: sqlcmd -S "(local)\SQL2016" -Q "Use [master]; CREATE DATABASE [AllReady]"
for example

11 changes: 11 additions & 0 deletions AllReadyApp/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e
run_cmd="tail -f /dev/null"
until dotnet ef database update; do
>&2 echo "SQL Server is starting up"
sleep 1
done

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems to only run the migration and does not actually start the app. i.e. dotnet AllReady.dll is nowhere to be seen...

>&2 echo "App and SQL Server is running"
exec $run_cmd