Skip to content

This project aims to build a development environment inside a docker container. The tools present in the environment are those used by the project's author in his daily life.

License

Notifications You must be signed in to change notification settings

vitor0p9f/dockerized-dev-environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This README is also available in the following languages:


Dockerized Dev Environment

This project aims to build a development environment inside a Docker container. The environment's tools are used daily by the project's author.

Index

Dockerized.Dev.Environment.demonstration.mp4
Neovim Lazygit Exa
Neovim screenshot Lazygit screenshot Exa screenshot
Bat Dust Atuin
Bat screenshot Dust screenshot Atuin screenshot
Zellij Autocomplete Code actions
Zellij screenshot Autocomplete in Neovim screenshot Code actions in Neovim screenshot
LSP
LSP in Neovim screenshot

The environment use fish as default shell.

  • NodeJS
  • NPM
Git
asdf
  • Elixir
  • Erlang
CLI
Neovim
  • Docker
  • Docker Compose
  • Some Nerd Font
  1. Clone this repository on your machine.

  2. Add the function below to your shell's config file.

    Fish
    function devE
    # Repository path
    
    set repo_path "$HOME/< The path where the repository was cloned, without '/' at the end. Example: Documents/GitHub >"
    
    # Generating env file
    
    rm $HOME/.dev-environment.env >> /dev/null
    
    touch $HOME/.dev-environment.env
    
    ## Adding the current working directory
    
    echo "PWD = $(pwd)" >> $HOME/.dev-environment.env
    
    ## Adding host's home path
    
    echo "HOST_HOME_DIR = $HOME" >> $HOME/.dev-environment.env
    
    # Generating .gitconfig file
    
    set git_username (git config user.name)
    set git_email (git config user.email)
    
    set content "
    	[user]
    		name = $git_username
    		email = $git_email
    
    	[safe]
    		directory = *
    
    	[core]
    		editor = nvim
    "
    
    rm $repo_path/dockerized-dev-environment/.gitconfig >> /dev/null
    
    touch $repo_path/dockerized-dev-environment/.gitconfig
    
    echo $content >> $repo_path/dockerized-dev-environment/.gitconfig
    
    # Commands
    
    switch $argv[1]
    	case "run"
    		set_color yellow
    		printf "Starting Docker daemon...\n"
    		set_color normal
    
    		sudo systemctl start docker
    
    		set_color yellow
    		printf "Running the container...\n"
    		set_color normal
    
    		sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml --env-file $HOME/.dev-environment.env up -d --force-recreate
    
    		sudo docker exec -it -w /home/ dockerized-dev-environment fish
    	case "build"
    		set_color yellow
    		printf "Starting Docker daemon...\n"
    		set_color normal
    
    		sudo systemctl start docker
    
    		set_color yellow
    		printf "Building the container...\n"
    		set_color normal
    
    		sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml --env-file $HOME/.dev-environment.env up -d --build --force-recreate
    
    		set_color yellow
    		printf "Running the container...\n"
    		set_color normal
    
    		sudo docker exec -it -w /home/ dockerized-dev-environment fish
    	case "stop"
    		set_color yellow
    		printf "Stopping the container...\n"
    		set_color normal
    
    		sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml stop
    
    		set_color yellow
    		printf "Stopping Docker daemon...\n"
    		set_color normal
    
    		sudo systemctl stop docker
    	case "remove"
    		set_color yellow
    		printf "Removing the container and the image...\n"
    		set_color normal
    
    		sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml down --rmi all
    
    		set_color yellow
    		printf "Stopping Docker daemon...\n"
    		set_color normal
    
    		sudo systemctl stop docker
    	case "*"
    		printf "Usage:\tdevE COMMAND\n\n"
    
    		printf "A development environment inside a Docker container\n\n"
    
    		printf "Commands:\n"
    
    		printf "  run\t\tRun the environment and bind the current working directory with container's home directory\n"
    
    		printf "  build\t\tForce the build of the container\n"
    
    		printf "  stop\t\tStop the container and the Docker's daemon\n"
    
    		printf "  remove\tRemove the container, the image and stops the Docker's daemon\n"
        end
    end
    Bash
    devE(){
    # Colors
    
    bright_yellow="\u001b[33;1m"
    normal="\u001b[0m"
    
    # Repository path
    
    repo_path="$HOME/< The path where the repository was cloned, without '/' at the end. Example: Documents/GitHub >"
    
    # Generating env file
    
    rm $HOME/.dev-environment.env >> /dev/null
    
    touch $HOME/.dev-environment.env
    
    ## Adding the current working directory
    
    echo "PWD = $(pwd)" >> $HOME/.dev-environment.env
    
    ## Adding host's home path
    
    echo "HOST_HOME_DIR = $HOME" >> $HOME/.dev-environment.env
    
    # Generating .gitconfig file
    
    git_username=$(git config user.name)
    git_email=$(git config user.name)
    
    content="
    	[user]
    		name = ${git_username}
    		email = ${git_email}
    
    	[safe]
    		directory = *
    
    	[core]
    		editor = nvim
    "
    
    rm $repo_path/dockerized-dev-environment/.gitconfig >> /dev/null
    
    touch $repo_path/dockerized-dev-environment/.gitconfig
    
    echo $content >> $repo_path/dockerized-dev-environment/.gitconfig
    
    # Commands
    
    case "$1" in
      "run")
        printf "${bright_yellow}Starting Docker daemon...\n${normal}"
    
        sudo systemctl start docker
    
        printf "${bright_yellow}Running the container...\n${normal}"
    
        sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml --env-file $HOME/.dev-environment.env up -d --force-recreate
    
        sudo docker exec -it -w /home/ dockerized-dev-environment fish
      ;;
    
      "build")
        printf "${bright_yellow}Starting Docker daemon...\n${normal}"
    
        sudo systemctl start docker
    
        printf "${bright_yellow}Building the container...\n${normal}"
    
        sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml --env-file $HOME/.dev-environment.env up -d --build --force-recreate
    
        printf "${bright_yellow}Running the container...\n${normal}"
    
        sudo docker exec -it -w /home/ dockerized-dev-environment fish
      ;;
    
      "stop")
        printf "${bright_yellow}Stopping the container...\n${normal}"
    
        sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml stop
    
        printf "${bright_yellow}Stopping Docker daemon...\n${normal}"
    
        sudo systemctl stop docker
      ;;
    
      "remove")
        printf "${bright_yellow}Removing the container and the image...\n${normal}"
    
        sudo docker-compose -f $repo_path/dockerized-dev-environment/docker-compose.yml down --rmi all
    
        printf "${bright_yellow}Stopping Docker daemon...\n${normal}"
    
        sudo systemctl stop docker
      ;;
    
      *)
        printf "Usage:\tdevE COMMAND\n\n"
    
        printf "A development environment inside a Docker container\n\n"
    
        printf "Commands:\n"
    
        printf "  run\t\tRun the environment and bind the current working directory with container's home directory\n"
    
        printf "  build\t\tForce the build of the container\n"
    
        printf "  stop\t\tStop the container and the Docker's daemon\n"
    
        printf "  remove\tRemove the container, the image and stops the Docker's daemon\n"
      ;;
    esac
    }

    OBS: If you don't have a git username and email configured on your git global config, you must fill in the fields on .gitconfig file.

    OBS: Close the terminal to apply the modifies on the shell's configuration file.

  3. Replace < The path where the repository was cloned, without '/' at the end. Example: Documents/GitHub > with the repository's path.

  4. Run devE build inside the desired directory to build the environment. This command will bind the host directory with the /home/ directory inside the container.

    OBS: devE build only needs to be executed once, or when it is necessary to force the construction of the container. Otherwise, use devE run.

  5. Run setup inside the environment to configure it.

    OBS: setup only needs to be executed once, or when it is necessary to reconfigure the environment.

