diff --git a/.vscode/launch.json b/.vscode/launch.json index 7fdfeb9..f0f2374 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,15 @@ // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md "version": "0.2.0", "configurations": [ + { + "name": "Docker .NET Core Attach (Preview)", + "type": "docker", + "request": "attach", + "platform": "netCore", + "sourceFileMap": { + "/app": "${workspaceFolder}" + } + }, { "name": ".NET Core Launch (web)", "type": "coreclr", diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7ae1424 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 +WORKDIR /app +COPY --from=build-env /app/out . + +# Run specific docker configuration +RUN cp appsettings.docker.json appsettings.json +ENTRYPOINT ["dotnet", "webapi.mongodb.dll"] \ No newline at end of file diff --git a/README.md b/README.md index 242ac1a..5899339 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,27 @@ services.AddSingleton(); ![](https://raw.githubusercontent.com/programando-ideas/webapi.mongodb/master/Imagenes/img_soapui_test.PNG) +## Soporte para docker y docker-compose + +Se agrega docker-compose.yml para poder correr ambas imágenes (webapi.mongodb y mongodb). + +Mediante el script *mongo-init.js* se realiza dentro del contenedor de mongodb la inicialización. + +Pasos para la construcción: + +``` +docker-compose build +``` + +Ejecución: + +``` +docker-compose up +``` + + + + ------------ #### Programando Ideas 2020

diff --git a/appsettings.docker.json b/appsettings.docker.json new file mode 100644 index 0000000..0323406 --- /dev/null +++ b/appsettings.docker.json @@ -0,0 +1,15 @@ +{ + "ClientesStoreDatabaseSettings": { + "ClientesCollectionName": "Clientes", + "ConnectionString": "mongodb://usrapi:UserApi123$@mongodb:27017", + "DatabaseName": "ClientesStoreDb" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8dfe422 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.6" +services: + mongodb: + container_name: mongodb + image: mongo:latest + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root123 + MONGO_INITDB_DATABASE: ClientesStoreDb + ports: + - 27017:27017 + volumes: + - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro + + webapi.mongodb: + container_name: webapi.mongodb + ports: + - 5000:80 + image: webapi.mongodb + build: + context: . + restart: on-failure + depends_on: + - mongodb \ No newline at end of file diff --git a/mongo-init.js b/mongo-init.js new file mode 100644 index 0000000..b585499 --- /dev/null +++ b/mongo-init.js @@ -0,0 +1,12 @@ +db.createUser( + { + user: "usrapi", + pwd: "UserApi123$", + roles: [ + { + role: "readWrite", + db: "ClientesStoreDb" + } + ] + } +); \ No newline at end of file