Skip to content
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

chore: added docker and docker-compose files, see Readme.md to get details #1

Merged
merged 1 commit into from Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
bin/
obj/
data/
/packages/
### VisualStudio template
## Ignore Visual Studio temporary files, build results, and
Expand Down
18 changes: 18 additions & 0 deletions ReadMe.md
Expand Up @@ -6,6 +6,24 @@ is in development and for a while i'm working on periphery around bot.a
Bot is developed with .NET Core 3.1. But to run it you will be required to have RabbitMQ server and MongoDB. All
configuration could be found in appsettings. To test it in Telegram you will ned a telegram bot token.

# Docker & docker-compose

## Starting docker-compose

If you want to have start all services follow up these commands:
```bash
docker-compose -f YogurtTheBot.ComposeFiles/docker-compose.yml up --build -d
```

## After start (only once)

You have to create an user by after rabbitmq started firstly:
```bash
docker-compose -f YogurtTheBot.ComposeFiles/docker-compose.yml exec rabbitmq rabbitmqctl add_user user user
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move it to Dockerfile?

docker-compose -f YogurtTheBot.ComposeFiles/docker-compose.yml exec rabbitmq rabbitmqctl set_user_tags user administrator
docker-compose -f YogurtTheBot.ComposeFiles/docker-compose.yml exec rabbitmq rabbitmqctl set_permissions -p / user ".*" ".*" ".*"
```

# Projects
A lot of projects, yeah? :)

Expand Down
14 changes: 14 additions & 0 deletions YogurtTheBot.Alice/Dockerfile
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build

COPY ./ /source
WORKDIR /source/YogurtTheBot.Alice
RUN dotnet publish -c Release -f netcoreapp3.1 -o /out

WORKDIR /
RUN rm -rf source
RUN find /out -name "*.pdb" -type f -delete

