Skip to content

se agrega dockerfile y docker-compose con scripts de inicialización #1

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

Open
wants to merge 1 commit 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
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ services.AddSingleton<IClientSettingsService, ClientSettingsServiceMongoDB>();

![](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
<p>
Expand Down
15 changes: 15 additions & 0 deletions appsettings.docker.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
db.createUser(
{
user: "usrapi",
pwd: "UserApi123$",
roles: [
{
role: "readWrite",
db: "ClientesStoreDb"
}
]
}
);