From c1daa0200e6f2597b0ea8e5851d666c7eab3cc16 Mon Sep 17 00:00:00 2001 From: Ivan-lis Date: Wed, 25 Sep 2024 18:16:34 +0200 Subject: [PATCH] Improved dev environment - Switched dev container to docker-compose - Added ejabberd and docker to dev container - Added post creation script for configuring environment --- .devcontainer/Dockerfile | 8 +++++ .devcontainer/devcontainer.json | 13 ++++++-- .devcontainer/docker-compose.yml | 39 ++++++++++++++++++++++ {deployment => .devcontainer}/ejabberd.yml | 2 +- .devcontainer/post_create_config.sh | 10 ++++++ .vscode/tasks.json | 19 +++++++++-- deployment/docker-compose.yml | 19 ----------- 7 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 .devcontainer/docker-compose.yml rename {deployment => .devcontainer}/ejabberd.yml (99%) create mode 100755 .devcontainer/post_create_config.sh delete mode 100644 deployment/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 6f5bef1..655b587 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,6 +13,14 @@ RUN useradd -ms /bin/bash dev \ && echo "dev ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/dev \ && chmod 0440 /etc/sudoers.d/dev +# Add docker and docker-compose and add permissions to run without sudo +COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker +COPY --from=docker/compose:latest /usr/local/bin/docker-compose /usr/bin/docker-compose + +RUN groupadd docker &&\ + usermod -aG docker dev &&\ + newgrp docker + # Add the custom bash prompt with branch info RUN printf '\n\ function modify_prompt { \n\ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c32a38b..b2ffe09 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,15 @@ { "name": "Arch Linux with GCC & Clang++", - "build": { - "dockerfile": "Dockerfile" - }, + "dockerComposeFile": "docker-compose.yml", + "service": "devcontainer", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "forwardPorts": [ + 5222, + 5269, + 5280, + 5443 + ], + "postStartCommand": "/workspaces/larra/.devcontainer/post_create_config.sh", "customizations": { "vscode": { "extensions": [ diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..9425810 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,39 @@ +services: + devcontainer: + build: + context: . + dockerfile: Dockerfile + + # Required for ptrace-based debuggers like C++, Go, and Rust + cap_add: + - SYS_PTRACE + security_opt: + - seccomp:unconfined + + volumes: + - ../..:/workspaces/:cached + - /var/run/docker.sock:/var/run/docker.sock:ro + network_mode: service:ejabberd_server # To access ejabberd inside a devcontainer + command: sleep infinity # To keep container alive + depends_on: + - ejabberd_server + + ejabberd_server: + image: ghcr.io/processone/ejabberd + container_name: ejabberd + # + # For some reasons below environment variables doesn't work inside vs code dev container + # Please, use devcontainer.json 'postStartCommand' for configuring ejabberd_server + # + environment: + - CTL_ON_CREATE=register admin localhost admin ; + register test1 localhost test1 ; + - CTL_ON_START=registered_users localhost ; + status + ports: + - "5222:5222" + - "5269:5269" + - "5280:5280" + - "5443:5443" + volumes: + - ./ejabberd.yml:/opt/ejabberd/conf/ejabberd.yml:ro diff --git a/deployment/ejabberd.yml b/.devcontainer/ejabberd.yml similarity index 99% rename from deployment/ejabberd.yml rename to .devcontainer/ejabberd.yml index 5783b8e..9f52450 100644 --- a/deployment/ejabberd.yml +++ b/.devcontainer/ejabberd.yml @@ -37,7 +37,7 @@ listen: max_stanza_size: 262144 shaper: c2s_shaper access: c2s - starttls_required: true + starttls_required: false - port: 5223 ip: "::" diff --git a/.devcontainer/post_create_config.sh b/.devcontainer/post_create_config.sh new file mode 100755 index 0000000..3927e55 --- /dev/null +++ b/.devcontainer/post_create_config.sh @@ -0,0 +1,10 @@ +sleep 1 + +printf "\n\n\tConfigure ejabber server\n\n" +sudo docker exec -it ejabberd ejabberdctl register admin localhost admin +sudo docker exec -it ejabberd ejabberdctl register sha512sum localhost 12345 + +printf "\n\n\tList of registered users:\n" +sudo docker exec -it ejabberd ejabberdctl registered_users localhost + +printf "\n\n\tConfigurating ejabber server ended\n\n" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b778385..eaea877 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,6 +3,20 @@ // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ + { + "label": "Ejabberd: show logs", + "type": "shell", + "command": [ + "sudo docker exec -it ejabberd tail -f logs/ejabberd.log" + ] + }, + { + "label": "Ejabberd: open shell", + "type": "shell", + "command": [ + "sudo docker exec -it ejabberd sh" + ] + }, { "label": "Build Debug GCC", "type": "shell", @@ -14,8 +28,7 @@ "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" ], "options": { - "env": { - } + "env": {} }, "presentation": { "clear": true @@ -39,7 +52,7 @@ "options": { "env": { "CC": "/usr/sbin/clang", - "CXX": "/usr/sbin/clang++", + "CXX": "/usr/sbin/clang++" } }, "presentation": { diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml deleted file mode 100644 index ca82055..0000000 --- a/deployment/docker-compose.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: '3.7' - -services: - - ejabberd_server: - image: ghcr.io/processone/ejabberd - container_name: ejabberd - environment: - - CTL_ON_CREATE=register admin localhost admin ; - register user localhost password - - CTL_ON_START=registered_users localhost ; - status - ports: - - "5222:5222" - - "5269:5269" - - "5280:5280" - - "5443:5443" - volumes: - - ./ejabberd.yml:/opt/ejabberd/conf/ejabberd.yml:ro