Was ist die Datei Docker-publish.sh und wie wurde sie erstellt?

292
Love

Ich folgte dem Beispiel, um eine asp.net-Anwendung in einem Docker-Container zu veröffentlichen. Grundsätzlich befindet sich eine Docker-Datei im Ordner PublishProfiles, der in Ihrem Visual Studio-Projekt unter "Eigenschaften" erstellt wird.

Dann können wir den Befehl von PowerShell oder Linux verwenden. Ich verstehe, wie es in PowerShell funktioniert, aber ich verstehe den Befehl von Linux nicht.

cd ProjectFolder (like WebApplication/src/WebApplication) source dnvm.sh dnu restore --no-cache mkdir ~/Temp dnu publish . --out ~/Temp/ --wwwroot-out "wwwroot" --quiet cd Properties/PublishProfiles chmod +x ./Docker-publish.sh ./Docker-publish.sh ./Docker.pubxml ~/Temp/ 

Meine Frage ist, was ist die Datei Docker-publish.shhier und wie wurde sie erstellt?

Ich gehe davon aus, dass es von DNX Utility generiert wurde und warum es einen solchen Namen hat? Was ist dann der Kontext?

0

1 Antwort auf die Frage

0
Love

Ich kann die Antwort finden. Microsoft verwendete, dass Docker-Tools eine SH-Datei generieren können. Danach wurden die Tools jedoch aktualisiert, die Shell-Datei war dann weg. Die neuesten Tools überspringen diese Shell-Datei.

