wslc-wip 1.0.0 → 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 +105 -24
- data/lib/wip/build_context.rb +151 -9
- data/lib/wip/cli.rb +2 -1
- data/lib/wip/config.rb +27 -1
- data/lib/wip/initializer.rb +6 -5
- data/lib/wip/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e2bffbab317006bdd799443ef1dc7e16d9527219261f91c9758504ae85aef638
|
|
4
|
+
data.tar.gz: b1e0f8f72d44878564573fcc8076af18defe14375d1bee4cd4946c72139bcc1e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d16eda21cb080e2dd7decc2522c4dac7c99536f3c720c1de7d64f0065edd7487c633450db9eeb687b12138b2763d3093628e0d169b82d7896c781e7c8298bb3c
|
|
7
|
+
data.tar.gz: 5f668930355e17877237892da08dc440630f2015253b072c715e324c38045598765c58cb84d9657d7769527d3f27774f8d4f03f6bec2cc1bb785bca9a308cce2
|
data/README.md
CHANGED
|
@@ -7,6 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
Homepage: https://wslc-wip.slidict.com/
|
|
9
9
|
|
|
10
|
+
`wip` is a Ruby-built OSS CLI wrapper that brings a [`dip`](https://github.com/bibendi/dip)-like
|
|
11
|
+
workflow to Microsoft WSLC. It collects a project's container, image, environment variables, and
|
|
12
|
+
commands into a single `wip.yml`, and forwards them to `wslc.exe` / `wslc` as safe argument arrays
|
|
13
|
+
(no shell interpolation).
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
> **Status:** early release. Expect to track WSLC's own interface as it evolves.
|
|
18
|
+
|
|
10
19
|
## Contents
|
|
11
20
|
|
|
12
21
|
- [Which mode should you use?](#which-mode-should-you-use)
|
|
@@ -22,20 +31,12 @@ Homepage: https://wslc-wip.slidict.com/
|
|
|
22
31
|
- [Commands](#commands)
|
|
23
32
|
- [doctor](#doctor)
|
|
24
33
|
- [Common errors](#common-errors)
|
|
34
|
+
- [FAQ](#faq)
|
|
25
35
|
- [Development](#development)
|
|
26
36
|
- [Contributing](#contributing)
|
|
27
37
|
- [Roadmap](#roadmap)
|
|
28
38
|
- [License](#license)
|
|
29
39
|
|
|
30
|
-
`wip` is a Ruby-built OSS CLI wrapper that brings a [`dip`](https://github.com/bibendi/dip)-like
|
|
31
|
-
workflow to Microsoft WSLC. It collects a project's container, image, environment variables, and
|
|
32
|
-
commands into a single `wip.yml`, and forwards them to `wslc.exe` / `wslc` as safe argument arrays
|
|
33
|
-
(no shell interpolation).
|
|
34
|
-
|
|
35
|
-

|
|
36
|
-
|
|
37
|
-
> **Status:** early release. Expect to track WSLC's own interface as it evolves.
|
|
38
|
-
|
|
39
40
|
## Which mode should you use?
|
|
40
41
|
|
|
41
42
|
`wip.yml` runs in one of three modes, set with `mode:`. Pick the one that matches your project:
|
|
@@ -86,7 +87,7 @@ version: 1
|
|
|
86
87
|
mode: container # default
|
|
87
88
|
wslc:
|
|
88
89
|
command: auto # tries wslc.exe, wslc, then System32; an absolute path also works
|
|
89
|
-
container: app # required once dependencies: has entries; which one `up`/`exec`/`run`/`build`/`
|
|
90
|
+
container: app # required once dependencies: has entries; which one `up`/`exec`/`run`/`build`/`interaction:`
|
|
90
91
|
# target. No default — a project must say which entry is the primary one explicitly.
|
|
91
92
|
network: app-tier # optional; shared by every dependencies: entry so containers can resolve each other by name
|
|
92
93
|
dependencies:
|
|
@@ -112,7 +113,7 @@ dependencies:
|
|
|
112
113
|
env:
|
|
113
114
|
MYSQL_ROOT_PASSWORD: password
|
|
114
115
|
MYSQL_DATABASE: development
|
|
115
|
-
|
|
116
|
+
interaction:
|
|
116
117
|
rails:
|
|
117
118
|
type: exec
|
|
118
119
|
command: bin/rails
|
|
@@ -137,6 +138,7 @@ commands:
|
|
|
137
138
|
type: build
|
|
138
139
|
context: .
|
|
139
140
|
tag: slidict/slidict:development
|
|
141
|
+
shadow_context: /mnt/c/Users/me/AppData/Local/wip/build-contexts
|
|
140
142
|
sync: # optional; mirror the source into a named volume instead of bind-mounting it live
|
|
141
143
|
exclude:
|
|
142
144
|
- .git
|
|
@@ -148,6 +150,11 @@ sync: # optional; mirror the source into a named volume instead of bind-mounting
|
|
|
148
150
|
credential, or auth. Keep real secrets out of the config file and in your runtime environment
|
|
149
151
|
instead.
|
|
150
152
|
|
|
153
|
+
`interaction:` can also be spelled `commands:` — the same block under a different name, e.g. for
|
|
154
|
+
projects that already use `commands:`. `wip config` prints the effective config using `commands:`.
|
|
155
|
+
The two are aliases for the same feature, not separate ones: pick whichever name you like, but declaring both
|
|
156
|
+
`commands:` and `interaction:` in the same `wip.yml` is a `ConfigError`.
|
|
157
|
+
|
|
151
158
|
#### Dependency containers
|
|
152
159
|
|
|
153
160
|
`dependencies:` holds every container uniformly — the primary one `container:` points at and any
|
|
@@ -161,7 +168,7 @@ entry by name first (creating `network:` beforehand if it doesn't exist and set)
|
|
|
161
168
|
starts the primary one — so `bin/rails c` (or anything else run inside it) can reach
|
|
162
169
|
`development.mysql`/`redis`/etc. by their dependency name, the same way Compose's service names
|
|
163
170
|
resolve. `wip down` tears the primary container and all sidecars down (the network itself is left
|
|
164
|
-
in place). Only the primary container is a target for `exec`/`run`/`build`/`
|
|
171
|
+
in place). Only the primary container is a target for `exec`/`run`/`build`/`interaction:` — sidecars
|
|
165
172
|
are only ever started and stopped, matching Compose's own service-vs-you-exec-into-one-of-them
|
|
166
173
|
split.
|
|
167
174
|
|
|
@@ -198,13 +205,13 @@ the Compose CLI vocabulary `wip` drives. `wip doctor` reports whether the config
|
|
|
198
205
|
found, its version, and which compose file `wip` resolved.
|
|
199
206
|
|
|
200
207
|
- `wip up`/`wip down` delegate straight to `<compose command> up -d`/`down`.
|
|
201
|
-
- `wip exec`/`wip NAME` (custom `
|
|
202
|
-
- `wip shell` also goes through the bridge: unless `
|
|
208
|
+
- `wip exec`/`wip NAME` (custom `interaction:`) run inside `compose.service`.
|
|
209
|
+
- `wip shell` also goes through the bridge: unless `interaction.shell` is defined in `wip.yml`, it
|
|
203
210
|
`exec`s `bash` against `compose.service`, falling back to `sh`.
|
|
204
211
|
- `wip logs [-f] [SERVICE...]` is only available in compose mode.
|
|
205
212
|
- `wip run` has no ephemeral-container equivalent in this exec-only vocabulary, so it falls back
|
|
206
213
|
to `exec` against the already-running `compose.service` (wip warns when this happens).
|
|
207
|
-
- `
|
|
214
|
+
- `interaction:` entries with `type: run`/`type: build` aren't supported in compose mode — use your
|
|
208
215
|
compose tool's own `build`/`up --build` directly; compose owns builds for its own services.
|
|
209
216
|
|
|
210
217
|
### Compose mode (native)
|
|
@@ -263,10 +270,15 @@ to load a different file instead.
|
|
|
263
270
|
|
|
264
271
|
### .dockerignore
|
|
265
272
|
|
|
266
|
-
`wip build` reads `.dockerignore` from the build context and
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
`wip build` reads `.dockerignore` from the build context and excludes anything it matches before
|
|
274
|
+
handing the context to `wslc build`, since `wslc` sends the context as-is otherwise. Set
|
|
275
|
+
`commands.build.shadow_context` in `wip.yml` to a directory on the Windows filesystem to enable a
|
|
276
|
+
persistent shadow context for projects outside `/mnt/<drive>`. The first build copies every
|
|
277
|
+
included file; later builds only copy added or changed files and remove deleted or newly ignored
|
|
278
|
+
files. Without this setting the optimization is disabled, and it only applies under WSL2 — on WSL1
|
|
279
|
+
(or anywhere else) the context is handed to `wslc build` directly. Projects already on `/mnt/c` (or
|
|
280
|
+
another mounted Windows drive) also continue to build directly even when the setting is present.
|
|
281
|
+
The path must live outside the build context itself, or `wip build` refuses it.
|
|
270
282
|
|
|
271
283
|
### Source sync
|
|
272
284
|
|
|
@@ -344,7 +356,7 @@ Everything below `sync:` is optional — `sync: {}` alone already works. With it
|
|
|
344
356
|
- With `sync.build` configured, `wip build`s that image once per `wip up`/`wip sync` invocation
|
|
345
357
|
(including once before a `--watch` loop starts, not on every tick) before mirroring with it.
|
|
346
358
|
|
|
347
|
-
Like every built-in command, `wip sync` takes precedence over
|
|
359
|
+
Like every built-in command, `wip sync` takes precedence over an `interaction:` entry of the same
|
|
348
360
|
name; wip says so and points at `wip dispatch sync`, which still runs yours.
|
|
349
361
|
|
|
350
362
|
Two things to keep in mind. The mirror runs `rsync` *inside* the container, so the image needs it
|
|
@@ -415,7 +427,7 @@ to that tag directly — `sync.build`'s tag wins if both are set, so don't confi
|
|
|
415
427
|
| `wip shell` | Open the configured shell, falling back to `bash` then `sh` |
|
|
416
428
|
| `wip logs [-f] [SERVICE...]` | Follow compose service logs (compose modes only; mode: compose-native takes at most one `SERVICE`) |
|
|
417
429
|
| `wip sync [-w] [--interval N]` | Mirror the source into the sync volume once, or keep re-syncing with `--watch` (needs `sync:`) |
|
|
418
|
-
| `wip NAME ARGS...` | Run `
|
|
430
|
+
| `wip NAME ARGS...` | Run `interaction.NAME`, appending any extra arguments |
|
|
419
431
|
|
|
420
432
|
TTY allocation is decided by combining the command's config, the CLI option, and whether both
|
|
421
433
|
stdin and stdout are real TTYs.
|
|
@@ -510,6 +522,74 @@ docker buildx build \
|
|
|
510
522
|
--push .
|
|
511
523
|
```
|
|
512
524
|
|
|
525
|
+
## FAQ
|
|
526
|
+
|
|
527
|
+
**Which mode should I start with?**
|
|
528
|
+
Pick whichever `mode:` fits your project — see [Which mode should you use?](#which-mode-should-you-use)
|
|
529
|
+
for the breakdown.
|
|
530
|
+
|
|
531
|
+
**Can I use `dependencies:` and `compose:` together?**
|
|
532
|
+
No — `compose:` is mutually exclusive with `dependencies:`/`network`. Pick one orchestration path
|
|
533
|
+
per project; see [Configuration](#configuration).
|
|
534
|
+
|
|
535
|
+
**What's the difference between `mode: compose` and `mode: compose-native`?**
|
|
536
|
+
`compose` delegates to a third-party compose-for-`wslc` binary you install yourself
|
|
537
|
+
(`compose.command`); `compose-native` parses `compose.yml` itself and drives `wslc` directly, no
|
|
538
|
+
external tool required. `compose-native`'s Compose coverage isn't frozen at whatever it handles
|
|
539
|
+
today — it keeps growing until `wslc` ships native Compose support of its own. See
|
|
540
|
+
[Compose mode](#compose-mode) and [Compose mode (native)](#compose-mode-native).
|
|
541
|
+
|
|
542
|
+
**`dependencies:` already gives me sidecar containers — why would I need `compose-native` too?**
|
|
543
|
+
`dependencies:` and `compose-native` aren't really alternatives to each other — they're for two
|
|
544
|
+
different starting points. No `compose.yml`? Declare containers directly in `wip.yml`'s own shape
|
|
545
|
+
with `dependencies:`. Already have a `compose.yml`? Reusing it is where `compose-native` and
|
|
546
|
+
`mode: compose` both come in, so the real comparison is between those two, not against
|
|
547
|
+
`dependencies:`: `mode: compose` reuses it too, but only by delegating to a third-party
|
|
548
|
+
compose-for-`wslc` binary you install yourself; `compose-native` reuses the same `compose.yml`
|
|
549
|
+
without installing anything external, parsing it and driving `wslc` directly — and gets a real
|
|
550
|
+
`wslc run --rm` for `wip run` instead of the `exec` fallback `mode: compose` falls back to.
|
|
551
|
+
`mode: compose`'s coverage is whatever the external tool you point it at supports; `compose-native`'s
|
|
552
|
+
is maintained in this repo and actively extended, not treated as a permanent ceiling. See
|
|
553
|
+
[Which mode should you use?](#which-mode-should-you-use) for the full picture.
|
|
554
|
+
|
|
555
|
+
**What happens to `compose-native` once `wslc` gets official Compose support?**
|
|
556
|
+
`compose-native` exists to close the gap for as long as `wslc` has no native Compose support of its
|
|
557
|
+
own (tracked upstream in [microsoft/WSL#40948](https://github.com/microsoft/WSL/issues/40948)), and
|
|
558
|
+
we intend to keep extending its Compose coverage until that lands — see
|
|
559
|
+
[Compose mode (native)](#compose-mode-native) and [Roadmap](#roadmap). `wip.yml`'s shape (`mode:`,
|
|
560
|
+
`compose:`) isn't planned to change for existing `container`/`compose`/`compose-native` setups, so
|
|
561
|
+
whatever we do once `wslc` catches up won't require rewriting your config.
|
|
562
|
+
|
|
563
|
+
**Is `sync:` required?**
|
|
564
|
+
No, it's entirely optional. Add it if boot times feel slow with a bind-mounted app directory — see
|
|
565
|
+
[Slow boot when the app directory is bind-mounted](#slow-boot-when-the-app-directory-is-bind-mounted).
|
|
566
|
+
|
|
567
|
+
**How does `wip` actually fix the slow bind-mount boot problem?**
|
|
568
|
+
The slowness comes from `.:/app`-style bind mounts going through virtiofs, where frameworks that
|
|
569
|
+
stat/open many small files at startup (e.g. Ruby's Zeitwerk) pay a round trip per file. A `sync:`
|
|
570
|
+
block moves the app off that path entirely: the host source is mounted read-only, the app itself
|
|
571
|
+
runs off a named volume (fast native storage inside the VM), and `wip` mirrors the read-only
|
|
572
|
+
source into that volume with `rsync` — once before boot, and on demand afterward via `wip sync`
|
|
573
|
+
(or continuously with `wip sync --watch`). Since the app never touches the bind mount directly, its
|
|
574
|
+
own file access is no longer paying the virtiofs cost; the trade-off is a one-way, slightly-delayed
|
|
575
|
+
mirror instead of an always-live view of host edits. See [Source sync](#source-sync) for the full
|
|
576
|
+
config and [Slow boot when the app directory is bind-mounted](#slow-boot-when-the-app-directory-is-bind-mounted)
|
|
577
|
+
for the root cause.
|
|
578
|
+
|
|
579
|
+
**Is it safe to put passwords/secrets in `wip.yml`?**
|
|
580
|
+
`wip config` masks any key matching token/password/secret/credential/auth when printing, but the
|
|
581
|
+
raw file itself is not encrypted. Keep real secrets in your runtime environment or `.env` instead
|
|
582
|
+
of committing them in `wip.yml` — but `.env` is only safe if it's actually untracked: add `.env` to
|
|
583
|
+
`.gitignore` (and confirm with `git check-ignore .env`) before putting anything sensitive in it.
|
|
584
|
+
|
|
585
|
+
**`wslc.exe`/`wslc` isn't found — what do I do?**
|
|
586
|
+
See [WSLC not found](#wslc-not-found) under Common errors.
|
|
587
|
+
|
|
588
|
+
**I'm migrating from `dip` — do I have to rename `interaction:`?**
|
|
589
|
+
No, `wip.yml` accepts `interaction:` as-is — it's the primary spelling, same as in `dip`. `commands:`
|
|
590
|
+
also works as an alias if you prefer it, but not both in the same file (that's a `ConfigError`). See
|
|
591
|
+
[Container mode](#container-mode).
|
|
592
|
+
|
|
513
593
|
## Development
|
|
514
594
|
|
|
515
595
|
```bash
|
|
@@ -522,7 +602,8 @@ bundle exec rake
|
|
|
522
602
|
```
|
|
523
603
|
|
|
524
604
|
The test suite doesn't need WSLC — the resolution, build, and execution layers are all
|
|
525
|
-
swappable.
|
|
605
|
+
swappable. This project uses RuboCop for Ruby style and static analysis; `bundle exec rake` runs
|
|
606
|
+
both RSpec and RuboCop. GitHub Actions checks them on Ruby 3.2, 3.3, 3.4, and 4.0.
|
|
526
607
|
|
|
527
608
|
## Contributing
|
|
528
609
|
|
|
@@ -533,7 +614,7 @@ checklist.
|
|
|
533
614
|
## Roadmap
|
|
534
615
|
|
|
535
616
|
`wip` already covers most of what [`dip`](https://github.com/bibendi/dip) adds on top of Compose —
|
|
536
|
-
named commands (`
|
|
617
|
+
named commands (`interaction:`), `run`/`exec` hidden behind a single verb, `.env` passthrough, and
|
|
537
618
|
sidecar services via `dependencies:` + `network:`. Rather than waiting on `wslc`'s own Compose
|
|
538
619
|
support ([microsoft/WSL#40948](https://github.com/microsoft/WSL/issues/40948)) or an external
|
|
539
620
|
compose-for-`wslc` tool staying complete, `mode: compose-native` (see
|
|
@@ -547,7 +628,7 @@ compose-for-`wslc` tool in [compose mode](#compose-mode) — which of those actu
|
|
|
547
628
|
entirely up to the external tool you point `compose.command` at; `wip` only forwards
|
|
548
629
|
`-f FILE [-p PROJECT] up|down|exec|logs`, so treat that list as what Compose offers, not as
|
|
549
630
|
something `wip` guarantees. See that section for what compose mode covers
|
|
550
|
-
and its current limitations (`run`, and `
|
|
631
|
+
and its current limitations (`run`, and `interaction:` of type `run`/`build`).
|
|
551
632
|
|
|
552
633
|
Beyond Compose parity, a resident/daemon process, a GUI, PowerShell-specific tuning, direct
|
|
553
634
|
registry API/manifest parsing, self-update, and plugins are all unimplemented and not currently
|
data/lib/wip/build_context.rb
CHANGED
|
@@ -1,33 +1,175 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'digest'
|
|
4
4
|
require 'fileutils'
|
|
5
|
+
require 'find'
|
|
6
|
+
require 'json'
|
|
5
7
|
require 'pathname'
|
|
6
8
|
require 'tmpdir'
|
|
7
9
|
|
|
8
10
|
module Wip
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
# context as-is instead of filtering it itself.
|
|
11
|
+
# Filters build contexts for wslc and keeps WSL-hosted sources in a fast,
|
|
12
|
+
# persistent Windows-side shadow directory.
|
|
12
13
|
class BuildContext
|
|
13
|
-
def initialize(context, ignore: nil)
|
|
14
|
+
def initialize(context, ignore: nil, environment: Environment.new, shadow_root: nil)
|
|
14
15
|
@root = Pathname(context).expand_path
|
|
15
16
|
@ignore = ignore || DockerIgnore.load(@root.join('.dockerignore'))
|
|
17
|
+
@environment = environment
|
|
18
|
+
@shadow_root = validated_shadow_root(shadow_root) if shadow_root
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
# on_progress fires before copying and after each file, as `|count, total|`,
|
|
19
22
|
# so a caller can report elapsed progress even while copying one large file.
|
|
20
|
-
def stage(on_progress: nil)
|
|
21
|
-
return
|
|
23
|
+
def stage(on_progress: nil, &block)
|
|
24
|
+
return stage_shadow(on_progress, &block) if shadow_required?
|
|
25
|
+
return block.call(@root.to_s) if @ignore.empty?
|
|
22
26
|
|
|
23
27
|
Dir.mktmpdir('wip-build-context-') do |dir|
|
|
24
28
|
copy_included_files(Pathname(dir), on_progress)
|
|
25
|
-
|
|
29
|
+
block.call(dir)
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
private
|
|
30
34
|
|
|
35
|
+
# A shadow root under the context would itself be walked by included_files
|
|
36
|
+
# on the next build and copied into itself at ever-deeper paths, so the
|
|
37
|
+
# cache would grow without bound and the build would eventually fail.
|
|
38
|
+
def validated_shadow_root(shadow_root)
|
|
39
|
+
root = Pathname(shadow_root).expand_path
|
|
40
|
+
if root == @root || root.to_s.start_with?("#{@root}/")
|
|
41
|
+
raise ConfigError, "shadow_context (#{root}) must not be inside the build context (#{@root})"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
root
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def shadow_required?
|
|
48
|
+
return false unless @shadow_root
|
|
49
|
+
|
|
50
|
+
@environment.wsl2? && !@root.to_s.match?(%r{\A/mnt/[a-z](?:/|\z)}i)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Keep one stable Windows-side context per source path. Its manifest lives
|
|
54
|
+
# beside (rather than inside) the context so it is never sent to wslc.
|
|
55
|
+
def stage_shadow(on_progress)
|
|
56
|
+
key = Digest::SHA256.hexdigest(@root.to_s)
|
|
57
|
+
cache = @shadow_root.join(key)
|
|
58
|
+
context = cache.join('context')
|
|
59
|
+
FileUtils.mkdir_p(cache)
|
|
60
|
+
|
|
61
|
+
File.open(cache.join('lock'), File::RDWR | File::CREAT, 0o600) do |lock|
|
|
62
|
+
lock.flock(File::LOCK_EX)
|
|
63
|
+
synchronize_shadow(context, cache.join('manifest.json'), on_progress)
|
|
64
|
+
# Keep the shadow immutable until wslc has finished reading it.
|
|
65
|
+
yield context.to_s
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def synchronize_shadow(context, manifest_path, on_progress)
|
|
70
|
+
current = included_files.to_h { |entry| [entry, fingerprint(@root.join(entry))] }
|
|
71
|
+
previous = previous_manifest(context, manifest_path)
|
|
72
|
+
changed = current.keys.reject { |entry| current[entry] == previous[entry] }
|
|
73
|
+
removed = previous.keys - current.keys
|
|
74
|
+
|
|
75
|
+
apply_shadow_changes(context, changed, removed, on_progress)
|
|
76
|
+
FileUtils.mkdir_p(context)
|
|
77
|
+
write_manifest(manifest_path, current)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# A context we can't describe is a context we can't update incrementally:
|
|
81
|
+
# with no manifest there is no way to tell which of its entries are stale,
|
|
82
|
+
# so it gets discarded and rebuilt rather than left holding deleted or
|
|
83
|
+
# newly ignored files.
|
|
84
|
+
def previous_manifest(context, manifest_path)
|
|
85
|
+
return {} unless context.directory?
|
|
86
|
+
|
|
87
|
+
manifest = load_manifest(manifest_path)
|
|
88
|
+
return manifest if manifest
|
|
89
|
+
|
|
90
|
+
FileUtils.rm_rf(context)
|
|
91
|
+
{}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def apply_shadow_changes(context, changed, removed, on_progress)
|
|
95
|
+
total = changed.size + removed.size
|
|
96
|
+
on_progress&.call(0, total)
|
|
97
|
+
|
|
98
|
+
removed.each_with_index do |entry, index|
|
|
99
|
+
FileUtils.rm_rf(context.join(entry))
|
|
100
|
+
prune_empty_parents(context.join(entry).dirname, context)
|
|
101
|
+
on_progress&.call(index + 1, total)
|
|
102
|
+
end
|
|
103
|
+
changed.each_with_index do |entry, index|
|
|
104
|
+
copy_entry_atomically(@root.join(entry), context.join(entry))
|
|
105
|
+
on_progress&.call(removed.size + index + 1, total)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Returns nil — not an empty manifest — when the manifest is missing,
|
|
110
|
+
# unreadable, or not a manifest at all, so callers can tell "nothing was
|
|
111
|
+
# synced yet" apart from "we no longer know what was synced".
|
|
112
|
+
def load_manifest(path)
|
|
113
|
+
manifest = JSON.parse(path.read)
|
|
114
|
+
manifest if manifest.is_a?(Hash)
|
|
115
|
+
rescue JSON::ParserError, SystemCallError
|
|
116
|
+
nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def write_manifest(path, contents)
|
|
120
|
+
temporary = Pathname("#{path}.tmp-#{Process.pid}")
|
|
121
|
+
temporary.write(JSON.generate(contents))
|
|
122
|
+
File.rename(temporary, path)
|
|
123
|
+
ensure
|
|
124
|
+
FileUtils.rm_f(temporary) if temporary
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def fingerprint(path)
|
|
128
|
+
stat = path.lstat
|
|
129
|
+
if stat.symlink?
|
|
130
|
+
{ 'type' => 'link', 'target' => path.readlink.to_s }
|
|
131
|
+
else
|
|
132
|
+
{ 'type' => 'file', 'size' => stat.size, 'mtime_ns' => stat.mtime.nsec + (stat.mtime.to_i * 1_000_000_000),
|
|
133
|
+
'mode' => stat.mode }
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# preserve: true keeps the source mode, so an executable stays executable
|
|
138
|
+
# even when the shadow lives on a DrvFs mount whose fmask would otherwise
|
|
139
|
+
# strip the bit and break a `RUN ./script` in the image build.
|
|
140
|
+
def copy_entry_atomically(source, target)
|
|
141
|
+
FileUtils.mkdir_p(target.dirname)
|
|
142
|
+
temporary = target.dirname.join(".#{target.basename}.wip-#{Process.pid}")
|
|
143
|
+
FileUtils.rm_rf(temporary)
|
|
144
|
+
FileUtils.copy_entry(source, temporary, true, false, false)
|
|
145
|
+
replace_atomically(temporary, target)
|
|
146
|
+
ensure
|
|
147
|
+
FileUtils.rm_rf(temporary) if temporary
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# rename replaces an existing entry in a single step, so an interrupted
|
|
151
|
+
# update leaves the previous copy in place instead of no copy at all. Only
|
|
152
|
+
# a target rename can't overwrite — a directory where a file now lives, or
|
|
153
|
+
# a filesystem without overwrite semantics — needs the unsafe fallback.
|
|
154
|
+
def replace_atomically(temporary, target)
|
|
155
|
+
File.rename(temporary, target)
|
|
156
|
+
rescue Errno::EISDIR, Errno::ENOTDIR, Errno::ENOTEMPTY, Errno::EEXIST, Errno::EPERM, Errno::EACCES
|
|
157
|
+
FileUtils.rm_rf(target)
|
|
158
|
+
File.rename(temporary, target)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def prune_empty_parents(directory, root)
|
|
162
|
+
while empty_descendant?(directory, root)
|
|
163
|
+
directory.rmdir
|
|
164
|
+
directory = directory.dirname
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def empty_descendant?(directory, root)
|
|
169
|
+
directory != root && directory.to_s.start_with?("#{root}/") &&
|
|
170
|
+
directory.directory? && directory.children.empty?
|
|
171
|
+
end
|
|
172
|
+
|
|
31
173
|
def copy_included_files(destination, on_progress)
|
|
32
174
|
files = included_files
|
|
33
175
|
on_progress&.call(0, files.size)
|
|
@@ -37,7 +179,7 @@ module Wip
|
|
|
37
179
|
# Keep links as links. Dereferencing a link here could copy arbitrary
|
|
38
180
|
# host files outside the build context (for example, ~/.ssh/id_rsa)
|
|
39
181
|
# into the staged directory and expose them to the image build.
|
|
40
|
-
FileUtils.copy_entry(@root.join(relative_path), target,
|
|
182
|
+
FileUtils.copy_entry(@root.join(relative_path), target, true, false, false)
|
|
41
183
|
on_progress&.call(index + 1, files.size)
|
|
42
184
|
end
|
|
43
185
|
end
|
data/lib/wip/cli.rb
CHANGED
|
@@ -73,7 +73,8 @@ module Wip
|
|
|
73
73
|
context = Pathname(load_config.path).dirname.join(settings['context'] || '.').to_s
|
|
74
74
|
warn "wip: staging build context (#{context})"
|
|
75
75
|
progress = StagingProgress.new
|
|
76
|
-
BuildContext.new(context
|
|
76
|
+
build_context = BuildContext.new(context, shadow_root: settings['shadow_context'])
|
|
77
|
+
build_context.stage(on_progress: progress.method(:tick)) do |staged_context|
|
|
77
78
|
progress.finish
|
|
78
79
|
built = builder.build(settings: settings.merge('context' => staged_context), extra: extra)
|
|
79
80
|
execute(built, interactive: tty?(true))
|
data/lib/wip/config.rb
CHANGED
|
@@ -27,7 +27,18 @@ module Wip
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def wslc_command = @raw.dig('wslc', 'command') || 'auto'
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
# interaction: is dip's name for the same concept — accepted as an alias so a
|
|
32
|
+
# dip.yml can be renamed to wip.yml with fewer edits. The two are mutually
|
|
33
|
+
# exclusive (validate_commands!) rather than merged, so a project doesn't end up
|
|
34
|
+
# with the same command split across both keys.
|
|
35
|
+
def commands
|
|
36
|
+
return @raw['commands'] if @raw.key?('commands')
|
|
37
|
+
return @raw['interaction'] if @raw.key?('interaction')
|
|
38
|
+
|
|
39
|
+
{}
|
|
40
|
+
end
|
|
41
|
+
|
|
31
42
|
# Raw dependencies: block as written in wip.yml. Under compose-native mode this stays
|
|
32
43
|
# empty by construction (validate_compose! forbids combining the two) — #dependencies
|
|
33
44
|
# below is what callers actually want, since it's synthesized from compose.yml there.
|
|
@@ -126,6 +137,8 @@ module Wip
|
|
|
126
137
|
end
|
|
127
138
|
|
|
128
139
|
def validate_commands!
|
|
140
|
+
raise ConfigError, 'commands is mutually exclusive with interaction — pick one' \
|
|
141
|
+
if @raw.key?('commands') && @raw.key?('interaction')
|
|
129
142
|
raise ConfigError, 'commands must be a mapping' unless commands.is_a?(Hash)
|
|
130
143
|
|
|
131
144
|
commands.each { |name, entry| validate_command!(name, entry) }
|
|
@@ -175,9 +188,22 @@ module Wip
|
|
|
175
188
|
type = entry['type'] || (name == 'build' ? 'build' : 'exec')
|
|
176
189
|
raise ConfigError, "Invalid command type for #{name}: #{type}" unless %w[exec run build].include?(type)
|
|
177
190
|
|
|
191
|
+
validate_shadow_context!(name, entry, type)
|
|
192
|
+
|
|
178
193
|
entry['env']&.transform_values!(&:to_s)
|
|
179
194
|
end
|
|
180
195
|
|
|
196
|
+
# shadow_context names a Windows-side mirror of the build context, so it only
|
|
197
|
+
# means anything on a build command — and only as a real path.
|
|
198
|
+
def validate_shadow_context!(name, entry, type)
|
|
199
|
+
return unless entry.key?('shadow_context')
|
|
200
|
+
|
|
201
|
+
shadow_context = entry['shadow_context']
|
|
202
|
+
return if type == 'build' && shadow_context.is_a?(String) && !shadow_context.empty?
|
|
203
|
+
|
|
204
|
+
raise ConfigError, "commands.#{name}.shadow_context must be a non-empty path for a build command"
|
|
205
|
+
end
|
|
206
|
+
|
|
181
207
|
def validate_dependency!(name, entry)
|
|
182
208
|
raise ConfigError, "dependencies.#{name} must be a mapping" unless entry.is_a?(Hash)
|
|
183
209
|
raise ConfigError, "dependencies.#{name} must set image" if entry['image'].to_s.empty?
|
data/lib/wip/initializer.rb
CHANGED
|
@@ -31,17 +31,18 @@ module Wip
|
|
|
31
31
|
# example uses.
|
|
32
32
|
FALLBACK_EXCLUDES = %w[.git tmp/ node_modules/].freeze
|
|
33
33
|
|
|
34
|
-
# Appended to both templates after dependencies/compose.
|
|
35
|
-
# commented since an empty
|
|
34
|
+
# Appended to both templates after dependencies/compose. interaction: itself is left
|
|
35
|
+
# commented since an empty interaction: {} is indistinguishable from omitting the key.
|
|
36
36
|
COMMANDS_EXAMPLE = <<~YAML.chomp
|
|
37
37
|
# optional; custom subcommands, e.g. `wip test` — see README
|
|
38
|
-
# commands:
|
|
38
|
+
# (interaction: is the primary key; commands: is accepted as an alias — the two are
|
|
39
|
+
# mutually exclusive, so pick one)
|
|
40
|
+
# interaction:
|
|
39
41
|
# test:
|
|
40
42
|
# optional; exec (default, runs in the running container) | run (fresh container) | build
|
|
41
43
|
# type: exec
|
|
42
44
|
|
|
43
|
-
#
|
|
44
|
-
# command: bundle exec rspec
|
|
45
|
+
# command: ls
|
|
45
46
|
YAML
|
|
46
47
|
|
|
47
48
|
def initialize(dir: Dir.pwd, template: nil)
|
data/lib/wip/version.rb
CHANGED