Skip to content

Commit

Permalink
generated by yo docker
Browse files Browse the repository at this point in the history
  • Loading branch information
NewGyu committed Dec 27, 2016
1 parent 03cd32a commit 2c3877d
Show file tree
Hide file tree
Showing 11 changed files with 582 additions and 30 deletions.
39 changes: 39 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,39 @@
{
"version": "0.2.0",
"configurations": [
{
"name":".NET Core Docker Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "composeForDebug",
"cwd": "/app",
"program": "/app/dotnet-core.dll",
"sourceFileMap": {
"/app": "${workspaceRoot}"
},

"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
}
},

"pipeTransport": {
"pipeProgram": "/bin/bash",
"pipeCwd": "${workspaceRoot}",
"pipeArgs": [ "-c", "./dockerTask.sh startDebugging" ],
"windows": {
"pipeProgram": "${env.windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"pipeCwd": "${workspaceRoot}",
"pipeArgs": [ ".\\dockerTask.ps1", "-StartDebugging" ]
}
}
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,5 @@
{
"files.associations": {
"dockerfile.*": "dockerfile"
}
}
66 changes: 66 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,66 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"windows": {
"command": "powershell",
"options": {
"cwd": "${workspaceRoot}"
},
"tasks": [
{
"taskName": "build",
"suppressTaskName": true,
"args": ["-ExecutionPolicy", "RemoteSigned", ".\\dockerTask.ps1", "-Build", "-Environment", "debug" ],
"isBuildCommand": true,
"showOutput": "always",
"echoCommand": true
},
{
"taskName": "compose",
"suppressTaskName": true,
"args": ["-ExecutionPolicy", "RemoteSigned", ".\\dockerTask.ps1", "-Compose", "-Environment", "debug" ],
"isBuildCommand": false,
"showOutput": "always",
"echoCommand": true
},
{
"taskName": "composeForDebug",
"suppressTaskName": true,
"args": ["-ExecutionPolicy", "RemoteSigned", ".\\dockerTask.ps1", "-ComposeForDebug", "-Environment", "debug" ],
"isBuildCommand": false,
"showOutput": "always",
"echoCommand": true
}
]
},
"osx": {
"command": "/bin/bash",
"options": {
"cwd": "${workspaceRoot}"
},
"tasks": [
{
"taskName": "build",
"suppressTaskName": true,
"args": [ "-c", "./dockerTask.sh build debug" ],
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "compose",
"suppressTaskName": true,
"args": [ "-c", "./dockerTask.sh compose debug" ],
"isBuildCommand": false,
"showOutput": "always"
},
{
"taskName": "composeForDebug",
"suppressTaskName": true,
"args": [ "-c", "./dockerTask.sh composeForDebug debug" ],
"isBuildCommand": false,
"showOutput": "always"
}
]
}
}
21 changes: 5 additions & 16 deletions Dockerfile
@@ -1,17 +1,6 @@
FROM microsoft/dotnet:latest

RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*

COPY . /app

FROM microsoft/dotnet:1.0.0-core
WORKDIR /app

RUN ["dotnet", "restore"]

RUN ["dotnet", "build"]

RUN ["dotnet", "ef", "database", "update"]

EXPOSE 5000/tcp

CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
ENTRYPOINT ["dotnet", "dotnet-core.dll"]
COPY . /app
13 changes: 13 additions & 0 deletions Dockerfile.debug
@@ -0,0 +1,13 @@
FROM microsoft/dotnet:1.0.0-preview2-sdk
ENV NUGET_XMLDOC_MODE skip
ARG CLRDBG_VERSION=VS2015U2
WORKDIR /clrdbg
RUN curl -SL https://raw.githubusercontent.com/Microsoft/MIEngine/getclrdbg-release/scripts/GetClrDbg.sh --output GetClrDbg.sh \
&& chmod 700 GetClrDbg.sh \
&& ./GetClrDbg.sh $CLRDBG_VERSION \
&& rm GetClrDbg.sh
WORKDIR /app
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
ENTRYPOINT ["/bin/bash", "-c", "if [ -z \"$REMOTE_DEBUGGING\" ]; then dotnet dotnet-core.dll; else sleep infinity; fi"]
COPY . /app
12 changes: 12 additions & 0 deletions docker-compose.debug.yml
@@ -0,0 +1,12 @@
version: '2'

services:
dotnet-core:
image: dotnet-core:debug
build:
context: .
dockerfile: Dockerfile.debug
ports:
- "5000:5000"
environment:
- REMOTE_DEBUGGING
10 changes: 10 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,10 @@
version: '2'

