mrsk 0.0.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +193 -77
- data/bin/mrsk +5 -0
- data/lib/mrsk/cli/accessory.rb +85 -0
- data/lib/mrsk/cli/app.rb +123 -0
- data/lib/mrsk/cli/base.rb +48 -0
- data/lib/mrsk/cli/build.rb +53 -0
- data/lib/mrsk/cli/main.rb +110 -0
- data/lib/mrsk/cli/prune.rb +19 -0
- data/lib/mrsk/cli/registry.rb +18 -0
- data/lib/mrsk/cli/server.rb +8 -0
- data/lib/mrsk/cli/templates/deploy.yml +17 -0
- data/lib/mrsk/cli/traefik.rb +77 -0
- data/lib/mrsk/cli.rb +9 -0
- data/lib/mrsk/commander.rb +45 -5
- data/lib/mrsk/commands/accessory.rb +61 -0
- data/lib/mrsk/commands/app.rb +50 -10
- data/lib/mrsk/commands/base.rb +13 -9
- data/lib/mrsk/commands/builder/base.rb +26 -0
- data/lib/mrsk/commands/builder/multiarch/remote.rb +12 -4
- data/lib/mrsk/commands/builder/multiarch.rb +17 -9
- data/lib/mrsk/commands/builder/native/remote.rb +71 -0
- data/lib/mrsk/commands/builder/native.rb +3 -7
- data/lib/mrsk/commands/builder.rb +11 -7
- data/lib/mrsk/commands/traefik.rb +13 -3
- data/lib/mrsk/configuration/accessory.rb +60 -0
- data/lib/mrsk/configuration/role.rb +46 -14
- data/lib/mrsk/configuration.rb +86 -43
- data/lib/mrsk/sshkit_with_ext.rb +12 -0
- data/lib/mrsk/utils.rb +29 -0
- data/lib/mrsk/version.rb +1 -1
- data/lib/mrsk.rb +0 -1
- metadata +40 -18
- data/lib/mrsk/engine.rb +0 -4
- data/lib/tasks/mrsk/app.rake +0 -97
- data/lib/tasks/mrsk/build.rake +0 -52
- data/lib/tasks/mrsk/mrsk.rake +0 -37
- data/lib/tasks/mrsk/prune.rake +0 -18
- data/lib/tasks/mrsk/registry.rake +0 -16
- data/lib/tasks/mrsk/server.rake +0 -11
- data/lib/tasks/mrsk/setup.rb +0 -6
- data/lib/tasks/mrsk/templates/deploy.yml +0 -24
- data/lib/tasks/mrsk/templates/mrsk +0 -8
- data/lib/tasks/mrsk/traefik.rake +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04a17f68f19cfaf130747feded6450c389fdcb01bb83c4d44b1acb0c33d6fb60
|
4
|
+
data.tar.gz: 4d60e6c22acd3bf07fa22b0e488138166cf2265cedcd102ebb3245bb6318f5e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 379a355dafd696bbe470367c712e318e6ff9b215143059bde147dc1fdca2870bc7e46a1f47057976c2c6a5ec2601ca7cef722d928c33d3b0f1ee0700a1ee934c
|
7
|
+
data.tar.gz: b0a6a7e0efa5824e116c3728726a3be1d6c9310903eefa992411a2d91731dddd8db6903d6a8697c5d5643b831b39adad9ec088ff28262d5b79e4f4aad3a90c46
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# MRSK
|
2
2
|
|
3
|
-
MRSK
|
3
|
+
MRSK deploys Rails apps in containers to servers running Docker with zero downtime. It uses the dynamic reverse-proxy Traefik to hold requests while the new application container is started and the old one is stopped. It works seamlessly across multiple hosts, using SSHKit to execute commands.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Install MRSK globally with `gem install mrsk`. Then, inside your app directory, run `mrsk install`. Now edit the new file `config/deploy.yml`. It could look as simple as this:
|
8
8
|
|
9
9
|
```yaml
|
10
10
|
service: hey
|
@@ -13,48 +13,48 @@ servers:
|
|
13
13
|
- 192.168.0.1
|
14
14
|
- 192.168.0.2
|
15
15
|
registry:
|
16
|
-
username:
|
17
|
-
password: <%=
|
18
|
-
```
|
19
|
-
|
20
|
-
Then ensure your encrypted credentials have the registry username + password by editing them with `rails credentials:edit`:
|
21
|
-
|
22
|
-
```
|
23
|
-
registry:
|
24
|
-
username: real-user-name
|
25
|
-
password: real-registry-password-or-token
|
16
|
+
username: registry-user-name
|
17
|
+
password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %>
|
26
18
|
```
|
27
19
|
|
28
20
|
Now you're ready to deploy a multi-arch image to the servers:
|
29
21
|
|
30
22
|
```
|
31
|
-
|
23
|
+
MRSK_REGISTRY_PASSWORD=pw mrsk deploy
|
32
24
|
```
|
33
25
|
|
34
26
|
This will:
|
35
27
|
|
36
|
-
1.
|
37
|
-
2.
|
38
|
-
3.
|
39
|
-
4.
|
40
|
-
5.
|
41
|
-
6.
|
42
|
-
7.
|
43
|
-
8.
|
28
|
+
1. Connect to the servers over SSH (using root by default, authenticated by your loaded ssh key)
|
29
|
+
2. Install Docker on any server that might be missing it (using apt-get)
|
30
|
+
3. Log into the registry both locally and remotely
|
31
|
+
4. Build the image using the standard Dockerfile in the root of the application.
|
32
|
+
5. Push the image to the registry.
|
33
|
+
6. Pull the image from the registry on the servers.
|
34
|
+
7. Ensure Traefik is running and accepting traffic on port 80.
|
35
|
+
8. Stop any containers running a previous versions of the app.
|
36
|
+
9. Start a new container with the version of the app that matches the current git version hash.
|
37
|
+
10. Prune unused images and stopped containers to ensure servers don't fill up.
|
44
38
|
|
45
39
|
Voila! All the servers are now serving the app on port 80. If you're just running a single server, you're ready to go. If you're running multiple servers, you need to put a load balancer in front of them.
|
46
40
|
|
41
|
+
## Why not just run Capistrano or Kubernetes?
|
42
|
+
|
43
|
+
MRSK basically is Capistrano for Containers, which allow us to use vanilla servers as the hosts. No need to ensure that the servers have just the right version of Ruby or other dependencies you need. That all lives in the Docker image now. You can boot a brand new Ubuntu (or whatever) server, add it to the deploy servers of MRSK, and it'll be auto-provisioned with Docker, and run right away. Docker's layer caching also allows for quicker deployments with less mucking about on the server. And the images built for MRSK can be used for CI or later introspection.
|
44
|
+
|
45
|
+
Kubernetes is a beast. Running it yourself on your own hardware is not for the faint of heart. It's a fine option if you want to run on someone else's platform, like Render or Fly, but if you'd like the freedom to move between cloud and your own hardware, or even mix the two, MRSK is much simpler. You can see everything that's going on, it's just basic Docker commands being called.
|
46
|
+
|
47
47
|
## Configuration
|
48
48
|
|
49
49
|
### Using another registry than Docker Hub
|
50
50
|
|
51
|
-
The default registry
|
51
|
+
The default registry is Docker Hub, but you can change it using `registry/server`:
|
52
52
|
|
53
53
|
```yaml
|
54
54
|
registry:
|
55
55
|
server: registry.digitalocean.com
|
56
|
-
username:
|
57
|
-
password: <%=
|
56
|
+
username: registry-user-name
|
57
|
+
password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %>
|
58
58
|
```
|
59
59
|
|
60
60
|
### Using a different SSH user than root
|
@@ -65,9 +65,9 @@ The default SSH user is root, but you can change it using `ssh_user`:
|
|
65
65
|
ssh_user: app
|
66
66
|
```
|
67
67
|
|
68
|
-
###
|
68
|
+
### Using env variables
|
69
69
|
|
70
|
-
You can inject
|
70
|
+
You can inject env variables into the app containers using `env`:
|
71
71
|
|
72
72
|
```yaml
|
73
73
|
env:
|
@@ -75,9 +75,38 @@ env:
|
|
75
75
|
REDIS_URL: redis://redis1:6379/1
|
76
76
|
```
|
77
77
|
|
78
|
-
###
|
78
|
+
### Using secret env variables
|
79
|
+
|
80
|
+
If you have env variables that are secret, you can divide the `env` block into `clear` and `secret`:
|
81
|
+
|
82
|
+
```yaml
|
83
|
+
env:
|
84
|
+
clear:
|
85
|
+
DATABASE_URL: mysql2://db1/hey_production/
|
86
|
+
REDIS_URL: redis://redis1:6379/1
|
87
|
+
secret:
|
88
|
+
- DATABASE_PASSWORD
|
89
|
+
- REDIS_PASSWORD
|
90
|
+
```
|
91
|
+
|
92
|
+
The list of secret env variables will be expanded at run time from your local machine. So a reference to a secret `DATABASE_PASSWORD` will look for `ENV["DATABASE_PASSWORD"]` on the machine running MRSK. Just like with build secrets.
|
79
93
|
|
80
|
-
If
|
94
|
+
If the referenced secret ENVs are missing, the configuration will be halted with a `KeyError` exception.
|
95
|
+
|
96
|
+
Note: Marking an ENV as secret currently only redacts its value in the output for MRSK. The ENV is still injected in the clear into the container at runtime.
|
97
|
+
|
98
|
+
### Using volumes
|
99
|
+
|
100
|
+
You can add custom volumes into the app containers using `volumes`:
|
101
|
+
|
102
|
+
```yaml
|
103
|
+
volumes:
|
104
|
+
- "/local/path:/container/path"
|
105
|
+
```
|
106
|
+
|
107
|
+
### Using different roles for servers
|
108
|
+
|
109
|
+
If your application uses separate hosts for running jobs or other roles beyond the default web running, you can specify these hosts in a dedicated role with a new entrypoint command like so:
|
81
110
|
|
82
111
|
```yaml
|
83
112
|
servers:
|
@@ -91,23 +120,35 @@ servers:
|
|
91
120
|
cmd: bin/jobs
|
92
121
|
```
|
93
122
|
|
94
|
-
Traefik will only be installed and run on the servers in the `web` role (and on all servers if no roles are defined).
|
123
|
+
Note: Traefik will only by default be installed and run on the servers in the `web` role (and on all servers if no roles are defined). If you need Traefik on hosts in other roles than `web`, add `traefik: true`:
|
95
124
|
|
96
|
-
|
125
|
+
```yaml
|
126
|
+
servers:
|
127
|
+
web:
|
128
|
+
- 192.168.0.1
|
129
|
+
- 192.168.0.2
|
130
|
+
web2:
|
131
|
+
traefik: true
|
132
|
+
hosts:
|
133
|
+
- 192.168.0.3
|
134
|
+
- 192.168.0.4
|
135
|
+
```
|
97
136
|
|
98
|
-
|
137
|
+
### Using container labels
|
138
|
+
|
139
|
+
You can specialize the default Traefik rules by setting labels on the containers that are being started:
|
99
140
|
|
100
141
|
```
|
101
142
|
labels:
|
102
143
|
traefik.http.routers.hey.rule: '''Host(`app.hey.com`)'''
|
103
144
|
```
|
104
145
|
|
105
|
-
|
146
|
+
Note: The extra quotes are needed to ensure the rule is passed in correctly!
|
106
147
|
|
107
148
|
This allows you to run multiple applications on the same server sharing the same Traefik instance and port.
|
108
149
|
See https://doc.traefik.io/traefik/routing/routers/#rule for a full list of available routing rules.
|
109
150
|
|
110
|
-
The labels can
|
151
|
+
The labels can also be applied on a per-role basis:
|
111
152
|
|
112
153
|
```yaml
|
113
154
|
servers:
|
@@ -120,60 +161,139 @@ servers:
|
|
120
161
|
- 192.168.0.4
|
121
162
|
cmd: bin/jobs
|
122
163
|
labels:
|
123
|
-
my-
|
164
|
+
my-label: "50"
|
124
165
|
```
|
125
166
|
|
126
|
-
###
|
167
|
+
### Using remote builder for native multi-arch
|
127
168
|
|
128
|
-
If you're developing on ARM64 (like Apple Silicon), but you want to deploy on AMD64 (x86 64-bit), you
|
169
|
+
If you're developing on ARM64 (like Apple Silicon), but you want to deploy on AMD64 (x86 64-bit), you can use multi-archecture images. By default, MRSK will setup a local buildx configuration that does this through QEMU emulation. But this can be quite slow, especially on the first build.
|
129
170
|
|
130
|
-
If you want to speed up this process by using a remote AMD64 host to natively build the AMD64 part of the image, while natively building the ARM64 part locally, you can do so using builder options
|
171
|
+
If you want to speed up this process by using a remote AMD64 host to natively build the AMD64 part of the image, while natively building the ARM64 part locally, you can do so using builder options:
|
131
172
|
|
132
173
|
```yaml
|
133
174
|
builder:
|
134
175
|
local:
|
135
176
|
arch: arm64
|
136
|
-
host: unix:///Users
|
177
|
+
host: unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock
|
137
178
|
remote:
|
138
179
|
arch: amd64
|
139
180
|
host: ssh://root@192.168.0.1
|
140
181
|
```
|
141
182
|
|
142
|
-
Note: You must have Docker running on the remote host being used as a builder.
|
183
|
+
Note: You must have Docker running on the remote host being used as a builder. This instance should only be shared for builds using the same registry and credentials.
|
143
184
|
|
144
|
-
|
185
|
+
### Using remote builder for single-arch
|
145
186
|
|
146
|
-
|
187
|
+
If you're developing on ARM64 (like Apple Silicon), want to deploy on AMD64 (x86 64-bit), but don't need to run the image locally (or on other ARM64 hosts), you can configure a remote builder that just targets AMD64. This is a bit faster than building with multi-arch, as there's nothing to build locally.
|
147
188
|
|
148
|
-
|
189
|
+
```yaml
|
190
|
+
builder:
|
191
|
+
remote:
|
192
|
+
arch: amd64
|
193
|
+
host: ssh://root@192.168.0.1
|
194
|
+
```
|
195
|
+
|
196
|
+
### Using native builder when multi-arch isn't needed
|
197
|
+
|
198
|
+
If you're developing on the same architecture as the one you're deploying on, you can speed up the build by forgoing both multi-arch and remote building:
|
149
199
|
|
150
200
|
```yaml
|
151
201
|
builder:
|
152
202
|
multiarch: false
|
153
203
|
```
|
154
204
|
|
205
|
+
This is also a good option if you're running MRSK from a CI server that shares architecture with the deployment servers.
|
206
|
+
|
207
|
+
### Using build secrets for new images
|
208
|
+
|
209
|
+
Some images need a secret passed in during build time, like a GITHUB_TOKEN to give access to private gem repositories. This can be done by having the secret in ENV, then referencing it in the builder configuration:
|
210
|
+
|
211
|
+
```yaml
|
212
|
+
builder:
|
213
|
+
secrets:
|
214
|
+
- GITHUB_TOKEN
|
215
|
+
```
|
216
|
+
|
217
|
+
This build secret can then be referenced in the Dockerfile:
|
218
|
+
|
219
|
+
```
|
220
|
+
# Copy Gemfiles
|
221
|
+
COPY Gemfile Gemfile.lock ./
|
222
|
+
|
223
|
+
# Install dependencies, including private repositories via access token
|
224
|
+
RUN --mount=type=secret,id=GITHUB_TOKEN \
|
225
|
+
BUNDLE_GITHUB__COM=x-access-token:$(cat /run/secrets/GITHUB_TOKEN) \
|
226
|
+
bundle install
|
227
|
+
```
|
228
|
+
|
229
|
+
### Configuring build args for new images
|
230
|
+
|
231
|
+
Build arguments that aren't secret can also be configured:
|
232
|
+
|
233
|
+
```yaml
|
234
|
+
builder:
|
235
|
+
args:
|
236
|
+
RUBY_VERSION: 3.2.0
|
237
|
+
```
|
238
|
+
|
239
|
+
This build argument can then be used in the Dockerfile:
|
240
|
+
|
241
|
+
```
|
242
|
+
# Private repositories need an access token during the build
|
243
|
+
ARG RUBY_VERSION
|
244
|
+
FROM ruby:$RUBY_VERSION-slim as base
|
245
|
+
```
|
246
|
+
|
247
|
+
### Using accessories for database, cache, search services
|
248
|
+
|
249
|
+
You can manage your accessory services via MRSK as well. The services will build off public images, and will not be automatically updated when you deploy:
|
250
|
+
|
251
|
+
```yaml
|
252
|
+
accessories:
|
253
|
+
mysql:
|
254
|
+
image: mysql:5.7
|
255
|
+
host: 1.1.1.3
|
256
|
+
port: 3306
|
257
|
+
env:
|
258
|
+
clear:
|
259
|
+
MYSQL_ROOT_HOST: '%'
|
260
|
+
secret:
|
261
|
+
- MYSQL_ROOT_PASSWORD
|
262
|
+
volumes:
|
263
|
+
- /var/lib/mysql:/var/lib/mysql
|
264
|
+
redis:
|
265
|
+
image: redis:latest
|
266
|
+
host: 1.1.1.4
|
267
|
+
port: "36379:6379"
|
268
|
+
volumes:
|
269
|
+
- /var/lib/redis:/data
|
270
|
+
```
|
271
|
+
|
272
|
+
Now run `mrsk accessory start mysql` to start the MySQL server on 1.1.1.3. See `mrsk accessory` for all the commands possible.
|
273
|
+
|
155
274
|
## Commands
|
156
275
|
|
157
|
-
###
|
276
|
+
### Running remote execution and runners
|
158
277
|
|
159
|
-
If you need to execute commands inside the Rails containers, you can use
|
278
|
+
If you need to execute commands inside the Rails containers, you can use `mrsk app exec` and `mrsk app runner`. Examples:
|
160
279
|
|
161
280
|
```bash
|
162
281
|
# Runs command on all servers
|
163
|
-
|
164
|
-
App Host:
|
282
|
+
mrsk app exec 'ruby -v'
|
283
|
+
App Host: 192.168.0.1
|
165
284
|
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
|
166
285
|
|
167
|
-
App Host:
|
286
|
+
App Host: 192.168.0.2
|
168
287
|
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
|
169
288
|
|
170
|
-
# Runs command on
|
171
|
-
|
289
|
+
# Runs command on primary server
|
290
|
+
mrsk app exec --primary 'cat .ruby-version'
|
291
|
+
App Host: 192.168.0.1
|
172
292
|
3.1.3
|
173
293
|
|
174
294
|
# Runs Rails command on all servers
|
175
|
-
|
176
|
-
App Host:
|
295
|
+
mrsk app exec 'bin/rails about'
|
296
|
+
App Host: 192.168.0.1
|
177
297
|
About your application's environment
|
178
298
|
Rails version 7.1.0.alpha
|
179
299
|
Ruby version ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
|
@@ -185,7 +305,7 @@ Environment production
|
|
185
305
|
Database adapter sqlite3
|
186
306
|
Database schema version 20221231233303
|
187
307
|
|
188
|
-
App Host:
|
308
|
+
App Host: 192.168.0.2
|
189
309
|
About your application's environment
|
190
310
|
Rails version 7.1.0.alpha
|
191
311
|
Ruby version ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
|
@@ -197,70 +317,66 @@ Environment production
|
|
197
317
|
Database adapter sqlite3
|
198
318
|
Database schema version 20221231233303
|
199
319
|
|
200
|
-
#
|
201
|
-
|
202
|
-
|
203
|
-
Current version: 20221231233303
|
320
|
+
# Run Rails runner on primary server
|
321
|
+
mrsk app runner -p 'puts Rails.application.config.time_zone'
|
322
|
+
UTC
|
204
323
|
```
|
205
324
|
|
206
|
-
### Running a Rails console
|
325
|
+
### Running a Rails console
|
207
326
|
|
208
|
-
If you need to interact with the production console for the app, you can use
|
327
|
+
If you need to interact with the production console for the app, you can use `mrsk app console`, which will start a Rails console session on the primary host. You can start the console on a different host using `mrsk app console --host 192.168.0.2`. Be mindful that this is a live wire! Any changes made to the production database will take effect immeditately.
|
209
328
|
|
210
|
-
###
|
329
|
+
### Running details to see state of containers
|
211
330
|
|
212
|
-
You can see the state of your servers by running
|
331
|
+
You can see the state of your servers by running `mrsk details`:
|
213
332
|
|
214
333
|
```
|
215
|
-
Traefik Host:
|
334
|
+
Traefik Host: 192.168.0.1
|
216
335
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
217
336
|
6195b2a28c81 traefik "/entrypoint.sh --pr…" 30 minutes ago Up 19 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp traefik
|
218
337
|
|
219
|
-
Traefik Host:
|
338
|
+
Traefik Host: 192.168.0.2
|
220
339
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
221
340
|
de14a335d152 traefik "/entrypoint.sh --pr…" 30 minutes ago Up 19 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp traefik
|
222
341
|
|
223
|
-
App Host:
|
342
|
+
App Host: 192.168.0.1
|
224
343
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
225
344
|
badb1aa51db3 registry.digitalocean.com/user/app:6ef8a6a84c525b123c5245345a8483f86d05a123 "/rails/bin/docker-e…" 13 minutes ago Up 13 minutes 3000/tcp chat-6ef8a6a84c525b123c5245345a8483f86d05a123
|
226
345
|
|
227
|
-
App Host:
|
346
|
+
App Host: 192.168.0.2
|
228
347
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
229
348
|
1d3c91ed1f55 registry.digitalocean.com/user/app:6ef8a6a84c525b123c5245345a8483f86d05a123 "/rails/bin/docker-e…" 13 minutes ago Up 13 minutes 3000/tcp chat-6ef8a6a84c525b123c5245345a8483f86d05a123
|
230
349
|
```
|
231
350
|
|
232
|
-
You can also see just info for app containers with
|
351
|
+
You can also see just info for app containers with `mrsk app details` or just for Traefik with `mrsk traefik details`.
|
233
352
|
|
234
|
-
###
|
353
|
+
### Running rollback to fix a bad deploy
|
235
354
|
|
236
|
-
If you've discovered a bad deploy, you can quickly rollback by reactivating the old, paused container image. You can see what old containers are available for rollback by running
|
355
|
+
If you've discovered a bad deploy, you can quickly rollback by reactivating the old, paused container image. You can see what old containers are available for rollback by running `mrsk app containers`. It'll give you a presentation similar to `mrsk app details`, but include all the old containers as well. Showing something like this:
|
237
356
|
|
238
357
|
```
|
239
|
-
App Host:
|
358
|
+
App Host: 192.168.0.1
|
240
359
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
241
360
|
1d3c91ed1f51 registry.digitalocean.com/user/app:6ef8a6a84c525b123c5245345a8483f86d05a123 "/rails/bin/docker-e…" 19 minutes ago Up 19 minutes 3000/tcp chat-6ef8a6a84c525b123c5245345a8483f86d05a123
|
242
361
|
539f26b28369 registry.digitalocean.com/user/app:e5d9d7c2b898289dfbc5f7f1334140d984eedae4 "/rails/bin/docker-e…" 31 minutes ago Exited (1) 27 minutes ago chat-e5d9d7c2b898289dfbc5f7f1334140d984eedae4
|
243
362
|
|
244
|
-
App Host:
|
363
|
+
App Host: 192.168.0.2
|
245
364
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
246
365
|
badb1aa51db4 registry.digitalocean.com/user/app:6ef8a6a84c525b123c5245345a8483f86d05a123 "/rails/bin/docker-e…" 19 minutes ago Up 19 minutes 3000/tcp chat-6ef8a6a84c525b123c5245345a8483f86d05a123
|
247
366
|
6f170d1172ae registry.digitalocean.com/user/app:e5d9d7c2b898289dfbc5f7f1334140d984eedae4 "/rails/bin/docker-e…" 31 minutes ago Exited (1) 27 minutes ago chat-e5d9d7c2b898289dfbc5f7f1334140d984eedae4
|
248
367
|
```
|
249
368
|
|
250
|
-
From the example above, we can see that `e5d9d7c2b898289dfbc5f7f1334140d984eedae4` was the last version, so it's available as a rollback target. We can perform this rollback by running
|
369
|
+
From the example above, we can see that `e5d9d7c2b898289dfbc5f7f1334140d984eedae4` was the last version, so it's available as a rollback target. We can perform this rollback by running `mrsk rollback e5d9d7c2b898289dfbc5f7f1334140d984eedae4`. That'll stop `6ef8a6a84c525b123c5245345a8483f86d05a123` and then start `e5d9d7c2b898289dfbc5f7f1334140d984eedae4`. Because the old container is still available, this is very quick. Nothing to download from the registry.
|
251
370
|
|
252
|
-
Note that by default old containers are pruned after 3 days when you run
|
371
|
+
Note that by default old containers are pruned after 3 days when you run `mrsk deploy`.
|
253
372
|
|
254
|
-
###
|
373
|
+
### Running removal to clean up servers
|
255
374
|
|
256
|
-
If you wish to remove the entire application, including Traefik, containers, images, and registry session, you can run
|
375
|
+
If you wish to remove the entire application, including Traefik, containers, images, and registry session, you can run `mrsk remove`. This will leave the servers clean.
|
257
376
|
|
258
377
|
## Stage of development
|
259
378
|
|
260
|
-
This is alpha software. Lots of stuff is missing.
|
261
|
-
|
262
|
-
- Adapterize commands to work with Podman and other container runners
|
263
|
-
- Integrate with cloud CI pipelines
|
379
|
+
This is alpha software. Lots of stuff is missing. Lots of stuff will keep moving around for a while.
|
264
380
|
|
265
381
|
## License
|
266
382
|
|
data/bin/mrsk
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require "mrsk/cli/base"
|
2
|
+
|
3
|
+
class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
4
|
+
desc "boot [NAME]", "Boot accessory service on host"
|
5
|
+
def boot(name)
|
6
|
+
accessory = MRSK.accessory(name)
|
7
|
+
on(accessory.host) { execute *accessory.run }
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "reboot [NAME]", "Reboot accessory on host (stop container, remove container, start new container)"
|
11
|
+
def reboot(name)
|
12
|
+
invoke :stop, [ name ]
|
13
|
+
invoke :remove_container, [ name ]
|
14
|
+
invoke :boot, [ name ]
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "start [NAME]", "Start existing accessory on host"
|
18
|
+
def start(name)
|
19
|
+
accessory = MRSK.accessory(name)
|
20
|
+
on(accessory.host) { execute *accessory.start }
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "stop [NAME]", "Stop accessory on host"
|
24
|
+
def stop(name)
|
25
|
+
accessory = MRSK.accessory(name)
|
26
|
+
on(accessory.host) { execute *accessory.stop }
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "restart [NAME]", "Restart accessory on host"
|
30
|
+
def restart(name)
|
31
|
+
invoke :stop, [ name ]
|
32
|
+
invoke :start, [ name ]
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "details [NAME]", "Display details about accessory on host"
|
36
|
+
def details(name)
|
37
|
+
accessory = MRSK.accessory(name)
|
38
|
+
on(accessory.host) { puts capture_with_info(*accessory.info) }
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "logs [NAME]", "Show log lines from accessory on host"
|
42
|
+
option :since, aliases: "-s", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
43
|
+
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
44
|
+
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
45
|
+
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
46
|
+
def logs(name)
|
47
|
+
accessory = MRSK.accessory(name)
|
48
|
+
|
49
|
+
grep = options[:grep]
|
50
|
+
|
51
|
+
if options[:follow]
|
52
|
+
run_locally do
|
53
|
+
info "Following logs on #{accessory.host}..."
|
54
|
+
info accessory.follow_logs(grep: grep)
|
55
|
+
exec accessory.follow_logs(grep: grep)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
since = options[:since]
|
59
|
+
lines = options[:lines]
|
60
|
+
|
61
|
+
on(accessory.host) do
|
62
|
+
puts capture_with_info(*accessory.logs(since: since, lines: lines, grep: grep))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "remove [NAME]", "Remove accessory container and image from host"
|
68
|
+
def remove(name)
|
69
|
+
invoke :stop, [ name ]
|
70
|
+
invoke :remove_container, [ name ]
|
71
|
+
invoke :remove_image, [ name ]
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "remove_container [NAME]", "Remove accessory container from host"
|
75
|
+
def remove_container(name)
|
76
|
+
accessory = MRSK.accessory(name)
|
77
|
+
on(accessory.host) { execute *accessory.remove_container }
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "remove_container [NAME]", "Remove accessory image from servers"
|
81
|
+
def remove_image(name)
|
82
|
+
accessory = MRSK.accessory(name)
|
83
|
+
on(accessory.host) { execute *accessory.remove_image }
|
84
|
+
end
|
85
|
+
end
|
data/lib/mrsk/cli/app.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "mrsk/cli/base"
|
2
|
+
|
3
|
+
class Mrsk::Cli::App < Mrsk::Cli::Base
|
4
|
+
desc "boot", "Boot app on servers (or start them if they've already been booted)"
|
5
|
+
def boot
|
6
|
+
MRSK.config.roles.each do |role|
|
7
|
+
on(role.hosts) do |host|
|
8
|
+
begin
|
9
|
+
execute *MRSK.app.run(role: role.name)
|
10
|
+
rescue SSHKit::Command::Failed => e
|
11
|
+
if e.message =~ /already in use/
|
12
|
+
error "Container with same version already deployed on #{host}, starting that instead"
|
13
|
+
execute *MRSK.app.start, host: host
|
14
|
+
else
|
15
|
+
raise
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "start", "Start existing app on servers (use --version=<git-hash> to designate specific version)"
|
23
|
+
option :version, desc: "Defaults to the most recent git-hash in local repository"
|
24
|
+
def start
|
25
|
+
if (version = options[:version]).present?
|
26
|
+
on(MRSK.hosts) { execute *MRSK.app.start(version: version) }
|
27
|
+
else
|
28
|
+
on(MRSK.hosts) { execute *MRSK.app.start, raise_on_non_zero_exit: false }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "stop", "Stop app on servers"
|
33
|
+
def stop
|
34
|
+
on(MRSK.hosts) { execute *MRSK.app.stop, raise_on_non_zero_exit: false }
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "details", "Display details about app containers"
|
38
|
+
def details
|
39
|
+
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.info) }
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "exec [CMD]", "Execute a custom command on servers"
|
43
|
+
option :run, type: :boolean, default: false, desc: "Start a new container to run the command rather than reusing existing"
|
44
|
+
def exec(cmd)
|
45
|
+
runner = options[:run] ? :run_exec : :exec
|
46
|
+
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.send(runner, cmd)) }
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "console", "Start Rails Console on primary host (or specific host set by --hosts)"
|
50
|
+
def console
|
51
|
+
run_locally do
|
52
|
+
info "Launching Rails console on #{MRSK.primary_host}"
|
53
|
+
exec MRSK.app.console(host: MRSK.primary_host)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "bash", "Start a bash session on primary host (or specific host set by --hosts)"
|
58
|
+
def bash
|
59
|
+
run_locally do
|
60
|
+
info "Launching bash session on #{MRSK.primary_host}"
|
61
|
+
exec MRSK.app.bash(host: MRSK.primary_host)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "runner [EXPRESSION]", "Execute Rails runner with given expression"
|
66
|
+
def runner(expression)
|
67
|
+
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.exec("bin/rails", "runner", "'#{expression}'")) }
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "containers", "List all the app containers currently on servers"
|
71
|
+
def containers
|
72
|
+
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.list_containers) }
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "current", "Return the current running container ID"
|
76
|
+
def current
|
77
|
+
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_container_id) }
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "logs", "Show lines from app on servers"
|
81
|
+
option :since, aliases: "-s", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
82
|
+
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
83
|
+
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
84
|
+
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
85
|
+
def logs
|
86
|
+
# FIXME: Catch when app containers aren't running
|
87
|
+
|
88
|
+
grep = options[:grep]
|
89
|
+
|
90
|
+
if options[:follow]
|
91
|
+
run_locally do
|
92
|
+
info "Following logs on #{MRSK.primary_host}..."
|
93
|
+
info MRSK.app.follow_logs(host: MRSK.primary_host, grep: grep)
|
94
|
+
exec MRSK.app.follow_logs(host: MRSK.primary_host, grep: grep)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
since = options[:since]
|
98
|
+
lines = options[:lines]
|
99
|
+
|
100
|
+
on(MRSK.hosts) do |host|
|
101
|
+
begin
|
102
|
+
puts_by_host host, capture_with_info(*MRSK.app.logs(since: since, lines: lines, grep: grep))
|
103
|
+
rescue SSHKit::Command::Failed
|
104
|
+
puts_by_host host, "Nothing found"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "remove", "Remove app containers and images from servers"
|
111
|
+
option :only, default: "", desc: "Use 'containers' or 'images'"
|
112
|
+
def remove
|
113
|
+
case options[:only]
|
114
|
+
when "containers"
|
115
|
+
on(MRSK.hosts) { execute *MRSK.app.remove_containers }
|
116
|
+
when "images"
|
117
|
+
on(MRSK.hosts) { execute *MRSK.app.remove_images }
|
118
|
+
else
|
119
|
+
on(MRSK.hosts) { execute *MRSK.app.remove_containers }
|
120
|
+
on(MRSK.hosts) { execute *MRSK.app.remove_images }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|