From 5da39e6f3955f2dba5aadcd1976813418e23165a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Crnojevi=C4=87?= Date: Wed, 6 Mar 2024 19:03:29 +0100 Subject: [PATCH] Update --- README.md | 19 +++++++++++++------ client.Dockerfile | 14 ++++---------- client.docker-compose.yaml | 3 ++- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index fd44497..b247115 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ This allows for a scalable deployment of the services, as they can be run in par Run the following command to start the service: ```shell -sudo docker-compose -f docker/rabbitClient.docker-compose.yaml --env-file .env up -d +docker-compose -f rabbitClient.docker-compose.yaml --env-file .env up -d ``` ### Running the Client @@ -53,15 +53,22 @@ Run the following command to start the Client on your machine: go run src/cmd/client/main.go ``` +#### With Docker + +```shell +docker build -t client -f client.Dockerfile . +docker run --network="host" --env-file .env client +``` + #### Scaling the Client -Run the following command to start the Client in a scalable way with docker compose: +Run the following command to start the Server in a scalable way with docker compose: ```shell -docker-compose -f docker/client.docker-compose.yaml --scale client=2 --env-file .env up -d +docker-compose -f client.docker-compose.yaml --env-file .env up -d --scale client=4 ``` -Change the `--scale client=2` parameter to any number of clients you'd want to run in parallel. +Change the `--scale client=4` parameter to any number of clients you'd want to run in parallel. ### Running the Server @@ -85,10 +92,10 @@ docker run --network="host" --env-file .env server Run the following command to start the Server in a scalable way with docker compose: ```shell -docker-compose -f server.docker-compose.yaml --env-file .env up -d --scale server=3 +docker-compose -f server.docker-compose.yaml --env-file .env up -d --scale server=4 ``` -Change the `--scale server=3` parameter to any number of clients you'd want to run in parallel. +Change the `--scale server=4` parameter to any number of clients you'd want to run in parallel. ## File structure diff --git a/client.Dockerfile b/client.Dockerfile index fad315d..8bc311f 100644 --- a/client.Dockerfile +++ b/client.Dockerfile @@ -2,16 +2,10 @@ FROM --platform=linux/amd64 golang:1.22 as builder WORKDIR /app -ADD docker /app +COPY . . -RUN go mod tidy && go build -o client_exec ./src/cmd/client/ - -FROM --platform=linux/amd64 alpine:latest - -RUN apk --no-cache add ca-certificates - -WORKDIR /root/ - -COPY --from=builder /app/client_exec . +RUN go mod download +RUN go mod tidy +RUN go build -o client_exec ./src/cmd/client/ CMD ["./client_exec"] diff --git a/client.docker-compose.yaml b/client.docker-compose.yaml index 9962b99..47d0afa 100644 --- a/client.docker-compose.yaml +++ b/client.docker-compose.yaml @@ -3,7 +3,7 @@ version: '3.8' services: client: build: - context: docker + context: . dockerfile: client.Dockerfile environment: RABBITMQ_USER: ${RABBITMQ_USER} @@ -11,6 +11,7 @@ services: RABBITMQ_AMQP_PORT: ${RABBITMQ_AMQP_PORT} RABBITMQ_AMQP_HOST: ${RABBITMQ_AMQP_HOST} COMMANDS_PATH: ${COMMANDS_PATH} + network_mode: host volumes: - ./resources:/resources