Improved dev environment

- Switched dev container to docker-compose
- Added ejabberd and docker to dev container
- Added post creation script for configuring environment
This commit is contained in:
Ivan-lis 2024-09-25 18:16:34 +02:00
parent ec53c19642
commit c1daa0200e
7 changed files with 84 additions and 26 deletions

View file

@ -13,6 +13,14 @@ RUN useradd -ms /bin/bash dev \
&& echo "dev ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/dev \ && echo "dev ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/dev \
&& chmod 0440 /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 # Add the custom bash prompt with branch info
RUN printf '\n\ RUN printf '\n\
function modify_prompt { \n\ function modify_prompt { \n\

View file

@ -1,8 +1,15 @@
{ {
"name": "Arch Linux with GCC & Clang++", "name": "Arch Linux with GCC & Clang++",
"build": { "dockerComposeFile": "docker-compose.yml",
"dockerfile": "Dockerfile" "service": "devcontainer",
}, "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"forwardPorts": [
5222,
5269,
5280,
5443
],
"postStartCommand": "/workspaces/larra/.devcontainer/post_create_config.sh",
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [

View file

@ -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

View file

@ -37,7 +37,7 @@ listen:
max_stanza_size: 262144 max_stanza_size: 262144
shaper: c2s_shaper shaper: c2s_shaper
access: c2s access: c2s
starttls_required: true starttls_required: false
- -
port: 5223 port: 5223
ip: "::" ip: "::"

View file

@ -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"

19
.vscode/tasks.json vendored
View file

@ -3,6 +3,20 @@
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "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", "label": "Build Debug GCC",
"type": "shell", "type": "shell",
@ -14,8 +28,7 @@
"|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )" "|| ( printf '\n\n\t\\e[31mERROR: Build failed!\\e[0m\n\n\n' && exit 1 )"
], ],
"options": { "options": {
"env": { "env": {}
}
}, },
"presentation": { "presentation": {
"clear": true "clear": true
@ -39,7 +52,7 @@
"options": { "options": {
"env": { "env": {
"CC": "/usr/sbin/clang", "CC": "/usr/sbin/clang",
"CXX": "/usr/sbin/clang++", "CXX": "/usr/sbin/clang++"
} }
}, },
"presentation": { "presentation": {

View file

@ -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