The basic syntax is:

devE COMMAND

The available commands are:

run - Run the environment and bind the current working directory with container's home directory

build - Force the build of the container

stop - Stop the container and the Docker's daemon

remove - Remove the container, the image and stops the Docker's daemon

To leave the environment, run exit on the command line.

In this section, you can find all the custom shortcuts used in Neovim. The leader key is the spacebar.


Find file using telescope - leader + f + f

Find recent files usign telescope - leader + f + r

Find a word inside a file using telescope - leader + f + w

Pin current tab - leader + t + f

Close current tab - leader + t + x

Move to the previous tab - leader + t + p

Move to the next tab - leader + t + n

Toggle neo-tree - leader + n + t

Focus on neo-tree - leader + n + f

Reset hunk under the cursor - leader + h + r

Preview hunk under the cursor - leader + h + p

Toggle git blame - leader + h + b

Run Lazygit - leader + l + r

Toggle trouble - leader + d + t

Show diagnostics for the current buffer - leader + b + d

Format the current buffer - leader + b + f

Show code actions for the line under the cursor - leader + b + a

LSP and autocomplete

The present and configured LSP servers are:

  • elixirls and nextls for Elixir programming language.
  • tsserver for JavaScript and Typescript programming language.
  • lua_ls for Lua programming language.
  • css_variables and cssls for CSS style sheet language.
  • dockerls for Dockerfile.

To add a new LSP server, open the Neovim and use the Mason plugin.

To configure the LSP server, check the available servers and their configurations on the Server Configurations page and paste the configuration into .config/nvim/lua/plugins/LSP/nvim-lspconfig.lua file.

Autocomplete is available only for the languages or file types with an LSP server installed and configured.

To add completions for a programming language or file type whitout configure a LSP server, see the Built-In sources of None-ls plugin and put the configuration into .config/nvim/lua/plugins/LSP/none-ls.lua file.

Diagnostics

The present and configured diagnostics tools are:

  • commitlint for commit messages.
  • hadolint for Dockerfile.
  • markdownlint for Markdown.

To add a new dignostic tool, see the Built-In sources for diagnostics of None-ls plugin and put the configuration into .config/nvim/lua/plugins/LSP/none-ls.lua file.

Formatting

The present and configured formatting tools are:

  • mix and surface for Elixir files.
  • prettier for Javascript, Typescript, Vue, CSS, SCSS, LESS, HTML, JSON, JSONC, YAML, Markdown, Markdown.mdx, Graphql, Handlebars, Svelte, and Astro files.
  • stylua for Lua files.

To add a new formatting tool, see the Built-In sources for formatting of None-ls plugin and put the configuration into .config/nvim/lua/plugins/LSP/none-ls.lua file.

Atuin

The tab functionality doesn't work.

When you press enter, the command will be copied to the command line, so you need to press enter again to run it.

About

This project aims to build a development environment inside a docker container. The tools present in the environment are those used by the project's author in his daily life.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published