Zum Glück habe ich die alten Werkzeuge gesichert. Es liest eine XML-Datei und führt den Prozess aus.

 #!/bin/bash  # Publish an application to Docker container # Please visit http://go.microsoft.com/fwlink/?LinkID=529706 to learn more about the scirpt  set -e  if ! type docker &>/dev/null; then echo "Unable to find docker command. Please install it first" exit 1 fi  if [ "$#" != "2" ]; then echo "Usage: $0 PubxmlFilePath PackOutputFolderPath" exit 1 fi  pubxmlFilePath="$1"  if [ ! -e "$pubxmlFilePath" ]; then echo "Unable to find publish settings xml file: $pubxmlFilePath" exit 1 fi  packOutputFolderPath="$2"  if [ ! -d "$packOutputFolderPath" ]; then echo "Unable to find pack output folder: $packOutputFolderPath" exit 1 fi  projectName=$(basename "$( cd -P "$(dirname "$pubxmlFilePath" )/../.." && pwd )")  publishProfilesFolderPath=$packOutputFolderPath/approot/src/$projectName/Properties/PublishProfiles  if [ ! -d "$publishProfilesFolderPath" ]; then echo "Unble to find publish profiles folder : $publishProfilesFolderPath." exit 1 fi  # Parse publish settings xml file dockerServerUrl=$(grep -Eo '<DockerServerUrl>.+</DockerServerUrl>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerImageName=$(grep -Eo '<DockerImageName>.+</DockerImageName>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerfileRelativePath=$(grep -Eo '<DockerfileRelativePath>.+</DockerfileRelativePath>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerPublishHostPort=$(grep -Eo '<DockerPublishHostPort>.+</DockerPublishHostPort>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerPublishContainerPort=$(grep -Eo '<DockerPublishContainerPort>.+</DockerPublishContainerPort>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerAuthOptions=$(grep -Eo '<DockerAuthOptions>.+</DockerAuthOptions>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerRunOptions=$(grep -Eo '<DockerRunOptions>.+</DockerRunOptions>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerAppType=$(grep -Eo '<DockerAppType>.+</DockerAppType>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerBuildOnly=$(grep -Eo '<DockerBuildOnly>.+</DockerBuildOnly>' "$pubxmlFilePath" | awk -F'[<>]' '') dockerRemoveConflictingContainers=$(grep -Eo '<DockerRemoveConflictingContainers>.+</DockerRemoveConflictingContainers>' "$pubxmlFilePath" | awk -F'[<>]' '') siteUrlToLaunchAfterPublish=$(grep -Eo '<SiteUrlToLaunchAfterPublish>.+</SiteUrlToLaunchAfterPublish>' "$pubxmlFilePath" | awk -F'[<>]' '') launchSiteAfterPublish=$(grep -Eo '<LaunchSiteAfterPublish>.+</LaunchSiteAfterPublish>' "$pubxmlFilePath" | awk -F'[<>]' '') createWindowsContainer=$(grep -Eo '<CreateWindowsContainer>.+</CreateWindowsContainer>' "$pubxmlFilePath" | awk -F'[<>]' '')  echo "==== Publish Settings ====" echo "DockerServerUrl: $dockerServerUrl" echo "DockerImageName: $dockerImageName" echo "DockerfileRelativePath: $dockerfileRelativePath" echo "DockerPublishHostPort: $dockerPublishHostPort" echo "DockerPublishContainerPort: $dockerPublishContainerPort" echo "DockerAuthOptions: $dockerAuthOptions" echo "DockerRunOptions: $dockerRunOptions" echo "DockerAppType: $dockerAppType" echo "DockerBuildOnly: $dockerBuildOnly" echo "DockerRemoveConflictingContainers: $dockerRemoveConflictingContainers" echo "SiteUrlToLaunchAfterPublish: $siteUrlToLaunchAfterPublish" echo "LaunchSiteAfterPublish: $launchSiteAfterPublish" echo "CreateWindowsContainer: $createWindowsContainer" echo "=========================="  echo "Creating Dockerfile..."  if [ "$dockerfileRelativePath" == "" ]; then dockerfilePath=$publishProfilesFolderPath/Dockerfile else dockerfilePath=$publishProfilesFolderPath/$ fi  if [ ! -e "$dockerfilePath" ]; then echo "Unble to find DockerFile : $dockerFilePath" exit 1 fi  if [ "$dockerRemoveConflictingContainers" == "True" ] && [ $dockerPublishHostPort ]; then echo "Docker command: docker $dockerAuthOptions -H $dockerServerUrl ps -a" if [ "$createWindowsContainer" == "True" ]; then conflictingContainers=$(docker "$dockerAuthOptions" -H "$dockerServerUrl" ps -a | grep "$dockerPublishHostPort_$dockerPublishContainerPort" | awk '') else conflictingContainers=$(docker "$dockerAuthOptions" -H "$dockerServerUrl" ps -a | grep ":$dockerPublishHostPort->" | awk '') fi  if [ $conflictingContainers ]; then echo "Removing conflicting containers: $conflictingContainers" echo "Docker command: docker $dockerAuthOptions -H $dockerServerUrl rm -f $conflictingContainers" if [ "$createWindowsContainer" == "True" ]; then docker "$dockerAuthOptions" -H "$dockerServerUrl" rm -f "$conflictingContainers" || true sleep 3 docker "$dockerAuthOptions" -H "$dockerServerUrl" rm -f "$conflictingContainers" || true else docker "$dockerAuthOptions" -H "$dockerServerUrl" rm -f "$conflictingContainers" fi fi fi  echo "Building docker image $dockerImageName..." echo "Docker command: docker $dockerAuthOptions -H $dockerServerUrl build -t $dockerImageName -f $dockerfilePath $packOutputFolderPath" docker "$dockerAuthOptions" -H "$dockerServerUrl" build -t "$dockerImageName" -f "$dockerfilePath" "$packOutputFolderPath"  if [ "$dockerBuildOnly" == "False" ]; then echo "Starting docker container: $dockerImageName..."  publishPort="" envVars="" containerName=""  if [ $dockerPublishHostPort ] && [ $dockerPublishContainerPort ]; then publishPort=" -p $dockerPublishHostPort:$dockerPublishContainerPort" if [ "$dockerAppType" == "Web" ]; then  envVars=" -e server.urls=http://*:$dockerPublishContainerPort" fi if [ "$createWindowsContainer" == "True" ]; then  containerName=" --name $dockerPublishHostPort_$dockerPublishContainerPort fi fi  echo "Docker command: docker $dockerAuthOptions -H $dockerServerUrl run -t -d$publishPort$envVars $dockerRunOptions $dockerImageName" containerId=$(docker "$dockerAuthOptions" -H "$dockerServerUrl" run -t -d$publishPort$envVars$containerName $dockerRunOptions "$dockerImageName") echo "New container started with id: $containerId"  echo -e "To see standard output from your application, execute the command:\ndocker $dockerAuthOptions -H $dockerServerUrl logs --follow $containerId" echo "Publish completed successfully."  if [ "$launchSiteAfterPublish" == "True" ]; then if [ "$siteUrlToLaunchAfterPublish" == "" ]; then url="http://"$(expr "$dockerServerUrl" : '.*//\(.*\:\)')$dockerPublishHostPort else url=$siteUrlToLaunchAfterPublish fi  echo "Attempting to connect to $url..."  set +e i=0 while [ $i -lt 5 ] do curl -s --head $url --max-time 10 | head -n 1 | grep "HTTP/1.[01] [23]..."  if [ $? == 0 ]; then if [ -e "/Applications/Safari.app" ]; then open -a /Applications/Safari.app $url elif [ -e "/usr/bin/firefox" ]; then firefox $url &>/dev/null & else echo -e "To see the web content, execute the command:\ncurl $url" fi  exit fi  sleep 5 i=$((i+1)) done  logs=$(docker "$dockerAuthOptions" -H "$dockerServerUrl" logs "$containerId") echo -e "Failed to connect to $url. If your Docker host is an Azure virtual machine, please make sure to set up the endpoint $dockerPublishContainerPort using the Azure portal.\nContainer logs:\n$logs\nPlease visit http://go.microsoft.com/fwlink/?LinkID=529706 for troubleshooting guide." fi  else echo "Publish completed successfully. The container was not started because the DockerBuildOnly flag was set to True." fi