From ba2b247356f0c735413cb97c119fb0a18a8c0a44 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 5 Apr 2017 15:37:48 -0700 Subject: [PATCH] Add docker-compose file and README for Swarm --- README.md | 36 +++++++++++++-- README.swarm.md | 29 ++++++++++++ docker-compose.swarm.yml | 99 ++++++++++++++++++++++++++++++++++++++++ swarm/Dockerfile | 2 + swarm/nginx.conf | 80 ++++++++++++++++++++++++++++++++ 5 files changed, 242 insertions(+), 4 deletions(-) create mode 100644 README.swarm.md create mode 100644 docker-compose.swarm.yml create mode 100644 swarm/Dockerfile create mode 100644 swarm/nginx.conf diff --git a/README.md b/README.md index ad3de086b..0e7c24a65 100644 --- a/README.md +++ b/README.md @@ -77,23 +77,51 @@ This is the more straightforward way to get started: https://github.com/dotnet/eShopOnContainers/wiki/02.-Setting-eShopOnContainer-solution-up-in-a-Visual-Studio-2017-environment ### CLI and Windows based -For those who prefer the CLI on Windows, using dotnet CLI, docker CLI and VS Code for Windows: +For those who prefer the CLI on Windows, using dotnet CLI, docker CLI and VS Code for Windows: https://github.com/dotnet/eShopOnContainers/wiki/03.-Setting-the-eShopOnContainers-solution-up-in-a-Windows-CLI-environment-(dotnet-CLI,-Docker-CLI-and-VS-Code) ### CLI and Mac based -For those who prefer the CLI on a Mac, using dotnet CLI, docker CLI and VS Code for Mac +For those who prefer the CLI on a Mac, using dotnet CLI, docker CLI and VS Code for Mac (Instructions still TBD, but similar to Windows CLI): https://github.com/dotnet/eShopOnContainers/wiki/04.-Setting-eShopOnContainer-solution-up-in-a-Mac,-VS-Code-and-CLI-environment--(dotnet-CLI,-Docker-CLI-and-VS-Code) > ### Note on tested Docker Containers/Images -> Most of the development and testing of this project was (as of early March 2017) done on Docker Linux containers running in development machines with "Docker for Windows" and the default Hyper-V Linux VM (MobiLinuxVM) installed by "Docker for Windows". +> Most of the development and testing of this project was (as of early March 2017) done on Docker Linux containers running in development machines with "Docker for Windows" and the default Hyper-V Linux VM (MobiLinuxVM) installed by "Docker for Windows". The Windows Containers scenario is currently being implemented/tested yet. The application should be able to run on Windows Nano Containers based on different Docker base images, as well, as the .NET Core services have also been tested running on plain Windows (with no Docker). The app was also partially tested on "Docker for Mac" using a development MacOS machine with .NET Core and VS Code installed, which is still a scenario using Linux containers running on the VM setup in the Mac by the "Docker for Windows" setup. But further testing and feedback on Mac environments and Windows Containers, from the community, will be appreciated. +## Docker Swarm +### Prerequisites +1. A Docker Swarm cluster ([Azure Container Service](https://docs.microsoft.com/en-us/azure/container-service/container-service-deployment)) +1. Docker tooling, including docker-compose, on your development machine ([docker.com](https://www.docker.com/)) + +### Deploying to a Swarm Cluster +1. Open a command line to your local eShopOnContainers repository. +2. Restore and publish the projects: +>``` +>dotnet restore eShopOnContainers-ServicesAndWebApps.sln +>dotnet publish eShopOnContainers-ServicesAndWebApps.sln -c Release -o ./obj/Docker/publish +>``` +3. Create an SSH tunnel to your cluster's master node (See [Connect with an ACS cluster](https://docs.microsoft.com/en-us/azure/container-service/container-service-connect#connect-to-a-dcos-or-swarm-cluster)) +4. Set `SWARM_AGENTS_FQDN` to the domain name of your swarm agents' load balancer. This is of the form `[dns prefix]agents.[azure region].cloudapp.azure.com` (it can also be found in the Azure portal). For example: +>```bash +>export SWARM_AGENTS_FQDN=myswarmclusteragents.centralus.cloudapp.azure.com +>``` +Or, in PowerShell: +>```powershell +>$env:SWARM_AGENTS_FQDN='myswarmclusteragents.centralus.cloudapp.azure.com' +>``` +5. Deploy eShopOnContainers with `docker-compose`: +>``` +>docker-compose -f docker-compose.yml -f docker-compose.swarm.yml up -d +>``` +### Further Reading +* Docker: [Swarm mode overview](https://docs.docker.com/engine/swarm/) + ## Sending feedback and pull requests As mentioned, we'd appreciate to your feedback, improvements and ideas. You can create new issues at the issues section, do pull requests and/or send emails to **eshop_feedback@service.microsoft.com** ## Questions [QUESTION] Answer +1 if the solution is working for you (Through VS2017 or CLI environment): -https://github.com/dotnet/eShopOnContainers/issues/107 +https://github.com/dotnet/eShopOnContainers/issues/107 diff --git a/README.swarm.md b/README.swarm.md new file mode 100644 index 000000000..2211e795b --- /dev/null +++ b/README.swarm.md @@ -0,0 +1,29 @@ +# eShopOnContainers on Docker Swarm + +## Prerequisites +1. A Docker Swarm cluster ([Azure Container Service](https://docs.microsoft.com/en-us/azure/container-service/container-service-deployment)) +1. Docker tooling, including docker-compose, on your development machine ([docker.com](https://www.docker.com/)) + +## Deploying to a Swarm Cluster +1. Open a command line to your local eShopOnContainers repository. +2. Restore and publish the projects: +>``` +>dotnet restore eShopOnContainers-ServicesAndWebApps.sln +>dotnet publish eShopOnContainers-ServicesAndWebApps.sln -c Release -o ./obj/Docker/publish +>``` +3. Create an SSH tunnel to your cluster's master node (See [Connect with an ACS cluster](https://docs.microsoft.com/en-us/azure/container-service/container-service-connect#connect-to-a-dcos-or-swarm-cluster)) +4. Set `SWARM_AGENTS_FQDN` to the domain name of your swarm agents' load balancer. This is of the form `[dns prefix]agents.[azure region].cloudapp.azure.com` (it can also be found in the Azure portal). For example: +>```bash +>export SWARM_AGENTS_FQDN=myswarmclusteragents.centralus.cloudapp.azure.com +>``` +Or, in PowerShell: +>```powershell +>$env:SWARM_AGENTS_FQDN='myswarmclusteragents.centralus.cloudapp.azure.com' +>``` +5. Deploy eShopOnContainers with `docker-compose`: +>``` +>docker-compose -f docker-compose.yml -f docker-compose.swarm.yml up -d +>``` + +## Further Reading +* Docker: [Swarm mode overview](https://docs.docker.com/engine/swarm/) diff --git a/docker-compose.swarm.yml b/docker-compose.swarm.yml new file mode 100644 index 000000000..d2d0d3002 --- /dev/null +++ b/docker-compose.swarm.yml @@ -0,0 +1,99 @@ +version: '2' + +services: + basket.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80/basket-api + - ConnectionString=basket.data + - IdentityUrl=http://${SWARM_AGENTS_FQDN}/identity + - EventBusConnection=rabbitmq + ports: + - "5100:80" + + catalog.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80/catalog-api + - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word + - ExternalCatalogBaseUrl=http://${SWARM_AGENTS_FQDN}/catalog-api + - EventBusConnection=rabbitmq + ports: + - "5101:80" + + frontend: + build: + context: ./swarm + depends_on: + - basket.api + - catalog.api + - identity.api + - ordering.api + - webmvc + - webspa + - webstatus + ports: + - "80:8080" + + identity.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80/identity + - SpaClient=http://${SWARM_AGENTS_FQDN} + - ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word + - MvcClient=http://${SWARM_AGENTS_FQDN}/webmvc + ports: + - "5102:80" + + ordering.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80/ordering-api + - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word + - IdentityUrl=http://${SWARM_AGENTS_FQDN}/identity + - BasketUrl=http://${SWARM_AGENTS_FQDN}/basket-api + - EventBusConnection=rabbitmq + ports: + - "5103:80" + + webmvc: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80/webmvc + - CatalogUrl=http://${SWARM_AGENTS_FQDN}/catalog-api + - OrderingUrl=http://${SWARM_AGENTS_FQDN}/ordering-api + - BasketUrl=http://${SWARM_AGENTS_FQDN}/basket-api + - IdentityUrl=http://${SWARM_AGENTS_FQDN}/identity + ports: + - "5104:80" + + webspa: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80 + - CatalogUrl=http://${SWARM_AGENTS_FQDN}/catalog-api + - OrderingUrl=http://${SWARM_AGENTS_FQDN}/ordering-api + - IdentityUrl=http://${SWARM_AGENTS_FQDN}/identity + - BasketUrl=http://${SWARM_AGENTS_FQDN}/basket-api + ports: + - "5105:80" + + sql.data: + environment: + - SA_PASSWORD=Pass@word + - ACCEPT_EULA=Y + ports: + - "1433:1433" + + webstatus: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80/webstatus + - CatalogUrl=http://${SWARM_AGENTS_FQDN}/catalog-api + - OrderingUrl=http://${SWARM_AGENTS_FQDN}/ordering-api + - BasketUrl=http://${SWARM_AGENTS_FQDN}/basket-api + - IdentityUrl=http://${SWARM_AGENTS_FQDN}/identity + - mvc=http://${SWARM_AGENTS_FQDN}/webmvc + - spa=http://${SWARM_AGENTS_FQDN} + ports: + - "5106:80" diff --git a/swarm/Dockerfile b/swarm/Dockerfile new file mode 100644 index 000000000..ad71a0db0 --- /dev/null +++ b/swarm/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:1.10.3-alpine +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/swarm/nginx.conf b/swarm/nginx.conf new file mode 100644 index 000000000..32a198f2a --- /dev/null +++ b/swarm/nginx.conf @@ -0,0 +1,80 @@ +pid /tmp/nginx.pid; + +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + server_tokens off; + + add_header X-Frame-Options SAMEORIGIN; + add_header X-Content-Type-Options nosniff; + add_header X-XSS-Protection "1; mode=block"; + + client_body_temp_path /tmp/client_body; + fastcgi_temp_path /tmp/fastcgi_temp; + proxy_temp_path /tmp/proxy_temp; + scgi_temp_path /tmp/scgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + + gzip on; + gzip_comp_level 6; + gzip_min_length 1024; + gzip_buffers 4 32k; + gzip_types text/plain application/javascript text/css; + gzip_vary on; + + keepalive_timeout 65; + + proxy_buffer_size 128k; + proxy_buffers 4 256k; + proxy_busy_buffers_size 256k; + + server { + listen 8080; + + location /basket-api { + proxy_pass http://basket.api; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /catalog-api { + proxy_pass http://catalog.api; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /identity { + proxy_pass http://identity.api; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /ordering-api { + proxy_pass http://ordering.api; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /webmvc { + proxy_pass http://webmvc; + proxy_redirect off; + proxy_set_header Host $host; + } + + location /webstatus { + proxy_pass http://webstatus; + proxy_redirect off; + proxy_set_header Host $host; + } + + location / { + proxy_pass http://webspa; + proxy_redirect off; + proxy_set_header Host $host; + } + } +}