Giter Site home page Giter Site logo

devc's Introduction

DevContainer CLI managment tool

Do not want to mess your minimal, clean and fine tuned OS installation with a bunch of compilers, linters, debuggers, interpreters, minifiers, unminifiers, beautifiers, etc...? Visual Studio Code nailed it with DevContainers. But do not want to use VSCode neither? That's where devc comes in, it a simple CLI that wrap docker/docker-compose and run the (almost) same commands that VSCode runs behind the scenes.

What is a "DevContainer"?

The devcontainer concept have been developped by the authors of Visual Studio Code and its "Remote - Containers" extension.

Work with a sandboxed toolchain or container-based application inside (or mounted into) a container. โ€“ https://code.visualstudio.com/docs/remote/remote-overview

This way you don't mess your computer with all the dependencies of all the projects and their programming languages on which you work on. It can also make it easier for others to start working on your projects, without having to guess what are the required tools to develop, lint, test, build, etc.

Install

There are different methods to install devc, ordered by preference.

On ArchLinux, from AUR:

$ yay -Syu devc-bin

To install from the devc devcontainer (requires: docker, docker-compose, go, make):

$ git clone https://github.com/nikaro/devc
$ cd devc
$ docker-composer -p devc_devcontainer -f .devcontainer/docker-compose.yml up -d
$ docker-composer -p devc_devcontainer -f .devcontainer/docker-compose.yml exec app make
$ sudo make install

To install from sources into /usr/local/bin/ (requires: go, make):

$ git clone https://github.com/nikaro/devc
$ cd devc
$ make
$ sudo make install

To install devc in your GOPATH (requires: golang):

$ go install github.com/nikaro/[email protected]

To install devc with brew:

$ brew install nikaro/tap/devc

Usage

$ devc --help
A CLI tool to manage your devcontainers using Docker-Compose

Usage:
  devc [command]

Available Commands:
  build       Build or rebuild devcontainer services
  completion  Generate completion script
  help        Help about any command
  init        Create an initial devcontainer configuration
  ps          List containers
  shell       Execute a shell inside the running devcontainer
  start       Start devcontainer services
  stop        Stop devcontainer services

Flags:
  -h, --help      help for devc
  -v, --verbose   show commands used

Use "devc [command] --help" for more information about a command.

Demo

asciicast

Configure (Neo)Vim

With this configuration you can make (Neo)Vim install plugins inside your container (and only inside, not on your host).

~/.config/nvim/init.vim with vim-plug as plugin manager:

if &compatible
  set nocompatible
endif

call plug#begin('~/.local/share/nvim/site/plugged')

Plug 'scrooloose/nerdtree'
[...]

" detect wether we are in a docker container or not
function! s:IsDocker()
  if filereadable('/.dockerenv')
    return 1
  endif
  if filereadable('/proc/self/cgroup')
    let l:cgroup = join(readfile('/proc/self/cgroup'), ' ')
    let l:docker = matchstr(l:cgroup, 'docker')
    if l:docker != ""
      return 1
    endif
  endif
endfunction

" if there is a devcontainer and we are in a container
if filereadable('.devcontainer/devcontainer.json') && s:IsDocker()
  let devcontainer = json_decode(readfile('.devcontainer/devcontainer.json'))
    " install vim plugins
    for plugin in get(devcontainer, 'vim-extensions', [])
      Plug plugin
    endfor
	" apply vim settings
    for setting in get(devcontainer, 'vim-settings', [])
      execute setting
    endfor
endif

call plug#end()

[...]

.devcontainer/devcontainer.json:

{
  [...]
  "vimExtensions": [
    "fatih/vim-go"
  ],
	"vimSettings": [
	  "let g:go_fmt_command = 'goimports'"
	],
  [...]
}

And take a look at my docker-compose.yml and Dockerfile (based on https://hub.docker.com/r/nikaro/debian-dev) to see how to configure your containers.

devcontainer.json properties support

  • docker - image
  • docker - build.dockerfile
  • docker - build.context
  • docker - build.args
  • docker - build.target
  • docker - appPort
  • docker - containerEnv
  • docker - remoteEnv
  • docker - containerUser
  • docker - remoteUser
  • docker - updateRemoteUserUID (do not know how to implement this one)
  • docker - mounts
  • docker - workspaceMount
  • docker - workspaceFolder
  • docker - runArgs
  • docker - overrideCommand
  • docker - shutdownAction (not applicable)
  • docker-compose - dockerComposeFile
  • docker-compose - service
  • docker-compose - runServices
  • docker-compose - workspaceFolder
  • docker-compose - remoteEnv
  • docker-compose - remoteUser
  • docker-compose - shutdownAction (not applicable)
  • general - name
  • general - extensions (not applicable)
  • general - settings (not applicable)
  • general - forwardPorts (for docker only, for docker-compose use docker-compose.yml)
  • general - postCreateCommand
  • general - postStartCommand
  • general - postAttachCommand
  • general - initializeCommand
  • general - userEnvProbe (not applicable)
  • general - devPort (not applicable)
  • variables

devc's People

Contributors

nikaro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.