Skip to content

Commit

Permalink
Start application via docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pdany1116 committed Jun 25, 2023
1 parent ee2aa5d commit cfb1fc4
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 30 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
COPY . .

RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /app/out .

EXPOSE 5000
ENTRYPOINT ["dotnet", "is-iot-web.dll"]
13 changes: 9 additions & 4 deletions Mqtt/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ public MqttClient(IMqttSettings mqttSettings)
{
_mqttSettings = mqttSettings;
_mqttClient = new MqttFactory().CreateMqttClient();
_mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer(_mqttSettings.BrokerHost, _mqttSettings.BrokerPort)
.WithCredentials(_mqttSettings.User, _mqttSettings.Password)
.Build();
var mqttClientOptionsBuilder = new MqttClientOptionsBuilder()
.WithTcpServer(_mqttSettings.BrokerHost, _mqttSettings.BrokerPort);

if (_mqttSettings.WithCredentials)
{
mqttClientOptionsBuilder.WithCredentials(_mqttSettings.User, _mqttSettings.Password);
}

_mqttClientOptions = mqttClientOptionsBuilder.Build();
}

public async Task Connect()
Expand Down
27 changes: 5 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,9 @@ Users are allowed:
13. [ ] To configure automated irrigation process.
14. [ ] To configure the sink module.

### System requirements
1. Windows 10.
2. Visual Studio 2022 Community with C#.
2. .NET 5 SDK.
3. ASP.NET and web development workload (can be installed from Visual Studio Installer).
## Linux Setup
1. `git clone https://github.com/pdany1116/is-iot-sink.git`
1. `cp appsettings.example.json appsettings.json`
2. `docker compose up`

### Clone repository
```
git clone https://github.com/pdany1116/is-iot-sink.git
```
or download as ZIP and extract.

### Configure application settings
#### Change default values
```
cp appsettings.example.json appsettings.json
```
`Note: Replace MongoDB, MQTT and AccuWeather settings with your values. All variables need to be defined!!!`

### Open solution with Visual Studio 2022.
### Clean and build solution.
### Restore nuget packages.
### Deploy with IIS Express.
The app is running at: http://localhost:5000
1 change: 1 addition & 0 deletions Settings/IMqttSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface IMqttSettings
int BrokerPort { get; set; }
string User { get; set; }
string Password { get; set; }
bool WithCredentials { get; set; }
}
}
1 change: 1 addition & 0 deletions Settings/MqttSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class MqttSettings : IMqttSettings
public int BrokerPort { get; set; }
public string User { get; set; }
public string Password { get; set; }
public bool WithCredentials { get; set; }
}
}
9 changes: 5 additions & 4 deletions appsettings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
},
"AllowedHosts": "*",
"MongoDbSettings": {
"ConnectionString": "mongodb://<username>:<password>@<host>:<port>/",
"DatabaseName": "<Database Name>"
"ConnectionString": "mongodb://root:example@mongo:27017/",
"DatabaseName": "development"
},
"MqttSettings": {
"BrokerHost": "<MQTT Broker host(IPv4 address, domain or hostname)>",
"BrokerPort": <port>,
"BrokerHost": "broker.emqx.io",
"BrokerPort": "1883",
"WithCredentials": false,
"User": "<username>",
"Password": "<password>"
},
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
version: '3.1'

services:
web:
build: .
ports:
- 5000:80

mongo:
image: mongo
restart: always
Expand Down
1 change: 1 addition & 0 deletions is-iot-web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>IsIoTWeb</RootNamespace>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit cfb1fc4

Please sign in to comment.