smartmachine 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -14
- data/lib/smart_machine/apps/container.rb +1 -0
- data/lib/smart_machine/apps/manager.rb +1 -1
- data/lib/smart_machine/base.rb +6 -0
- data/lib/smart_machine/buildpackers/buildpacker.rb +49 -1
- data/lib/smart_machine/buildpackers/rails.rb +87 -12
- data/lib/smart_machine/commands/grid.rb +8 -0
- data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +0 -3
- data/lib/smart_machine/commands/grid_commands/nextcloud.rb +65 -0
- data/lib/smart_machine/commands/grid_commands/terminal.rb +107 -0
- data/lib/smart_machine/commands/machine.rb +8 -0
- data/lib/smart_machine/configuration.rb +23 -1
- data/lib/smart_machine/credentials.rb +9 -0
- data/lib/smart_machine/docker.rb +10 -9
- data/lib/smart_machine/engine.rb +44 -9
- data/lib/smart_machine/grids/nextcloud.rb +93 -0
- data/lib/smart_machine/grids/prereceiver/Dockerfile +10 -13
- data/lib/smart_machine/grids/redis.rb +8 -3
- data/lib/smart_machine/grids/redmine.rb +61 -0
- data/lib/smart_machine/grids/terminal/entrypoint.rb +95 -0
- data/lib/smart_machine/grids/terminal/haproxy.cfg +45 -0
- data/lib/smart_machine/grids/terminal/init.el +310 -0
- data/lib/smart_machine/grids/terminal/wetty.rb +44 -0
- data/lib/smart_machine/grids/terminal.rb +179 -0
- data/lib/smart_machine/machine.rb +26 -5
- data/lib/smart_machine/syncer.rb +8 -7
- data/lib/smart_machine/templates/dotsmartmachine/config/nextcloud.yml +27 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +6 -1
- data/lib/smart_machine/templates/dotsmartmachine/config/terminal.yml +13 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/fastcgi.conf +1 -1
- data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/nginx.tmpl +448 -314
- data/lib/smart_machine/version.rb +3 -3
- data/lib/smart_machine.rb +3 -1
- metadata +57 -24
- data/lib/smart_machine/buildpackers/rails/Dockerfile +0 -21
- data/lib/smart_machine/commands/grid_commands/scheduler.rb +0 -15
- data/lib/smart_machine/engine/Dockerfile +0 -30
- data/lib/smart_machine/grids/elasticsearch/.keep +0 -0
- data/lib/smart_machine/grids/minio/.keep +0 -0
- data/lib/smart_machine/grids/nginx/.keep +0 -0
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/APKBUILD +0 -49
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.confd +0 -6
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.initd +0 -43
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.pre-install +0 -7
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/APKINDEX.tar.gz +0 -0
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-1.1.1-r4.apk +0 -0
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-doc-1.1.1-r4.apk +0 -0
- data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-openrc-1.1.1-r4.apk +0 -0
- data/lib/smart_machine/grids/redis/.keep +0 -0
- data/lib/smart_machine/grids/scheduler/Dockerfile +0 -14
- data/lib/smart_machine/grids/scheduler.rb +0 -188
- data/lib/smart_machine/templates/dotsmartmachine/grids/scheduler/crontabs/.keep +0 -0
@@ -0,0 +1,310 @@
|
|
1
|
+
(custom-set-variables
|
2
|
+
;; custom-set-variables was added by Custom.
|
3
|
+
;; If you edit it by hand, you could mess it up, so be careful.
|
4
|
+
;; Your init file should contain only one such instance.
|
5
|
+
;; If there is more than one, they won't work right.
|
6
|
+
'(package-selected-packages
|
7
|
+
'(polymode ruby-electric ruby-electric-mode ruby-mode dockerfile-mode expand-region flycheck zenburn-theme multi-vterm vterm yaml-mode web-mode use-package undo-tree typescript-mode smartparens robe rbenv rainbow-delimiters projectile-rails osx-trash magit logview indent-guide diredfl dired-sidebar dired-narrow dired-git-info diff-hl company clipetty bundler)))
|
8
|
+
(custom-set-faces
|
9
|
+
;; custom-set-faces was added by Custom.
|
10
|
+
;; If you edit it by hand, you could mess it up, so be careful.
|
11
|
+
;; Your init file should contain only one such instance.
|
12
|
+
;; If there is more than one, they won't work right.
|
13
|
+
'(diff-hl-change ((t (:foreground "#f7ca88" :background "#f7ca88"))))
|
14
|
+
'(diff-hl-delete ((t (:foreground "#ab4642" :background "#ab4642"))))
|
15
|
+
'(diff-hl-insert ((t (:foreground "#a1b56c" :background "#a1b56c")))))
|
16
|
+
|
17
|
+
;; Add melpa to package-archives list.
|
18
|
+
(require 'package)
|
19
|
+
(add-to-list 'package-archives
|
20
|
+
'("melpa" . "http://melpa.org/packages/") t)
|
21
|
+
|
22
|
+
;; use-package
|
23
|
+
;; Ensure use-package is installed.
|
24
|
+
(unless (package-installed-p 'use-package)
|
25
|
+
(package-refresh-contents)
|
26
|
+
(package-install 'use-package))
|
27
|
+
;; Configure and load use-package.
|
28
|
+
(setq use-package-always-ensure t)
|
29
|
+
(eval-when-compile
|
30
|
+
(defvar use-package-verbose t)
|
31
|
+
(require 'use-package))
|
32
|
+
|
33
|
+
;; Disable menu bar in emacs.
|
34
|
+
(menu-bar-mode -1)
|
35
|
+
|
36
|
+
;; change backup file directory for emacs
|
37
|
+
(setq backup-directory-alist `(("." . ,(concat user-emacs-directory "backups"))))
|
38
|
+
|
39
|
+
;; Use gls instead of the default ls on darwain systems like Apple.
|
40
|
+
;; coreutils is needed to be installed for gls. You can get it with brew install coreutils.
|
41
|
+
;; This solves the --dired problem on macOS and lists the directories first in dired.
|
42
|
+
(when (string= system-type "darwin")
|
43
|
+
(setq dired-use-ls-dired t
|
44
|
+
insert-directory-program "/usr/local/bin/gls"
|
45
|
+
dired-listing-switches "-aBhl --ignore=.DS_Store --ignore=.git --ignore=.bundle --ignore=.byebug_history --group-directories-first"))
|
46
|
+
|
47
|
+
;; Hide dired details on startup
|
48
|
+
(add-hook 'dired-mode-hook
|
49
|
+
(lambda ()
|
50
|
+
(dired-hide-details-mode)))
|
51
|
+
|
52
|
+
;; Setup initial screen
|
53
|
+
(setq initial-buffer-choice (expand-file-name "."))
|
54
|
+
|
55
|
+
;; Org mode key bindings
|
56
|
+
(global-set-key (kbd "C-c l") 'org-store-link)
|
57
|
+
(global-set-key (kbd "C-c a") 'org-agenda)
|
58
|
+
(global-set-key (kbd "C-c c") 'org-capture)
|
59
|
+
|
60
|
+
;; Display line numbers.
|
61
|
+
(when (version<= "26.0.50" emacs-version)
|
62
|
+
(global-display-line-numbers-mode))
|
63
|
+
|
64
|
+
;; Highlight current line.
|
65
|
+
(global-hl-line-mode +1)
|
66
|
+
|
67
|
+
;; Revert buffers if they've changed on disk
|
68
|
+
(global-auto-revert-mode 1)
|
69
|
+
(setq auto-revert-verbose nil)
|
70
|
+
|
71
|
+
;; Exclude directories from grep.
|
72
|
+
(eval-after-load 'grep
|
73
|
+
'(progn
|
74
|
+
(add-to-list 'grep-find-ignored-directories "log")
|
75
|
+
(add-to-list 'grep-find-ignored-directories "node_modules")
|
76
|
+
(add-to-list 'grep-find-ignored-directories "public/packs")
|
77
|
+
(add-to-list 'grep-find-ignored-directories "storage")
|
78
|
+
(add-to-list 'grep-find-ignored-directories "tmp")
|
79
|
+
(add-to-list 'grep-find-ignored-directories ".bundle")
|
80
|
+
(add-to-list 'grep-find-ignored-directories "auto")
|
81
|
+
(add-to-list 'grep-find-ignored-directories "elpa")))
|
82
|
+
|
83
|
+
(use-package zenburn-theme
|
84
|
+
:ensure t
|
85
|
+
:config
|
86
|
+
(load-theme 'zenburn t)
|
87
|
+
(zenburn-with-color-variables
|
88
|
+
(custom-theme-set-faces
|
89
|
+
'zenburn
|
90
|
+
`(hl-line-face ((t (:background ,zenburn-bg+05 ))))
|
91
|
+
`(hl-line ((t (:background ,zenburn-bg+05 ))))
|
92
|
+
`(region ((nil (:background ,zenburn-bg+2))))
|
93
|
+
)))
|
94
|
+
|
95
|
+
(use-package logview
|
96
|
+
:ensure t)
|
97
|
+
|
98
|
+
(use-package dired-hacks-utils
|
99
|
+
:ensure t)
|
100
|
+
|
101
|
+
(use-package dired-narrow
|
102
|
+
:ensure t
|
103
|
+
:bind (:map dired-mode-map
|
104
|
+
("/" . dired-narrow)))
|
105
|
+
|
106
|
+
(use-package dired-subtree
|
107
|
+
:ensure t
|
108
|
+
:after dired
|
109
|
+
:bind (:map dired-mode-map
|
110
|
+
("TAB" . dired-subtree-toggle)
|
111
|
+
("<backtab>" . dired-subtree-remove))
|
112
|
+
:config
|
113
|
+
(setq dired-subtree-use-backgrounds nil))
|
114
|
+
|
115
|
+
(use-package dired-git-info
|
116
|
+
:ensure t
|
117
|
+
:bind (:map dired-mode-map
|
118
|
+
(")" . dired-git-info-mode)))
|
119
|
+
|
120
|
+
(use-package dired-sidebar
|
121
|
+
:ensure t
|
122
|
+
:commands (dired-sidebar-toggle-sidebar)
|
123
|
+
:bind (("C-x C-n" . dired-sidebar-toggle-sidebar))
|
124
|
+
:init
|
125
|
+
(setq dired-sidebar-use-term-integration t)
|
126
|
+
(setq dired-sidebar-use-custom-font t))
|
127
|
+
|
128
|
+
(use-package typescript-mode
|
129
|
+
:ensure t)
|
130
|
+
|
131
|
+
(use-package clipetty
|
132
|
+
:ensure t
|
133
|
+
:bind ("M-w" . clipetty-kill-ring-save))
|
134
|
+
|
135
|
+
(use-package osx-trash
|
136
|
+
:config
|
137
|
+
(when (eq system-type 'darwin)
|
138
|
+
(osx-trash-setup))
|
139
|
+
(setq delete-by-moving-to-trash t))
|
140
|
+
|
141
|
+
(use-package undo-tree
|
142
|
+
:config
|
143
|
+
(global-undo-tree-mode))
|
144
|
+
|
145
|
+
(use-package indent-guide
|
146
|
+
:config
|
147
|
+
(setq indent-guide-delay 0.3)
|
148
|
+
(indent-guide-global-mode))
|
149
|
+
|
150
|
+
(use-package rainbow-delimiters
|
151
|
+
:config
|
152
|
+
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
|
153
|
+
|
154
|
+
(use-package smartparens
|
155
|
+
:config
|
156
|
+
(require 'smartparens-config))
|
157
|
+
(add-hook 'prog-mode-hook #'smartparens-mode)
|
158
|
+
|
159
|
+
(use-package ruby-mode
|
160
|
+
:config
|
161
|
+
(add-to-list 'auto-mode-alist
|
162
|
+
'("\\.\\(?:cap\\|gemspec\\|irbrc\\|gemrc\\|rake\\|rb\\|ru\\|thor\\)\\'" . ruby-mode))
|
163
|
+
(add-to-list 'auto-mode-alist
|
164
|
+
'("\\(?:Brewfile\\|Capfile\\|Gemfile\\(?:\\.[a-zA-Z0-9._-]+\\)?\\|[rR]akefile\\)\\'" . ruby-mode)))
|
165
|
+
|
166
|
+
(use-package ruby-electric
|
167
|
+
:config
|
168
|
+
(add-hook 'ruby-mode-hook 'ruby-electric-mode))
|
169
|
+
|
170
|
+
(use-package robe
|
171
|
+
:config
|
172
|
+
(eval-after-load 'company '(push 'company-robe company-backends))
|
173
|
+
(global-robe-mode))
|
174
|
+
|
175
|
+
(use-package company
|
176
|
+
:config
|
177
|
+
(add-hook 'after-init-hook 'global-company-mode))
|
178
|
+
|
179
|
+
(use-package bundler)
|
180
|
+
|
181
|
+
(use-package rbenv
|
182
|
+
:config
|
183
|
+
(global-rbenv-mode))
|
184
|
+
|
185
|
+
(use-package yaml-mode
|
186
|
+
:config
|
187
|
+
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
|
188
|
+
(add-hook 'yaml-mode-hook '(lambda () (define-key yaml-mode-map "\C-m" 'newline-and-indent))))
|
189
|
+
|
190
|
+
(use-package web-mode
|
191
|
+
:config
|
192
|
+
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
|
193
|
+
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
|
194
|
+
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
|
195
|
+
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
|
196
|
+
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
|
197
|
+
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
|
198
|
+
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
|
199
|
+
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
|
200
|
+
(add-to-list 'auto-mode-alist '("\\.js?\\'" . web-mode))
|
201
|
+
(add-to-list 'auto-mode-alist '("\\.jsx?\\'" . web-mode))
|
202
|
+
(add-to-list 'auto-mode-alist '("\\.css?\\'" . web-mode))
|
203
|
+
(add-to-list 'auto-mode-alist '("\\.scss?\\'" . web-mode))
|
204
|
+
(add-to-list 'auto-mode-alist '("\\.xml?\\'" . web-mode)))
|
205
|
+
|
206
|
+
(use-package projectile
|
207
|
+
:config
|
208
|
+
(projectile-mode +1)
|
209
|
+
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
|
210
|
+
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map))
|
211
|
+
|
212
|
+
(use-package projectile-rails
|
213
|
+
:config
|
214
|
+
(projectile-rails-global-mode)
|
215
|
+
(define-key projectile-rails-mode-map (kbd "C-c r") 'projectile-rails-command-map))
|
216
|
+
|
217
|
+
;; Extra font lock rules for a more colourful dired.
|
218
|
+
(use-package diredfl
|
219
|
+
:ensure t
|
220
|
+
:config
|
221
|
+
(diredfl-global-mode))
|
222
|
+
|
223
|
+
(use-package diff-hl
|
224
|
+
:custom-face
|
225
|
+
;; Change colors for insert, delete and change indicators in diff-hl
|
226
|
+
(diff-hl-insert ((t (:foreground "#a1b56c" :background "#a1b56c"))))
|
227
|
+
(diff-hl-delete ((t (:foreground "#ab4642" :background "#ab4642"))))
|
228
|
+
(diff-hl-change ((t (:foreground "#f7ca88" :background "#f7ca88"))))
|
229
|
+
|
230
|
+
:hook
|
231
|
+
;; To enable in all Dired buffers.
|
232
|
+
(dired-mode . diff-hl-dired-mode)
|
233
|
+
;; diff-hl integration with magit.
|
234
|
+
(magit-pre-refresh . diff-hl-magit-pre-refresh)
|
235
|
+
(magit-post-refresh . diff-hl-magit-post-refresh)
|
236
|
+
|
237
|
+
:config
|
238
|
+
;; it modifies 'diff-hl-mode' to use the margin instead of the fringe. The unless condition does this only for terminal.
|
239
|
+
(unless (window-system) (diff-hl-margin-mode))
|
240
|
+
;; This mode enables diffing on-the-fly.
|
241
|
+
(diff-hl-flydiff-mode)
|
242
|
+
;; Highlight uncommitted changes using VCHighlight uncommitted changes using VC.
|
243
|
+
(global-diff-hl-mode))
|
244
|
+
|
245
|
+
;; A Git porcelain inside Emacs.
|
246
|
+
(use-package magit
|
247
|
+
:ensure t
|
248
|
+
|
249
|
+
:commands (magit-add-section-hook magit-section-initial-visibility-alist)
|
250
|
+
|
251
|
+
:init
|
252
|
+
(setq magit-diff-refine-hunk 'all)
|
253
|
+
(setq magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
|
254
|
+
|
255
|
+
:config
|
256
|
+
;; To list branches and tags directly in your Magit status buffer.
|
257
|
+
(magit-add-section-hook 'magit-status-sections-hook 'magit-insert-local-branches nil t)
|
258
|
+
(add-to-list 'magit-section-initial-visibility-alist '(local . hide))
|
259
|
+
(magit-add-section-hook 'magit-status-sections-hook 'magit-insert-remote-branches nil t)
|
260
|
+
(add-to-list 'magit-section-initial-visibility-alist '(remote . hide))
|
261
|
+
(magit-add-section-hook 'magit-status-sections-hook 'magit-insert-tags nil t)
|
262
|
+
(add-to-list 'magit-section-initial-visibility-alist '(tags . hide)))
|
263
|
+
|
264
|
+
;; Emacs-libvterm (vterm) is fully-fledged terminal emulator inside GNU Emacs based on libvterm, a C library.
|
265
|
+
(use-package vterm
|
266
|
+
:ensure t
|
267
|
+
:config
|
268
|
+
(define-key vterm-mode-map (kbd "C-q") #'vterm-send-next-key)
|
269
|
+
:custom
|
270
|
+
(vterm-always-compile-module t))
|
271
|
+
;; Managing multiple vterm buffers in Emacs.
|
272
|
+
(use-package multi-vterm
|
273
|
+
:ensure t)
|
274
|
+
|
275
|
+
;; Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs.
|
276
|
+
(use-package flycheck
|
277
|
+
:ensure t
|
278
|
+
:init
|
279
|
+
(global-flycheck-mode))
|
280
|
+
|
281
|
+
;; Expand region increases the selected region by semantic units. Just keep pressing the key until it selects what you want.
|
282
|
+
(use-package expand-region
|
283
|
+
:ensure t
|
284
|
+
:bind
|
285
|
+
("C-=" . er/expand-region))
|
286
|
+
|
287
|
+
(use-package dockerfile-mode
|
288
|
+
:ensure t)
|
289
|
+
|
290
|
+
;; Polymode is a framework for multiple major modes (MMM) inside a single Emacs buffer.
|
291
|
+
(use-package polymode
|
292
|
+
:ensure t
|
293
|
+
|
294
|
+
:config
|
295
|
+
(with-eval-after-load "polymode"
|
296
|
+
(eieio-oset-default pm-inner-chunkmode :adjust-face -2))
|
297
|
+
(define-innermode poly-dockerfile-innermode
|
298
|
+
:mode 'dockerfile-mode
|
299
|
+
:head-matcher "<<[~-]?\'?DOCKERFILE_?\'?.*\r?\n"
|
300
|
+
:tail-matcher "[ \t]*DOCKERFILE_?.*\r?\n")
|
301
|
+
(define-polymode poly-ruby-mode
|
302
|
+
:hostmode 'poly-ruby-hostmode
|
303
|
+
:innermodes '(poly-dockerfile-innermode))
|
304
|
+
(add-to-list 'auto-mode-alist '("\\.rb" . poly-ruby-mode))
|
305
|
+
|
306
|
+
:hook
|
307
|
+
(poly-ruby-mode . (lambda ()
|
308
|
+
(setq dockerfile-enable-auto-indent nil))))
|
309
|
+
|
310
|
+
;;; init.el ends here
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SmartMachine
|
2
|
+
class Grids
|
3
|
+
class Terminal < SmartMachine::Base
|
4
|
+
class Wetty
|
5
|
+
def initialize(name:, host:, ssh_host:)
|
6
|
+
@name = name
|
7
|
+
@host = host
|
8
|
+
@ssh_host = ssh_host
|
9
|
+
end
|
10
|
+
|
11
|
+
def uper
|
12
|
+
raise "Error: Could not create container: #{@name}" unless system(command.compact.join(' '), out: File::NULL)
|
13
|
+
raise "Error: Could not start container: #{@name}" unless system("docker start #{@name}", out: File::NULL)
|
14
|
+
|
15
|
+
puts "Created & Started container: #{@name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def downer
|
19
|
+
raise "Error: Could not stop container: #{@name}" unless system("docker stop '#{@name}'", out: File::NULL)
|
20
|
+
raise "Error: Could not remove container: #{@name}" unless system("docker rm '#{@name}'", out: File::NULL)
|
21
|
+
|
22
|
+
puts "Stopped & Removed container: #{@name}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def command
|
28
|
+
[
|
29
|
+
'docker create',
|
30
|
+
"--name='#{@name}'",
|
31
|
+
"--env VIRTUAL_HOST=#{@host}",
|
32
|
+
"--env VIRTUAL_PATH=/",
|
33
|
+
"--env LETSENCRYPT_HOST=#{@host}",
|
34
|
+
"--env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email}",
|
35
|
+
'--env LETSENCRYPT_TEST=false',
|
36
|
+
"--restart='always'",
|
37
|
+
"--network='nginx-network'",
|
38
|
+
"wettyoss/wetty --base=/ --ssh-host=#{@ssh_host} --ssh-port=2223 --force-ssh=true --title=Terminal"
|
39
|
+
]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module SmartMachine
|
2
|
+
class Grids
|
3
|
+
class Terminal < SmartMachine::Base
|
4
|
+
def initialize(name:)
|
5
|
+
config = SmartMachine.config.grids.terminal.dig(name.to_sym)
|
6
|
+
raise "terminal config for #{name} not found." unless config
|
7
|
+
|
8
|
+
@image = "smartmachine/terminal:#{SmartMachine.version}"
|
9
|
+
@host = config.dig(:host)
|
10
|
+
@frontend = config.dig(:frontend)
|
11
|
+
@packages = config.dig(:packages)
|
12
|
+
@username = config.dig(:username)
|
13
|
+
@password = config.dig(:password)
|
14
|
+
|
15
|
+
@name = name.to_s
|
16
|
+
@home_dir = File.expand_path('~')
|
17
|
+
|
18
|
+
@wetty = Wetty.new(name: "#{@name}-wetty", host: @host, ssh_host: @name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def installer
|
22
|
+
unless system("docker image inspect #{@image}", [:out, :err] => File::NULL)
|
23
|
+
puts "-----> Creating image #{@image} ... "
|
24
|
+
command = [
|
25
|
+
"docker image build -t #{@image}",
|
26
|
+
"--build-arg SMARTMACHINE_VERSION=#{SmartMachine.version}",
|
27
|
+
"-f- #{SmartMachine.config.gem_dir}/lib/smart_machine/grids/terminal",
|
28
|
+
"<<'EOF'\n#{dockerfile}EOF"
|
29
|
+
]
|
30
|
+
if system(command.join(" "), out: File::NULL)
|
31
|
+
puts "done"
|
32
|
+
else
|
33
|
+
raise "Error: Could not install image: #{@image}"
|
34
|
+
end
|
35
|
+
else
|
36
|
+
raise "Error: Image already installed: #{@image}. Please uninstall using 'smartmachine grids terminal uninstall' and try installing again."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def uninstaller
|
41
|
+
unless system("docker inspect -f '{{.State.Running}}' '#{@name}'", [:out, :err] => File::NULL)
|
42
|
+
if system("docker image inspect #{@image}", [:out, :err] => File::NULL)
|
43
|
+
puts "-----> Removing image #{@image} ... "
|
44
|
+
if system("docker image rm #{@image}", out: File::NULL)
|
45
|
+
puts "done"
|
46
|
+
end
|
47
|
+
else
|
48
|
+
raise "Error: Terminal already uninstalled. Please install using 'smartmachine grids terminal install' and try uninstalling again."
|
49
|
+
end
|
50
|
+
else
|
51
|
+
raise "Error: Terminal is currently running. Please stop the terminal using 'smartmachine grids terminal down' and try uninstalling again."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def uper
|
56
|
+
if system("docker image inspect #{@image}", [:out, :err] => File::NULL)
|
57
|
+
FileUtils.mkdir_p("#{@home_dir}/machine/grids/terminal/#{@name}/backups")
|
58
|
+
|
59
|
+
# Creating & Starting containers
|
60
|
+
print "-----> Creating container #{@name} ... "
|
61
|
+
|
62
|
+
command = [
|
63
|
+
"docker create",
|
64
|
+
"--name='#{@name}'",
|
65
|
+
"--env VIRTUAL_HOST=#{@host}",
|
66
|
+
"--env VIRTUAL_PATH=#{@frontend}",
|
67
|
+
"--env VIRTUAL_PORT=80",
|
68
|
+
"--env LETSENCRYPT_HOST=#{@host}",
|
69
|
+
"--env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email}",
|
70
|
+
"--env LETSENCRYPT_TEST=false",
|
71
|
+
"--env CONTAINER_NAME='#{@name}'",
|
72
|
+
"--env PACKAGES='#{@packages.join(' ')}'",
|
73
|
+
"--env USERNAME=#{@username}",
|
74
|
+
"--env PASSWORD=#{@password}",
|
75
|
+
"--publish='2223:2223'", # TODO: Remove this published port and move it behind the reverse proxy when ready.
|
76
|
+
"--volume='#{@name}-home:/home'",
|
77
|
+
"--volume='#{@home_dir}/smartmachine/grids/terminal/#{@name}/backups:/root/backups'",
|
78
|
+
"--init",
|
79
|
+
"--restart='always'",
|
80
|
+
"--network='nginx-network'",
|
81
|
+
"#{@image}"
|
82
|
+
]
|
83
|
+
if system(command.compact.join(" "), out: File::NULL)
|
84
|
+
puts "done"
|
85
|
+
puts "-----> Starting container #{@name} ... "
|
86
|
+
if system("docker start #{@name}", out: File::NULL)
|
87
|
+
puts "done"
|
88
|
+
|
89
|
+
@wetty.uper
|
90
|
+
else
|
91
|
+
raise "Error: Could not start container: #{@name}"
|
92
|
+
end
|
93
|
+
else
|
94
|
+
raise "Error: Could not create container: #{@name}"
|
95
|
+
end
|
96
|
+
else
|
97
|
+
raise "Error: Could not find image: #{@image}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def downer
|
102
|
+
# Stopping & Removing containers - in reverse order
|
103
|
+
|
104
|
+
@wetty.downer
|
105
|
+
|
106
|
+
print "-----> Stopping container #{@name} ... "
|
107
|
+
if system("docker stop '#{@name}'", out: File::NULL)
|
108
|
+
puts "done"
|
109
|
+
print "-----> Removing container #{@name} ... "
|
110
|
+
if system("docker rm '#{@name}'", out: File::NULL)
|
111
|
+
puts "done"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
# openssh-server
|
119
|
+
# sshd needs rsyslog to output /var/log/auth.log.
|
120
|
+
# imklog module is commented in rsyslog.conf because rsyslog does not
|
121
|
+
# have privileges to run it and hence throws error on startup.
|
122
|
+
#
|
123
|
+
# fail2ban
|
124
|
+
# fail2ban needs sshd to output /var/log/auth.log.
|
125
|
+
# Otherwise it cannot start the sshd jail.
|
126
|
+
def dockerfile
|
127
|
+
file = <<~'DOCKERFILE'
|
128
|
+
ARG SMARTMACHINE_VERSION
|
129
|
+
|
130
|
+
FROM smartmachine/smartengine:$SMARTMACHINE_VERSION
|
131
|
+
LABEL maintainer="plainsource <plainsource@humanmind.me>"
|
132
|
+
|
133
|
+
RUN apt-get update && \
|
134
|
+
\
|
135
|
+
apt-get install -y --no-install-recommends sudo && \
|
136
|
+
\
|
137
|
+
apt-get install -y --no-install-recommends rsyslog openssh-server && \
|
138
|
+
mkdir -p /run/sshd && \
|
139
|
+
sed -i'.original' '/#Port 22/a Port 2223' /etc/ssh/sshd_config && \
|
140
|
+
sed -i '/#AddressFamily any/a AddressFamily inet' /etc/ssh/sshd_config && \
|
141
|
+
sed -i '/#PermitRootLogin prohibit-password/a PermitRootLogin no' /etc/ssh/sshd_config && \
|
142
|
+
sed -i '/imklog/s/^/#/' /etc/rsyslog.conf && \
|
143
|
+
\
|
144
|
+
apt-get install -y --no-install-recommends fail2ban sendmail-bin sendmail && \
|
145
|
+
cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local && \
|
146
|
+
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local && \
|
147
|
+
sed -i'.original' 's/destemail = root@localhost/#destemail = root@localhost\ndestemail = %<sysadmin_email>s/' /etc/fail2ban/jail.local && \
|
148
|
+
sed -i 's/action = %<percent>s(action_)s/#action = %<percent>s(action_)s\naction = %<percent>s(action_mwl)s/' /etc/fail2ban/jail.local && \
|
149
|
+
sed -i 's/port = ssh/#port = ssh\nport = 2223/' /etc/fail2ban/jail.local && \
|
150
|
+
\
|
151
|
+
apt-get install -y --no-install-recommends haproxy && \
|
152
|
+
mkdir -p /run/haproxy && \
|
153
|
+
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.original && \
|
154
|
+
\
|
155
|
+
apt-get install -y --no-install-recommends cmake libtool libtool-bin emacs-nox && \
|
156
|
+
mkdir -p /root/.emacs.d && \
|
157
|
+
\
|
158
|
+
apt-get install -y --no-install-recommends vim && \
|
159
|
+
\
|
160
|
+
rm -rf /var/lib/apt/lists/* && \
|
161
|
+
gem install bundler -v 2.1.4
|
162
|
+
|
163
|
+
COPY haproxy.cfg /etc/haproxy
|
164
|
+
COPY init.el /root/.emacs.d/init.el
|
165
|
+
|
166
|
+
COPY entrypoint.rb /usr/local/bin/entrypoint.rb
|
167
|
+
RUN chmod +x /usr/local/bin/entrypoint.rb
|
168
|
+
ENTRYPOINT ["entrypoint.rb"]
|
169
|
+
|
170
|
+
EXPOSE 2223 80
|
171
|
+
STOPSIGNAL SIGUSR1
|
172
|
+
CMD ["haproxy", "-W", "-db", "-f", "/etc/haproxy/haproxy.cfg"]
|
173
|
+
DOCKERFILE
|
174
|
+
|
175
|
+
format(file, "sysadmin_email": SmartMachine.config.sysadmin_email, "percent": '%')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -49,11 +49,6 @@ module SmartMachine
|
|
49
49
|
puts "New machine #{name} has been created."
|
50
50
|
end
|
51
51
|
|
52
|
-
def initial_setup
|
53
|
-
getting_started
|
54
|
-
securing_your_server
|
55
|
-
end
|
56
|
-
|
57
52
|
def run_on_machine(commands:)
|
58
53
|
commands = Array(commands).flatten
|
59
54
|
ssh = SmartMachine::SSH.new
|
@@ -62,9 +57,35 @@ module SmartMachine
|
|
62
57
|
status[:exit_code] == 0
|
63
58
|
end
|
64
59
|
|
60
|
+
def setup
|
61
|
+
getting_started
|
62
|
+
securing_your_server
|
63
|
+
end
|
64
|
+
|
65
65
|
private
|
66
66
|
|
67
67
|
def getting_started
|
68
|
+
run_on_machine(commands: "sudo apt update && sudo apt upgrade")
|
69
|
+
|
70
|
+
sysctl_lines = []
|
71
|
+
# sysctl_lines.push('# KVM uses this.')
|
72
|
+
# sysctl_lines.push('# These lines should only be activated for VM hosts and not for VM guests.')
|
73
|
+
# sysctl_lines.push('# When getting a VM from a service provider, you will usually get a VM guest and not a VM host and hence these lines should not be added.')
|
74
|
+
# sysctl_lines.push('# Prevent bridged traffic from being processed by iptables rules.')
|
75
|
+
# sysctl_lines.push('net.bridge.bridge-nf-call-ip6tables=0')
|
76
|
+
# sysctl_lines.push('net.bridge.bridge-nf-call-iptables=0')
|
77
|
+
# sysctl_lines.push('net.bridge.bridge-nf-call-arptables=0')
|
78
|
+
sysctl_lines.push('# Redis uses this.')
|
79
|
+
sysctl_lines.push('vm.overcommit_memory=1')
|
80
|
+
sysctl_lines.push('# Elasticsearch uses this.')
|
81
|
+
sysctl_lines.push('vm.max_map_count=262144')
|
82
|
+
commands = [
|
83
|
+
"sudo touch /etc/sysctl.d/99-smartmachine.conf",
|
84
|
+
"echo -e '#{sysctl_lines.join('\n')}' | sudo tee /etc/sysctl.d/99-smartmachine.conf",
|
85
|
+
"sudo sysctl -p /etc/sysctl.d/99-smartmachine.conf"
|
86
|
+
]
|
87
|
+
run_on_machine(commands: commands)
|
88
|
+
|
68
89
|
# apt install locales-all
|
69
90
|
|
70
91
|
# puts 'You may be prompted to make a menu selection when the Grub package is updated on Ubuntu. If prompted, select keep the local version currently installed.'
|
data/lib/smart_machine/syncer.rb
CHANGED
@@ -68,6 +68,9 @@ module SmartMachine
|
|
68
68
|
'grids/mysql',
|
69
69
|
'grids/mysql/***',
|
70
70
|
|
71
|
+
'grids/nextcloud',
|
72
|
+
'grids/nextcloud/***',
|
73
|
+
|
71
74
|
'grids/nginx',
|
72
75
|
'grids/nginx/certificates/***',
|
73
76
|
|
@@ -77,11 +80,11 @@ module SmartMachine
|
|
77
80
|
'grids/redis',
|
78
81
|
'grids/redis/***',
|
79
82
|
|
80
|
-
'grids/scheduler',
|
81
|
-
'grids/scheduler/crontabs/***',
|
82
|
-
|
83
83
|
'grids/solr',
|
84
84
|
'grids/solr/solr/***',
|
85
|
+
|
86
|
+
'grids/terminal',
|
87
|
+
'grids/terminal/***',
|
85
88
|
]
|
86
89
|
files.join(',')
|
87
90
|
end
|
@@ -105,8 +108,10 @@ module SmartMachine
|
|
105
108
|
'config/elasticsearch.yml',
|
106
109
|
'config/minio.yml',
|
107
110
|
'config/mysql.yml',
|
111
|
+
'config/nextcloud.yml',
|
108
112
|
'config/prereceiver.yml',
|
109
113
|
'config/redis.yml',
|
114
|
+
'config/terminal.yml',
|
110
115
|
|
111
116
|
'grids',
|
112
117
|
|
@@ -117,10 +122,6 @@ module SmartMachine
|
|
117
122
|
'grids/nginx/fastcgi.conf',
|
118
123
|
'grids/nginx/nginx.tmpl',
|
119
124
|
|
120
|
-
'grids/scheduler',
|
121
|
-
'grids/scheduler/crontabs',
|
122
|
-
'grids/scheduler/crontabs/.keep',
|
123
|
-
|
124
125
|
'grids/solr',
|
125
126
|
'grids/solr/solr',
|
126
127
|
'grids/solr/solr/.keep',
|
@@ -0,0 +1,27 @@
|
|
1
|
+
nextcloudone:
|
2
|
+
image: "nextcloud:25.0.1-apache"
|
3
|
+
host: "yournextcloudone.yourdomain.com"
|
4
|
+
admin_user: <%= SmartMachine.credentials.dig(:nextcloudone, :admin_user) %>
|
5
|
+
admin_password: <%= SmartMachine.credentials.dig(:nextcloudone, :admin_password) %>
|
6
|
+
mysql_host: mysqlone
|
7
|
+
mysql_port: 3306
|
8
|
+
mysql_user: <%= SmartMachine.credentials.dig(:nextcloudone, :mysql_user) %>
|
9
|
+
mysql_password: <%= SmartMachine.credentials.dig(:nextcloudone, :mysql_password) %>
|
10
|
+
mysql_database_name: <%= SmartMachine.credentials.dig(:nextcloudone, :mysql_database_name) %>
|
11
|
+
redis_host: redisone
|
12
|
+
redis_port: 6379
|
13
|
+
redis_password: <%= SmartMachine.credentials.dig(:redisone, :password) %>
|
14
|
+
|
15
|
+
# nextcloudtwo:
|
16
|
+
# image: "nextcloud:25.0.1-apache"
|
17
|
+
# host: "yournextcloudtwo.yourdomain.com"
|
18
|
+
# admin_user: <%= SmartMachine.credentials.dig(:nextcloudtwo, :admin_user) %>
|
19
|
+
# admin_password: <%= SmartMachine.credentials.dig(:nextcloudtwo, :admin_password) %>
|
20
|
+
# mysql_host: mysqlone
|
21
|
+
# mysql_port: 3306
|
22
|
+
# mysql_user: <%= SmartMachine.credentials.dig(:nextcloudtwo, :mysql_user) %>
|
23
|
+
# mysql_password: <%= SmartMachine.credentials.dig(:nextcloudtwo, :mysql_password) %>
|
24
|
+
# mysql_database_name: <%= SmartMachine.credentials.dig(:nextcloudtwo, :mysql_database_name) %>
|
25
|
+
# redis_host: redistwo
|
26
|
+
# redis_port: 6380
|
27
|
+
# redis_password: <%= SmartMachine.credentials.dig(:redistwo, :password) %>
|
@@ -1,12 +1,17 @@
|
|
1
|
+
# For redis modules you need to use the image redislabs/redismod:latest
|
2
|
+
# https://hub.docker.com/r/redislabs/redismod
|
3
|
+
|
1
4
|
redisone:
|
5
|
+
image: "redis:6.2.6-alpine3.15"
|
2
6
|
port: 6379
|
3
7
|
password: <%= SmartMachine.credentials.dig(:redisone, :password) %>
|
4
8
|
appendonly: "yes"
|
5
9
|
maxmemory: 250MB
|
6
10
|
maxmemory_policy: allkeys-lfu
|
7
|
-
modules: []
|
11
|
+
# modules: []
|
8
12
|
|
9
13
|
# redistwo:
|
14
|
+
# image: "redis:6.2.6-alpine3.15"
|
10
15
|
# port: 6380
|
11
16
|
# password: <%= SmartMachine.credentials.dig(:redistwo, :password) %>
|
12
17
|
# appendonly: "yes"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
terminalone:
|
2
|
+
host: "yourterminalone.yourdomain.com"
|
3
|
+
frontend: "/frontend"
|
4
|
+
username: <%= SmartMachine.credentials.dig(:terminalone, :username) %>
|
5
|
+
password: <%= SmartMachine.credentials.dig(:terminalone, :password) %>
|
6
|
+
packages: []
|
7
|
+
|
8
|
+
# terminaltwo:
|
9
|
+
# host: "yourterminaltwo.yourdomain.com"
|
10
|
+
# frontend: "/frontend"
|
11
|
+
# username: <%= SmartMachine.credentials.dig(:terminaltwo, :username) %>
|
12
|
+
# password: <%= SmartMachine.credentials.dig(:terminaltwo, :password) %>
|
13
|
+
# packages: []
|