Skip to content

Commit

Permalink
initial refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-smoker committed Jun 11, 2021
1 parent 40414de commit 3bd6274
Show file tree
Hide file tree
Showing 195 changed files with 11,593 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_site
.sass-cache
.jekyll-cache
.jekyll-metadata
vendor
.DS_Store
Gemfile.lock
.bundle
.terraform*
yarn.lock
.vscode*
.yarn*
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM alpine:3.13.5

ENV TERRAFORM_VERSION=1.0.0

# Dependencies. #Terraform # Awscli # make directory
RUN apk update && \
apk add curl jq python3 py3-pip bash ca-certificates git openssl unzip wget openssh-keygen && \
cd /tmp && \
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/bin && \
pip3 install awscli && pip3 install requests urllib3 && pip3 install git+git://github.com/HR/github-clone#egg=ghclone && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/* && \
rm -rf /var/tmp/*

# Aviatrix Sandbox-Starter.
ADD sandbox-starter/controller /root/controller
ADD sandbox-starter/controller-govcloud /root/controller-govcloud
ADD sandbox-starter/mcna /root/mcna
ADD sandbox-starter/mcna-govcloud /root/mcna-govcloud
ADD sandbox-starter/sandbox_starter.sh /root/
ADD sandbox-starter/.plane /root/
ADD sandbox-starter/.eagle /root/

# SST backend.
ADD sandbox-starter/sandbox_starter_web.sh /root/
ADD sst-backend/requirements.txt /root/requirements.txt
RUN pip3 install -r /root/requirements.txt
ADD sst-backend /root/

# Misc. configuration
RUN mkdir -p /root/.emacs.d/lisp
ADD config/terraform-mode.el /root/.emacs.d/lisp
ADD config/hcl-mode.el /root/.emacs.d/lisp
ADD config/dotemacs /root/.emacs

WORKDIR /root
CMD python3 app.py
4 changes: 4 additions & 0 deletions config/dotemacs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(add-to-list 'load-path "~/.emacs.d/lisp/")

(require 'terraform-mode)
(add-to-list 'auto-mode-alist '("\\.tf\\'" . terraform-mode))
227 changes: 227 additions & 0 deletions config/hcl-mode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
;;; hcl-mode.el --- Major mode for Hashicorp -*- lexical-binding: t -*-

;; Copyright (C) 2017 by Syohei YOSHIDA

;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL: https://github.com/syohex/emacs-hcl-mode
;; Version: 0.03
;; Package-Requires: ((emacs "24.3"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; hcl-mode provides a major-mode of hcl file.

;;; Code:

(require 'cl-lib)
(require 'rx)

(defgroup hcl nil
"Major mode of Hashicorp Configuration Language."
:group 'languages)

(defcustom hcl-indent-level 2
"The tab width to use when indenting."
:type 'integer)

(defconst hcl--block-regexp
"^\\s-*[^{]+{")

;; String Interpolation(This regexp is taken from ruby-mode)
(defconst hcl--string-interpolation-regexp
"\\${[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}")

(defconst hcl--assignment-regexp
"\\s-*\\([[:word:]]+\\)\\s-*=\\(?:[^>=]\\)")

(defconst hcl--map-regexp
"\\s-*\\([[:word:]]+\\)\\s-*{")

(defconst hcl--boolean-regexp
(concat "\\(?:^\\|[^.]\\)"
(regexp-opt '("true" "false" "on" "off" "yes" "no")
'words)))

(defvar hcl-font-lock-keywords
`((,hcl--assignment-regexp 1 font-lock-variable-name-face)
(,hcl--boolean-regexp . font-lock-constant-face)
(,hcl--map-regexp 1 font-lock-type-face)
(,hcl--string-interpolation-regexp 0 font-lock-variable-name-face t)))

(defsubst hcl--paren-level ()
(car (syntax-ppss)))

(defsubst hcl--in-string-or-comment-p ()
(nth 8 (syntax-ppss)))

(defun hcl--block-indentation ()
(let ((curline (line-number-at-pos)))
(save-excursion
(condition-case nil
(progn
(backward-up-list)
(unless (= curline (line-number-at-pos))
(current-indentation)))
(scan-error nil)))))

(defun hcl--previous-indentation ()
(save-excursion
(forward-line -1)
(let (finish)
(while (not finish)
(cond ((bobp) (setq finish t))
((hcl--in-string-or-comment-p) (forward-line -1))
(t
(let ((line (buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(if (not (string-match-p "\\`\\s-*\\'" line))
(setq finish t)
(forward-line -1))))))
(current-indentation))))

(defun hcl-indent-line ()
"Indent current line as Hcl configuration."
(interactive)
(let* ((curpoint (point))
(pos (- (point-max) curpoint)))
(back-to-indentation)
(if (hcl--in-string-or-comment-p)
(goto-char curpoint)
(let ((block-indentation (hcl--block-indentation)))
(delete-region (line-beginning-position) (point))
(if block-indentation
(if (looking-at "[]}]")
(indent-to block-indentation)
(indent-to (+ block-indentation hcl-indent-level)))
(indent-to (hcl--previous-indentation)))
(when (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))))))

(defun hcl-beginning-of-defun (&optional count)
(interactive "p")
(setq count (or count 1))
(let ((match 0)
finish)
(while (and (not finish)
(re-search-backward hcl--block-regexp nil t))
(unless (hcl--in-string-or-comment-p)
(cl-incf match)
(when (= match count)
(setq finish t))))))

(defun hcl-end-of-defun (&optional count)
(interactive "p")
(let ((paren-level (hcl--paren-level)))
(when (or (and (looking-at-p "}") (= paren-level 1))
(= paren-level 0))
(re-search-forward hcl--block-regexp nil t)))
(dotimes (_i count)
(when (looking-at-p hcl--block-regexp)
(goto-char (line-end-position)))
(hcl-beginning-of-defun 1)
(skip-chars-forward "^{")
(forward-char 1)
(let ((orig-level (hcl--paren-level)))
(while (>= (hcl--paren-level) orig-level)
(skip-chars-forward "^}")
(forward-line +1)))))

(eval-and-compile
(defconst hcl--here-doc-beg-re
"[^<]<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\|[-/~._]\\)+\\)\\(\n\\)"))

(defun hcl--syntax-propertize-heredoc (end)
(let ((ppss (syntax-ppss)))
(when (eq t (nth 3 ppss))
(let ((key (get-text-property (nth 8 ppss) 'hcl-here-doc-marker))
(case-fold-search nil))
(when (re-search-forward
(concat "^\\(?:[ \t]*\\)" (regexp-quote key) "\\(\n\\)")
end 'move)
(let ((eol (match-beginning 1)))
(put-text-property eol (1+ eol)
'syntax-table (string-to-syntax "|"))))))))

(defun hcl--font-lock-open-heredoc (start string eol)
(unless (or (memq (char-before start) '(?< ?>))
(save-excursion
(goto-char start)
(hcl--in-string-or-comment-p)))
(let ((str (replace-regexp-in-string "['\"]" "" string))
(ppss (save-excursion (syntax-ppss eol))))
(put-text-property eol (1+ eol) 'hcl-here-doc-marker str)
(prog1 (string-to-syntax "|")
(goto-char (+ 2 start))))))

(defun hcl--syntax-propertize-function (start end)
(goto-char start)
(hcl--syntax-propertize-heredoc end)
(funcall
(syntax-propertize-rules
(hcl--here-doc-beg-re
(2 (hcl--font-lock-open-heredoc
(match-beginning 0) (match-string 1) (match-beginning 2))))
("\\s|" (0 (prog1 nil (hcl--syntax-propertize-heredoc end)))))
(point) end))

(defvar hcl-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-M-a") 'hcl-beginning-of-defun)
(define-key map (kbd "C-M-e") 'hcl-end-of-defun)
map)
"Keymap for Hcl major mode.")

;;;###autoload
(define-derived-mode hcl-mode prog-mode "HCL"
"Major mode for editing hcl configuration file"

(setq font-lock-defaults '((hcl-font-lock-keywords)))

(modify-syntax-entry ?_ "w" hcl-mode-syntax-table)

;;; Comments
;; Single line comment
(modify-syntax-entry ?# "< b" hcl-mode-syntax-table)
(modify-syntax-entry ?\n "> b" hcl-mode-syntax-table)

;; multiple line comment(/* ... */) taken from `go-mode'
(modify-syntax-entry ?/ ". 124b" hcl-mode-syntax-table)
(modify-syntax-entry ?* ". 23" hcl-mode-syntax-table)

(setq-local comment-start "#")
(setq-local comment-use-syntax t)
(setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")

;; indentation
(make-local-variable 'hcl-indent-level)
(setq-local indent-line-function 'hcl-indent-line)

(setq-local beginning-of-defun-function #'hcl-beginning-of-defun)
(setq-local end-of-defun-function #'hcl-end-of-defun)

(setq-local syntax-propertize-function #'hcl--syntax-propertize-function)

;; electric-mode
(setq-local electric-indent-chars (append "{}[]" electric-indent-chars)))

;;;###autoload
(progn
(add-to-list 'auto-mode-alist '("\\.hcl\\'" . hcl-mode))
(add-to-list 'auto-mode-alist '("\\.nomad\\'" . hcl-mode)))

(provide 'hcl-mode)

;;; hcl-mode.el ends here
113 changes: 113 additions & 0 deletions config/terraform-mode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
;;; terraform-mode.el --- Major mode for terraform configuration file -*- lexical-binding: t -*-

;; Copyright (C) 2017 by Syohei YOSHIDA

;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL: https://github.com/syohex/emacs-terraform-mode
;; Version: 0.06
;; Package-Requires: ((emacs "24.3") (hcl-mode "0.03"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Major mode of terraform configuration file. terraform-mode provides
;; syntax highlighting, indentation function and formatting.

;; Format the current buffer with terraform-format-buffer. To always
;; format terraform buffers when saving, use:
;; (add-hook 'terraform-mode-hook #'terraform-format-on-save-mode)

;;; Code:

(require 'cl-lib)
(require 'rx)
(require 'hcl-mode)

(defgroup terraform nil
"Major mode of Terraform configuration file."
:group 'languages)

(defcustom terraform-indent-level 2
"The tab width to use when indenting."
:type 'integer)

(defconst terraform--block-regexp
"^\\s-*\\(provider\\|resource\\|data\\|module\\|variable\\|output\\)\\s-+\"")

(defconst terraform--atlas-regexp
"^\\s-*\\(atlas\\)\\s-*")

(defconst terraform--provisioner-regexp
"^\\s-+\\(provisioner\\)\\s-+\"")

(defconst terraform--inner-block-regexp
"^\\s-+\\(connection\\)\\s-+{"
"Inner special block.")

(defvar terraform-font-lock-keywords
`((,terraform--block-regexp 1 font-lock-function-name-face)
(,terraform--atlas-regexp 1 font-lock-function-name-face)
(,terraform--provisioner-regexp 1 font-lock-function-name-face)
(,terraform--inner-block-regexp 1 font-lock-keyword-face)
,@hcl-font-lock-keywords))

