;;;; Devops tunings
;; (use-package ansible)
;; (ansible::set-default-keymap)
(use-package yaml-mode
:config
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
(add-hook 'yaml-mode-hook
(lambda ()
(setq evil-shift-width 2)
))
)
;; Unlike python-mode, this mode follows the Emacs convention of not
;; binding the ENTER key to `newline-and-indent'. To get this
;; behavior, add the key definition to `yaml-mode-hook':
;; (add-hook 'yaml-mode-hook
;; '(lambda ()
;; (define-key yaml-mode-map "\C-m" 'newline-and-indent)))
;;;; Hydra
;; https://github.com/abo-abo/hydra/
;; (require hydra)
Web page: Silex/docker.el: Manage docker from Emacs. https://github.com/politza/tablist – tables functions
(use-package docker
;; :disabled
:config
(setq docker-keymap-prefix (kbd "C-c d")
docker-containers-show-all t
)
(docker-global-mode 1)
(evil-set-initial-state 'docker-containers-mode 'emacs)
(evil-set-initial-state 'docker-images-mode 'emacs)
(evil-set-initial-state 'docker-volumes-mode 'emacs)
(evil-set-initial-state 'docker-networks-mode 'emacs)
(push '("\\*docker-\\*" . emacs) evil-buffer-regexps)
(push '("\\*docker \\*" . emacs) evil-buffer-regexps)
(defun bss/kill-docker-result-buffer()
(interactive)
(kill-buffer "*docker result*"))
(evil-add-hjkl-bindings docker-containers-mode-map 'emacs
"c" 'bss/kill-docker-result-buffer
"q" 'quit-window
)
(evil-add-hjkl-bindings docker-images-mode-map 'emacs
"c" 'bss/kill-docker-result-buffer
"q" 'quit-window
)
(evil-add-hjkl-bindings docker-networks-mode-map 'emacs
"c" 'bss/kill-docker-result-buffer
"q" 'quit-window
)
;; (add-hook 'docker-containers-mode-hook '(lambda () (toggle-truncate-lines 1)))
;; (setq tabulated-list-revert-hook nil)
(add-hook 'tabulated-list-revert-hook '(lambda () (toggle-truncate-lines 1)(setq docker-containers-show-all t)))
(ignore-errors (fmakunbound 'docker-utils-with-result-buffer))
(defmacro docker-utils-with-result-buffer (&rest body)
`(let ((buffer (get-buffer-create "*docker result*")))
(with-current-buffer buffer
(setq buffer-read-only nil)
(erase-buffer)
(buffer-local-set-key (kbd "q") 'kill-this-buffer) ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ADDED THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;; (local-set-key (kbd "q") 'kill-this-buffer)
,@body
(setq buffer-read-only t))
(display-buffer buffer)))
(defun bss/work-docker()
(interactive)
(setenv "DOCKER_TLS_VERIFY" "1")
(setenv "DOCKER_HOST" "tcp://192.168.1.54:2375")
(setenv "DOCKER_CERT_PATH" "/Users/stalker/.docker/")
(setenv "DOCKER_MACHINE_NAME" "")
)
(defun bss/home-docker ()
(interactive)
(setenv "DOCKER_TLS_VERIFY" "1")
(setenv "DOCKER_HOST" "tcp://192.168.99.100:2376")
(setenv "DOCKER_CERT_PATH" "/Users/stalker/.docker/machine/machines/docker-local")
(setenv "DOCKER_MACHINE_NAME" "docker-local")
)
)
Adds syntax highlighting as well as the ability to build the image directly (C-c C-b) from the buffer.
(use-package dockerfile-mode
;; :disabled
:config
;; show only running containers
(setq docker-containers-show-all nil)
(add-to-list 'auto-mode-alist '("\\Dockerfile" . dockerfile-mode))
)
C-x C-f /docker:user@container:/path/to/file
(use-package docker-tramp
;; :disabled
:ensure t
:config
;; (defadvice tramp-completion-handle-file-name-all-completions
;; (around dotemacs-completion-docker activate)
;; "(tramp-completion-handle-file-name-all-completions \"\" \"/docker:\" returns
;; a list of active Docker container names, followed
;; by colons."
;; (if (equal (ad-get-arg 1) "/docker:")
;; (let* ((dockernames-raw (shell-command-to-string "docker ps | awk '$NF != \"NAMES\" { print $NF \":\" }'"))
;; (dockernames (cl-remove-if-not
;; #'(lambda (dockerline) (string-match ":$" dockerline))
;; (split-string dockernames-raw "\n"))))
;; (setq ad-return-value dockernames))
;; ad-do-it))
)
Web page: masasam/emacs-helm-tramp: Tramp helm interface for ssh and docker and vagrant
(use-package helm-tramp
:ensure t
:bind ("C-c s" . helm-tramp)
:config
(setq helm-tramp-docker-user "root")
;; hack for docker container NAMES
(defun helm-tramp--candidates ()
"Collect candidates for helm-tramp."
(let ((source (split-string
(with-temp-buffer
(insert-file-contents "~/.ssh/config")
(buffer-string))
"\n"))
(hosts (list)))
(dolist (host source)
(when (string-match "[H\\|h]ost +\\(.+?\\)$" host)
(setq host (match-string 1 host))
(if (string-match "[ \t\n\r]+\\'" host)
(replace-match "" t t host))
(if (string-match "\\`[ \t\n\r]+" host)
(replace-match "" t t host))
(unless (string= host "*")
(push
(concat "/" tramp-default-method ":" host ":")
hosts)
(push
(concat "/ssh:" host "|sudo:" host ":/")
hosts))))
(when (package-installed-p 'docker-tramp)
;; container names
(cl-loop for line in (split-string (ignore-errors (shell-command-to-string "docker ps | awk '$NF != \"NAMES\" { print $NF }'")) nil)
collect (progn (if (null helm-tramp-docker-user)
(push
(concat "/docker:" (string-trim line) ":/")
hosts))
(unless (null helm-tramp-docker-user)
(if (listp helm-tramp-docker-user)
(let ((docker-user helm-tramp-docker-user))
(while docker-user
(push
(concat "/docker:" (car docker-user) "@" (string-trim line) ":/")
hosts)
(pop docker-user)))
(push
(concat "/docker:" helm-tramp-docker-user "@" (string-trim line) ":/")
hosts)))))
;; end container names
(cl-loop for line in (cdr (ignore-errors (apply #'process-lines "docker" (list "ps"))))
for info = (split-string line "[[:space:]]+" t)
collect (progn (if (null helm-tramp-docker-user)
(push
(concat "/docker:" (car info) ":/")
hosts))
(unless (null helm-tramp-docker-user)
(if (listp helm-tramp-docker-user)
(let ((docker-user helm-tramp-docker-user))
(while docker-user
(push
(concat "/docker:" (car docker-user) "@" (car info) ":/")
hosts)
(pop docker-user)))
(push
(concat "/docker:" helm-tramp-docker-user "@" (car info) ":/")
hosts)))))
)
(when (package-installed-p 'vagrant-tramp)
(cl-loop for box-name in (map 'list 'cadr (vagrant-tramp--completions))
do (progn
(push (concat "/vagrant:" box-name ":/") hosts)
(push (concat "/vagrant:" box-name "|sudo:" box-name ":/") hosts))))
(push "/sudo:root@localhost:/" hosts)
(reverse hosts)))
)
Web page: meqif/docker-compose-mode: Major mode for editing docker-compose files
(use-package docker-compose-mode)