From 45de847274200c0079f80c98d1295d46d5ed783d Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Sun, 29 Oct 2023 00:01:31 +0400 Subject: [PATCH 1/7] docker-4 --- README.md | 24 ++++++++++++++-- src/.env.example | 6 ++++ src/.gitignore | 2 +- src/comment/Dockerfile | 2 +- src/docker-compose.override.yml | 50 +++++++++++++++++++++++++++++++++ src/docker-compose.yml | 42 +++++++++++++++++++++++++++ src/post-py/Dockerfile | 2 +- src/ui/Dockerfile | 2 +- 8 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 src/.env.example create mode 100644 src/docker-compose.override.yml create mode 100644 src/docker-compose.yml diff --git a/README.md b/README.md index 6ce72fe..d3ff250 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ yc compute instance create \ ```shell docker-machine --debug create \ --driver generic \ - --generic-ip-address=51.250.84.88 \ + --generic-ip-address=51.250.92.127 \ --generic-ssh-user yc-user \ --generic-ssh-key ~/.ssh/id_ed25519 \ docker-host @@ -46,10 +46,15 @@ docker pull baykanurov/otus-reddit:1.0 ## Docker-3 ### Что было сделано: -1. Написал Dockerfiles для сервисов: +1. Написал Dockerfile и собрал образ для каждого из сервисов приложения: - **post-py** - **comment** - **ui** +```shell +docker build -t baykanurov/post:1.0 ./post-py +docker build -t baykanurov/comment:1.0 ./comment +docker build -t baykanurov/ui:1.0 ./ui +``` 2. Запустил и проверил, что всё работает ```shell docker network create reddit @@ -96,3 +101,18 @@ docker run -d --network=reddit --network-alias=post baykanurov/post:1.0 docker run -d --network=reddit --network-alias=comment baykanurov/comment:1.0 docker run -d --network=reddit -p 9292:9292 baykanurov/ui:1.0 ``` + +## Docker-4 +### Что было сделано: +- Изучено как работают сети Docker +- Написан docker-compose для сервисов нашего приложения +- Параметризированы значения в docker compose для: + - тегов образов для всех сервисов + - порт публикации сервиса ui + - username +- Также для всех параметров добавлены default values +- Задано имя для каждого контейнера +- Имя проекта можно задать через name в docker-compose +### Дополнительное задание +Добавил файл docker-compose.override.yml который пробрасывает код сервиса как volume и добавляет возможность запускать puma для руби приложений в дебаг +режиме с двумя воркерами diff --git a/src/.env.example b/src/.env.example new file mode 100644 index 0000000..f5a6621 --- /dev/null +++ b/src/.env.example @@ -0,0 +1,6 @@ +USERNAME=test +MONGO_IMAGE_TAG= +UI_IMAGE_TAG= +POST_IMAGE_TAG= +COMMENT_IMAGE_TAG= +UI_PORT= diff --git a/src/.gitignore b/src/.gitignore index 169a724..5f651ab 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,6 +1,6 @@ -docker-compose.yml build_info.txt prometheus/ +.env ## python specific *.pyc diff --git a/src/comment/Dockerfile b/src/comment/Dockerfile index 9882bde..237eb06 100644 --- a/src/comment/Dockerfile +++ b/src/comment/Dockerfile @@ -13,4 +13,4 @@ RUN apk update --no-cache && \ gem install bundler:1.17.2 && \ bundle install -ENTRYPOINT ["puma"] +CMD ["puma"] diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml new file mode 100644 index 0000000..2b5b2a6 --- /dev/null +++ b/src/docker-compose.override.yml @@ -0,0 +1,50 @@ +name: reddit-override +services: + mongo: + container_name: post_db + image: mongo:${MONGO_IMAGE_TAG:-4.4} + volumes: + - post_db:/data/db + networks: + - back_net + - front_net + + ui: + container_name: ui + build: ./ui + image: ${USERNAME:-baykanurov}/ui:${UI_IMAGE_TAG:-1.0} + command: ["puma", "--debug", "-w 2"] + ports: + - ${UI_PORT:-9292}:9292/tcp + volumes: + - ./ui:/app:consistent + networks: + - front_net + + post: + container_name: post + build: ./post-py + image: ${USERNAME:-baykanurov}/post:${POST_IMAGE_TAG:-1.0} + volumes: + - ./post-py:/app:consistent + networks: + - back_net + - front_net + + comment: + container_name: comment + build: ./comment + image: ${USERNAME:-baykanurov}/comment:${COMMENT_IMAGE_TAG:-1.0} + command: ["puma", "--debug", "-w 2"] + volumes: + - ./comment:/app:consistent + networks: + - back_net + - front_net + +volumes: + post_db: + +networks: + back_net: + front_net: diff --git a/src/docker-compose.yml b/src/docker-compose.yml new file mode 100644 index 0000000..ee1f1c9 --- /dev/null +++ b/src/docker-compose.yml @@ -0,0 +1,42 @@ +name: reddit +services: + mongo: + container_name: post_db + image: mongo:${MONGO_IMAGE_TAG:-4.4} + volumes: + - post_db:/data/db + networks: + - back_net + - front_net + + ui: + container_name: ui + build: ./ui + image: ${USERNAME:-baykanurov}/ui:${UI_IMAGE_TAG:-1.0} + ports: + - ${UI_PORT:-9292}:9292/tcp + networks: + - front_net + + post: + container_name: post + build: ./post-py + image: ${USERNAME:-baykanurov}/post:${POST_IMAGE_TAG:-1.0} + networks: + - back_net + - front_net + + comment: + container_name: comment + build: ./comment + image: ${USERNAME:-baykanurov}/comment:${COMMENT_IMAGE_TAG:-1.0} + networks: + - back_net + - front_net + +volumes: + post_db: + +networks: + back_net: + front_net: diff --git a/src/post-py/Dockerfile b/src/post-py/Dockerfile index b1b9ed5..f5a077c 100644 --- a/src/post-py/Dockerfile +++ b/src/post-py/Dockerfile @@ -12,4 +12,4 @@ RUN apk --no-cache --update add build-base && \ pip install -r requirements.txt && \ apk del build-base -ENTRYPOINT ["python3", "post_app.py"] +CMD ["python3", "post_app.py"] diff --git a/src/ui/Dockerfile b/src/ui/Dockerfile index f85dfbd..0f800e1 100644 --- a/src/ui/Dockerfile +++ b/src/ui/Dockerfile @@ -15,4 +15,4 @@ RUN apk update --no-cache && \ gem install bundler:1.17.2 && \ bundle install -ENTRYPOINT ["puma"] +CMD ["puma"] From 1b8d2547f14456be74dbfec24cceff23ced03b42 Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Sun, 29 Oct 2023 18:02:32 +0400 Subject: [PATCH 2/7] fix test --- src/.env.example | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/.env.example b/src/.env.example index f5a6621..07f7bd5 100644 --- a/src/.env.example +++ b/src/.env.example @@ -1,6 +1,6 @@ USERNAME=test -MONGO_IMAGE_TAG= -UI_IMAGE_TAG= -POST_IMAGE_TAG= -COMMENT_IMAGE_TAG= -UI_PORT= +MONGO_IMAGE_TAG=4.4 +UI_IMAGE_TAG=1.0 +POST_IMAGE_TAG=1.0 +COMMENT_IMAGE_TAG=1.0 +UI_PORT=9292 From ce7f43c49e8c3ad8dc08c75f5efb6c4eccd36538 Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Sun, 29 Oct 2023 18:05:29 +0400 Subject: [PATCH 3/7] fix test --- src/docker-compose.override.yml | 1 - src/docker-compose.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index 2b5b2a6..79c5fa1 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -1,4 +1,3 @@ -name: reddit-override services: mongo: container_name: post_db diff --git a/src/docker-compose.yml b/src/docker-compose.yml index ee1f1c9..7136c08 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -1,4 +1,3 @@ -name: reddit services: mongo: container_name: post_db From a2e0b09ce737bd5deb75326d8f3fbade1d27318d Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Sun, 29 Oct 2023 18:07:46 +0400 Subject: [PATCH 4/7] fix test --- src/docker-compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 7136c08..b1a1392 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -1,7 +1,7 @@ services: mongo: container_name: post_db - image: mongo:${MONGO_IMAGE_TAG:-4.4} + image: mongo:${MONGO_IMAGE_TAG} volumes: - post_db:/data/db networks: @@ -11,7 +11,7 @@ services: ui: container_name: ui build: ./ui - image: ${USERNAME:-baykanurov}/ui:${UI_IMAGE_TAG:-1.0} + image: ${USERNAME}/ui:${UI_IMAGE_TAG} ports: - ${UI_PORT:-9292}:9292/tcp networks: @@ -20,7 +20,7 @@ services: post: container_name: post build: ./post-py - image: ${USERNAME:-baykanurov}/post:${POST_IMAGE_TAG:-1.0} + image: ${USERNAME}/post:${POST_IMAGE_TAG} networks: - back_net - front_net @@ -28,7 +28,7 @@ services: comment: container_name: comment build: ./comment - image: ${USERNAME:-baykanurov}/comment:${COMMENT_IMAGE_TAG:-1.0} + image: ${USERNAME}/comment:${COMMENT_IMAGE_TAG} networks: - back_net - front_net From db5ebbb05712e8ac3513f4c077188c55a1fdd8bc Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Mon, 30 Oct 2023 11:00:44 +0400 Subject: [PATCH 5/7] fix test --- src/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docker-compose.yml b/src/docker-compose.yml index b1a1392..404e9c3 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -13,7 +13,7 @@ services: build: ./ui image: ${USERNAME}/ui:${UI_IMAGE_TAG} ports: - - ${UI_PORT:-9292}:9292/tcp + - ${UI_PORT}:9292/tcp networks: - front_net From ead87891427ce57b669b2e6d6386878dfefa39fc Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Mon, 30 Oct 2023 15:14:45 +0400 Subject: [PATCH 6/7] fix test --- src/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 404e9c3..a4f44fc 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -1,3 +1,4 @@ +version: '3.3' services: mongo: container_name: post_db From 885b00cb51b2b6b7af8b9c19380c5b98e5dfccc5 Mon Sep 17 00:00:00 2001 From: Baykanurov Date: Wed, 1 Nov 2023 00:28:21 +0400 Subject: [PATCH 7/7] fix networks mongo --- src/docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/docker-compose.yml b/src/docker-compose.yml index a4f44fc..867ee2a 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -7,7 +7,6 @@ services: - post_db:/data/db networks: - back_net - - front_net ui: container_name: ui