(defun terraform-format-buffer ()
"Rewrite current buffer in a canonical format using terraform fmt."
(interactive)
(let ((buf (get-buffer-create "*terraform-fmt*")))
(if (zerop (call-process-region (point-min) (point-max)
"terraform" nil buf nil "fmt" "-"))
(let ((point (point))
(window-start (window-start)))
(erase-buffer)
(insert-buffer-substring buf)
(goto-char point)
(set-window-start nil window-start))
(message "terraform fmt: %s" (with-current-buffer buf (buffer-string))))
(kill-buffer buf)))

(define-minor-mode terraform-format-on-save-mode
"Run terraform-format-buffer before saving current buffer."
:lighter ""
(if terraform-format-on-save-mode
(add-hook 'before-save-hook #'terraform-format-buffer nil t)
(remove-hook 'before-save-hook #'terraform-format-buffer t)))

;;;###autoload
(define-derived-mode terraform-mode hcl-mode "Terraform"
"Major mode for editing terraform configuration file"

(setq font-lock-defaults '((terraform-font-lock-keywords)))

;; indentation
(make-local-variable 'terraform-indent-level)
(setq hcl-indent-level terraform-indent-level)

;; imenu
(setq imenu-generic-expression
'(("resource" "^resource\\s-+\"[^\"]+\"\\s-+\"\\([^\"]+\\)\"" 1)
("data" "^data\\s-+\"[^\"]+\"\\s-+\"\\([^\"]+\\)\"" 1)
("provider" "^provider\\s-+\"\\([^\"]+\\)\"" 1)
("module" "^module\\s-+\"\\([^\"]+\\)\"" 1)
("variable" "^variable\\s-+\"\\([^\"]+\\)\"" 1)
("output" "^output\\s-+\"\\([^\"]+\\)\"" 1)))
(imenu-add-to-menubar "Index"))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.tf\\(vars\\)?\\'" . terraform-mode))

(provide 'terraform-mode)

;;; terraform-mode.el ends here
Loading

0 comments on commit 3bd6274

Please sign in to comment.