services:
dotnet-core:
image: dotnet-core
build:
context: .
dockerfile: Dockerfile
ports:
- "5000:5000"
160 changes: 160 additions & 0 deletions dockerTask.ps1
@@ -0,0 +1,160 @@
<#
.SYNOPSIS
Builds and runs a Docker image.
.PARAMETER Compose
Runs docker-compose.
.PARAMETER Build
Builds a Docker image.
.PARAMETER Clean
Removes the image dotnet-core and kills all containers based on that image.
.PARAMETER ComposeForDebug
Builds the image and runs docker-compose.
.PARAMETER StartDebugging
Finds the running container and starts the debugger inside of it.
.PARAMETER Environment
The enviorment to build for (Debug or Release), defaults to Debug
.EXAMPLE
C:\PS> .\dockerTask.ps1 -Build
Build a Docker image named dotnet-core
#>

Param(
[Parameter(Mandatory=$True,ParameterSetName="Compose")]
[switch]$Compose,
[Parameter(Mandatory=$True,ParameterSetName="ComposeForDebug")]
[switch]$ComposeForDebug,
[Parameter(Mandatory=$True,ParameterSetName="StartDebugging")]
[switch]$StartDebugging,
[Parameter(Mandatory=$True,ParameterSetName="Build")]
[switch]$Build,
[Parameter(Mandatory=$True,ParameterSetName="Clean")]
[switch]$Clean,
[parameter(ParameterSetName="Compose")]
[Parameter(ParameterSetName="ComposeForDebug")]
[parameter(ParameterSetName="Build")]
[parameter(ParameterSetName="Clean")]
[ValidateNotNullOrEmpty()]
[String]$Environment = "Debug"
)

$imageName="dotnet-core"
$projectName="dotnetcore"
$serviceName="dotnet-core"
$containerName="${projectName}_${serviceName}_1"
$publicPort=5000
$url="http://localhost:$publicPort"
$runtimeID = "debian.8-x64"
$framework = "netcoreapp1.0"

# Kills all running containers of an image and then removes them.
function CleanAll () {
$composeFileName = "docker-compose.yml"
if ($Environment -ne "Release") {
$composeFileName = "docker-compose.$Environment.yml"
}

if (Test-Path $composeFileName) {
docker-compose -f "$composeFileName" -p $projectName down --rmi all

$danglingImages = $(docker images -q --filter 'dangling=true')
if (-not [String]::IsNullOrWhiteSpace($danglingImages)) {
docker rmi -f $danglingImages
}
}
else {
Write-Error -Message "$Environment is not a valid parameter. File '$composeFileName' does not exist." -Category InvalidArgument
}
}

# Builds the Docker image.
function BuildImage () {
$composeFileName = "docker-compose.yml"
if ($Environment -ne "Release") {
$composeFileName = "docker-compose.$Environment.yml"
}

if (Test-Path $composeFileName) {
Write-Host "Building the project ($ENVIRONMENT)."
$pubFolder = "bin\$Environment\$framework\publish"
dotnet publish -f $framework -r $runtimeID -c $Environment -o $pubFolder

Write-Host "Building the image $imageName ($Environment)."
docker-compose -f "$pubFolder\$composeFileName" -p $projectName build
}
else {
Write-Error -Message "$Environment is not a valid parameter. File '$composeFileName' does not exist." -Category InvalidArgument
}
}

# Runs docker-compose.
function Compose () {
$composeFileName = "docker-compose.yml"
if ($Environment -ne "Release") {
$composeFileName = "docker-compose.$Environment.yml"
}

if (Test-Path $composeFileName) {
Write-Host "Running compose file $composeFileName"
docker-compose -f $composeFileName -p $projectName kill
docker-compose -f $composeFileName -p $projectName up -d
}
else {
Write-Error -Message "$Environment is not a valid parameter. File '$dockerFileName' does not exist." -Category InvalidArgument
}
}

function StartDebugging () {
Write-Host "Running on $url"

$containerId = (docker ps -f "name=$containerName" -q -n=1)
if ([System.String]::IsNullOrWhiteSpace($containerId)) {
Write-Error "Could not find a container named $containerName"
}

docker exec -i $containerId /clrdbg/clrdbg --interpreter=mi
}

# Opens the remote site
function OpenSite () {
Write-Host "Opening site" -NoNewline
$status = 0

#Check if the site is available
while($status -ne 200) {
try {
$response = Invoke-WebRequest -Uri $url -Headers @{"Cache-Control"="no-cache";"Pragma"="no-cache"} -UseBasicParsing
$status = [int]$response.StatusCode
}
catch [System.Net.WebException] { }
if($status -ne 200) {
Write-Host "." -NoNewline
Start-Sleep 1
}
}

Write-Host
# Open the site.
Start-Process $url
}

$Environment = $Environment.ToLowerInvariant()

# Call the correct function for the parameter that was used
if($Compose) {
Compose
OpenSite
}
elseif($ComposeForDebug) {
$env:REMOTE_DEBUGGING = 1
BuildImage
Compose
}
elseif($StartDebugging) {
StartDebugging
}
elseif($Build) {
BuildImage
}
elseif ($Clean) {
CleanAll
}

0 comments on commit 2c3877d

Please sign in to comment.