FROM mcr.microsoft.com/dotnet/core/runtime:3.1 as runtime
WORKDIR /app
COPY --from=build /out ./
ENTRYPOINT ["dotnet", "YogurtTheBot.Alice.dll"]
4 changes: 3 additions & 1 deletion YogurtTheBot.Alice/Services/RabbitService.cs
Expand Up @@ -76,7 +76,9 @@ private void SetupRabbit()
{
var factory = new ConnectionFactory()
{
HostName = _rabbitMqSettings.Value.Hostname
HostName = _rabbitMqSettings.Value.Hostname,
UserName = _rabbitMqSettings.Value.Username,
Password = _rabbitMqSettings.Value.Password
};

_connection = factory.CreateConnection();
Expand Down
4 changes: 3 additions & 1 deletion YogurtTheBot.Alice/appsettings.json
Expand Up @@ -8,7 +8,9 @@
},
"AllowedHosts": "*",
"RabbitMqSettings": {
"Hostname": "localhost",
"Hostname": "rabbitmq",
"Username": "user",
"Password": "user",
"ServersQueue": "incoming_messages",
"MessagesExchange": "messages"
}
Expand Down
1 change: 1 addition & 0 deletions YogurtTheBot.ComposeFiles/Scripts/enabled_plugins
@@ -0,0 +1 @@
[rabbitmq_management].
1 change: 1 addition & 0 deletions YogurtTheBot.ComposeFiles/Scripts/rabbitmq.conf
@@ -0,0 +1 @@
loopback_users = none
48 changes: 48 additions & 0 deletions YogurtTheBot.ComposeFiles/docker-compose.yml
@@ -0,0 +1,48 @@
version: '3.7'
services:
mongo:
logging: &loggingConfig
driver: json-file
image: mongo
restart: always
volumes:
- ../data/mongodb:/data/db
environment:
- MONGO_INITDB_DATABASE=root
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
rabbitmq:
logging: *loggingConfig
hostname: rabbitmq
image: rabbitmq
restart: always
# if you didn't want to share that port then have to delete that below
ports:
- "15672:15672"
- "5672:5672"
volumes:
- ./Scripts/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
- ./Scripts/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
- ../data/rabbitmq:/var/lib/rabbitmq:delegated
yogurt-alice:
build:
context: ../
dockerfile: YogurtTheBot.Alice/Dockerfile
links:
- rabbitmq
restart: always
yogurt-game-server:
build:
context: ../
dockerfile: YogurtTheBot.Game.Server/Dockerfile
links:
- mongo
- rabbitmq
restart: always
yogurt-telegram-polling:
build:
context: ../
dockerfile: YogurtTheBot.Telegram.Polling/Dockerfile
links:
- rabbitmq
restart: always
4 changes: 4 additions & 0 deletions YogurtTheBot.Game.Server.RabbitMq/RabbitMqSettings.cs
Expand Up @@ -4,6 +4,10 @@ public class RabbitMqSettings
{
public string Hostname { get; set; }

public string Username { get; set; }

public string Password { get; set; }

public string ServersQueue { get; set; }

public string MessagesExchange { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions YogurtTheBot.Game.Server/Dockerfile
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build

COPY ./ /source
WORKDIR /source/YogurtTheBot.Game.Server
RUN dotnet publish -c Release -f netcoreapp3.1 -o /out

WORKDIR /
RUN rm -rf source
RUN find /out -name "*.pdb" -type f -delete

FROM mcr.microsoft.com/dotnet/core/runtime:3.1 as runtime
WORKDIR /app
COPY --from=build /out ./
ENTRYPOINT ["dotnet", "YogurtTheBot.Game.Server.dll"]
2 changes: 2 additions & 0 deletions YogurtTheBot.Game.Server/Program.cs
Expand Up @@ -43,6 +43,8 @@ public static void Main(string[] args)
var factory = new ConnectionFactory
{
HostName = rabbitMqSettings.Hostname,
UserName = rabbitMqSettings.Username,
Password = rabbitMqSettings.Password,
DispatchConsumersAsync = true
};

Expand Down
8 changes: 5 additions & 3 deletions YogurtTheBot.Game.Server/appsettings.json
Expand Up @@ -7,12 +7,14 @@
}
},
"MongoSettings": {
"Database": "sb",
"ConnectionString": "mongodb://localhost:27017",
"Database": "root",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be in separate config. appsettings.Dockerfile.json or something like that, so this won't broke rgular development

"ConnectionString": "mongodb://root:root@mongo",
"EnumAsString": true
},
"RabbitMqSettings": {
"Hostname": "localhost",
"Hostname": "rabbitmq",
"Username": "user",
"Password": "user",
"ServersQueue": "incoming_messages",
"MessagesExchange": "messages"
},
Expand Down
14 changes: 14 additions & 0 deletions YogurtTheBot.Telegram.Polling/Dockerfile
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build

COPY ./ /source
WORKDIR /source/YogurtTheBot.Telegram.Polling
RUN dotnet publish -c Release -f netcoreapp3.1 -o /out

WORKDIR /
RUN rm -rf source
RUN find /out -name "*.pdb" -type f -delete

FROM mcr.microsoft.com/dotnet/core/runtime:3.1 as runtime
WORKDIR /app
COPY --from=build /out ./
ENTRYPOINT ["dotnet", "YogurtTheBot.Telegram.Polling.dll"]
2 changes: 2 additions & 0 deletions YogurtTheBot.Telegram.Polling/Program.cs
Expand Up @@ -37,6 +37,8 @@ public static async Task Main(string[] args)
var factory = new ConnectionFactory
{
HostName = rabbitMqSettings.Hostname,
UserName = rabbitMqSettings.Username,
Password = rabbitMqSettings.Password,
DispatchConsumersAsync = true
};

Expand Down
4 changes: 3 additions & 1 deletion YogurtTheBot.Telegram.Polling/appsettings.json
Expand Up @@ -10,7 +10,9 @@
"Token": "783350134:AAGN7YbHEwYLjQYNMLpWKsBrXXj4QzIM83U"
},
"RabbitMqSettings": {
"Hostname": "localhost",
"Hostname": "rabbitmq",
"Username": "user",
"Password": "user",
"ServersQueue": "incoming_messages",
"MessagesExchange": "messages"
}
Expand Down