Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| da1fb2ae17 | |||
| 8a2713bd3b | |||
| 5b65b37d81 | |||
| d806f056f3 | |||
| ec89ce64bd | |||
| 91b3730f0c | |||
| db45af6b9d | |||
|
|
f0bebff6a1 | ||
|
|
e6d1a95c02 | ||
|
|
725fb5679b | ||
|
|
8f80dc49f5 | ||
|
|
6d24d0da7a | ||
|
|
d3efb410d0 | ||
| 1c46fb8617 | |||
| 4408a9e005 | |||
| 41baf180a3 | |||
| 4754869190 | |||
| ec62b65ecd | |||
| 0ff72b99d9 | |||
| e4c0d4d72a | |||
| eab7c3c1ef | |||
| ec61d24fd4 | |||
| d3933efd74 | |||
| a265915b21 | |||
| 8c00e74df9 | |||
| 5e297827d3 | |||
| dc03b29e6e | |||
| f02af98ac5 | |||
| cca579d218 | |||
| 436a866f5d | |||
| 71aab65b75 | |||
| 984752b812 | |||
| 4568429a69 | |||
| 6f40bc91be | |||
| 63d171007e | |||
| 5d4d6410da |
19
.build.yml
19
.build.yml
@@ -1,19 +0,0 @@
|
|||||||
image: alpine/edge
|
|
||||||
packages:
|
|
||||||
- go
|
|
||||||
- git
|
|
||||||
- make
|
|
||||||
sources:
|
|
||||||
- https://git.sr.ht/~motiejus/undocker
|
|
||||||
tasks:
|
|
||||||
- setup: |
|
|
||||||
go install honnef.co/go/tools/cmd/staticcheck@latest
|
|
||||||
- test: |
|
|
||||||
make -C undocker coverage.html
|
|
||||||
- lint: |
|
|
||||||
make -C undocker -O -j$(nproc) lint
|
|
||||||
- binaries: |
|
|
||||||
make -C undocker -O -j$(nproc) sha256sum.txt
|
|
||||||
cat undocker/sha256sum.txt
|
|
||||||
artifacts:
|
|
||||||
- undocker/coverage.html
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
/undocker
|
||||||
/undocker-*
|
/undocker-*
|
||||||
coverage.html
|
coverage.html
|
||||||
sha256sum.txt*
|
sha256sum.txt*
|
||||||
|
|||||||
215
LICENSE
215
LICENSE
@@ -1,19 +1,202 @@
|
|||||||
Copyright (c) 2021 Motiejus Jakštys
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Apache License
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
Version 2.0, January 2004
|
||||||
in the Software without restriction, including without limitation the rights
|
http://www.apache.org/licenses/
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
1. Definitions.
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
SOFTWARE.
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2021 Motiejus Jakštys
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|||||||
49
Makefile
49
Makefile
@@ -1,58 +1,29 @@
|
|||||||
|
SCRIPTS = $(shell awk '/#!\/usr\/bin\/env (ba)?sh/&&FNR==1{print FILENAME}' $(shell git ls-files))
|
||||||
GODEPS = $(shell git ls-files '*.go' go.mod go.sum)
|
GODEPS = $(shell git ls-files '*.go' go.mod go.sum)
|
||||||
GOBIN = $(shell go env GOPATH)/bin/
|
|
||||||
|
|
||||||
GOOSARCHS = $(sort \
|
|
||||||
darwin/amd64 \
|
|
||||||
darwin/arm64 \
|
|
||||||
linux/amd64 \
|
|
||||||
linux/arm64 \
|
|
||||||
windows/amd64/.exe \
|
|
||||||
windows/arm64/.exe)
|
|
||||||
|
|
||||||
VSN ?= $(shell git describe --dirty)
|
VSN ?= $(shell git describe --dirty)
|
||||||
VSNHASH = $(shell git rev-parse --verify HEAD)
|
VSNHASH = $(shell git rev-parse --verify HEAD)
|
||||||
LDFLAGS = -ldflags "-X main.Version=$(VSN) -X main.VersionHash=$(VSNHASH)"
|
LDFLAGS = -ldflags "-X main.Version=$(VSN) -X main.VersionHash=$(VSNHASH)"
|
||||||
|
|
||||||
|
undocker: ## builds binary for the current architecture
|
||||||
|
go build $(LDFLAGS) -o $@
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test: coverage.out
|
||||||
go test -race -cover ./...
|
|
||||||
|
|
||||||
define undockertarget
|
|
||||||
UNDOCKERS += undocker-$(1)-$(2)-$(VSN)$(firstword $(3))
|
|
||||||
undocker-$(1)-$(2)-$(VSN)$(firstword $(3)): $(GODEPS)
|
|
||||||
CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build $(LDFLAGS) -o $$@
|
|
||||||
endef
|
|
||||||
|
|
||||||
$(foreach goosarch,$(GOOSARCHS),\
|
|
||||||
$(eval $(call undockertarget,$(word 1,$(subst /, ,$(goosarch))),$(word 2,$(subst /, ,$(goosarch))),$(word 3,$(subst /, ,$(goosarch))))))
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: $(UNDOCKERS)
|
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: vet staticcheck
|
lint:
|
||||||
|
|
||||||
.PHONY: vet
|
|
||||||
vet:
|
|
||||||
go vet ./...
|
go vet ./...
|
||||||
|
staticcheck -f stylish ./...
|
||||||
.PHONY: staticcheck
|
shellcheck $(SCRIPTS)
|
||||||
staticcheck:
|
|
||||||
$(GOBIN)staticcheck -f stylish ./...
|
|
||||||
|
|
||||||
.INTERMEDIATE: coverage.out
|
.INTERMEDIATE: coverage.out
|
||||||
coverage.out: $(GODEPS)
|
coverage.out: $(GODEPS)
|
||||||
go test -coverprofile $@ ./...
|
go test -race -cover -coverprofile $@ ./...
|
||||||
|
|
||||||
coverage.html: coverage.out
|
coverage.html: coverage.out
|
||||||
go tool cover -html=$< -o $@
|
go tool cover -html=$< -o $@
|
||||||
|
|
||||||
sha256sum.txt: $(UNDOCKERS)
|
|
||||||
sha256sum $(UNDOCKERS) > $@
|
|
||||||
|
|
||||||
sha256sum.txt.asc: sha256sum.txt
|
|
||||||
gpg --clearsign $<
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f undocker-*-v* coverage.html sha256sum.txt sha256sum.txt.asc
|
rm -f undocker coverage.html
|
||||||
|
|||||||
95
README.md
95
README.md
@@ -1,11 +1,19 @@
|
|||||||
[](http://godocs.io/git.sr.ht/~motiejus/undocker)
|
[](http://godocs.io/git.jakstys.lt/motiejus/undocker)
|
||||||
[](https://builds.sr.ht/~motiejus/undocker?)
|
|
||||||
|
|
||||||
Undocker
|
Undocker
|
||||||
--------
|
--------
|
||||||
|
|
||||||
Converts a Docker image (a bunch of layers) to a flattened "rootfs" tarball.
|
Converts a Docker image (a bunch of layers) to a flattened "rootfs" tarball.
|
||||||
|
|
||||||
|
Project Status
|
||||||
|
--------------
|
||||||
|
|
||||||
|
The project was announced to be deprecated in the beginning of 2024, but the
|
||||||
|
maintainer has an interest in Docker ecosystem again, thus will maintain it
|
||||||
|
somewhat starting at mid-2024.
|
||||||
|
|
||||||
|
The author has some significant changes in mind, but the timeline is unknown.
|
||||||
|
|
||||||
Why?
|
Why?
|
||||||
----
|
----
|
||||||
|
|
||||||
@@ -18,7 +26,19 @@ and application isolation ("container") runtimes: once the docker image is
|
|||||||
extracted, it can be run with old-fashioned tools: lxc, systemd-nspawn,
|
extracted, it can be run with old-fashioned tools: lxc, systemd-nspawn,
|
||||||
systemd, FreeBSD Jails, and many others.
|
systemd, FreeBSD Jails, and many others.
|
||||||
|
|
||||||
Undocker has no dependencies outside Golang stdlib.
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
Build it like this for the "current" platform:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ make undocker
|
||||||
|
```
|
||||||
|
|
||||||
|
`make -B` will print the extra flags (`-X <...>`) for cross-compiling with
|
||||||
|
other archs. It's all `go build <...>` in the back, and depends only on Go's
|
||||||
|
compiler and stdlib.
|
||||||
|
|
||||||
Usage: convert docker image to rootfs
|
Usage: convert docker image to rootfs
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
@@ -27,69 +47,53 @@ Download `busybox` docker image from docker hub and convert it to a rootfs:
|
|||||||
|
|
||||||
```
|
```
|
||||||
$ skopeo copy docker://docker.io/busybox:latest docker-archive:busybox.tar
|
$ skopeo copy docker://docker.io/busybox:latest docker-archive:busybox.tar
|
||||||
$ undocker busybox.tar - | tar -tv | head -10
|
$ undocker busybox.tar - | tar -xv | sponge | head -10; echo '<...>'
|
||||||
drwxr-xr-x 0/0 0 2021-05-17 22:07 bin/
|
bin/
|
||||||
-rwxr-xr-x 0/0 1149184 2021-05-17 22:07 bin/[
|
bin/[
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/[[ link to bin/[
|
bin/[[
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/acpid link to bin/[
|
bin/acpid
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/add-shell link to bin/[
|
bin/add-shell
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/addgroup link to bin/[
|
bin/addgroup
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/adduser link to bin/[
|
bin/adduser
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/adjtimex link to bin/[
|
bin/adjtimex
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/ar link to bin/[
|
bin/ar
|
||||||
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/arch link to bin/[
|
bin/arch
|
||||||
|
<...>
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also refer [here][2] for other ways to download Docker images. There
|
Refer [here][2] for other ways to download Docker images. There are many.
|
||||||
are many.
|
|
||||||
|
|
||||||
Converting a [1.1GB Docker image with 77
|
On author's laptop converting a [1.1GB Docker image with 77
|
||||||
layers](https://hub.docker.com/r/homeassistant/home-assistant) takes around 4
|
layers](https://hub.docker.com/r/homeassistant/home-assistant) takes around 3
|
||||||
seconds and on a reasonably powerful Intel laptop.
|
seconds and uses ~65MB of residential memory.
|
||||||
|
|
||||||
Usage example: systemd-nspawn
|
Usage example: systemd
|
||||||
-----------------------------
|
----------------------
|
||||||
|
|
||||||
Start with systemd-nspawn:
|
|
||||||
|
|
||||||
```
|
|
||||||
systemd-nspawn -D $PWD busybox httpd -vfp 8080
|
|
||||||
```
|
|
||||||
|
|
||||||
Usage example: plain old systemd
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
```
|
```
|
||||||
systemd-run \
|
systemd-run \
|
||||||
--wait --pty --collect --service-type=exec \
|
--wait --pty --collect --service-type=exec \
|
||||||
|
-p RootDirectory=$PWD \
|
||||||
|
-p ProtectProc=invisible \
|
||||||
-p PrivateUsers=true \
|
-p PrivateUsers=true \
|
||||||
-p DynamicUser=yes \
|
-p DynamicUser=yes \
|
||||||
-p ProtectProc=invisible \
|
|
||||||
-p RootDirectory=$PWD \
|
|
||||||
-- busybox httpd -vfp 8080
|
-- busybox httpd -vfp 8080
|
||||||
```
|
```
|
||||||
|
|
||||||
Good things like `PrivateUsers`, `DynamicUser`, `ProtectProc` and other
|
[Systemd protections][1] like `PrivateUsers`, `DynamicUser`, `ProtectProc` and
|
||||||
[systemd protections][1] are available, just like to any systemd unit.
|
others are available, just like to any systemd unit.
|
||||||
|
|
||||||
Similar Projects
|
Similar Projects
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
* [rootfs_builder](https://github.com/ForAllSecure/rootfs_builder)
|
* [rootfs_builder](https://github.com/ForAllSecure/rootfs_builder)
|
||||||
|
|
||||||
Changelog
|
|
||||||
---------
|
|
||||||
|
|
||||||
**v1.0**
|
|
||||||
|
|
||||||
* initial release: `rootfs.Flatten` and a simple command-line application.
|
|
||||||
|
|
||||||
Contributions
|
Contributions
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
The following contributions may be accepted:
|
The following contributions may be accepted:
|
||||||
|
|
||||||
- Pull requests (patchsets) with accompanying tests.
|
- Patchsets, with accompanying tests.
|
||||||
- Regression reports.
|
- Regression reports.
|
||||||
|
|
||||||
If you found a container that undocker cannot extract, or extracts incorrectly
|
If you found a container that undocker cannot extract, or extracts incorrectly
|
||||||
@@ -100,6 +104,11 @@ Reports of regression reports must provide examples of "works before" and "does
|
|||||||
not work after". Issues without an accompanying patch will most likely be
|
not work after". Issues without an accompanying patch will most likely be
|
||||||
rejected.
|
rejected.
|
||||||
|
|
||||||
|
Communication
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Feel free to ping me [directly][motiejus-comms].
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@@ -107,3 +116,5 @@ MIT
|
|||||||
|
|
||||||
[1]: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
|
[1]: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
|
||||||
[2]: https://fly.io/blog/docker-without-docker/
|
[2]: https://fly.io/blog/docker-without-docker/
|
||||||
|
|
||||||
|
[motiejus-comms]: https://jakstys.lt/contact/
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module git.sr.ht/~motiejus/undocker
|
module git.jakstys.lt/motiejus/undocker
|
||||||
|
|
||||||
go 1.16
|
go 1.20
|
||||||
|
|||||||
19
main.go
19
main.go
@@ -2,13 +2,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"git.sr.ht/~motiejus/undocker/rootfs"
|
"git.jakstys.lt/motiejus/undocker/rootfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "unknown"
|
var Version = "unknown"
|
||||||
@@ -42,7 +43,7 @@ func main() {
|
|||||||
|
|
||||||
c := &command{flattener: rootfs.Flatten, Stdout: os.Stdout}
|
c := &command{flattener: rootfs.Flatten, Stdout: os.Stdout}
|
||||||
if err := c.execute(os.Args[1], os.Args[2]); err != nil {
|
if err := c.execute(os.Args[1], os.Args[2]); err != nil {
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -53,16 +54,13 @@ type command struct {
|
|||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *command) execute(infile string, outfile string) (err error) {
|
func (c *command) execute(infile string, outfile string) (_err error) {
|
||||||
rd, err := os.Open(infile)
|
rd, err := os.Open(infile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err1 := rd.Close()
|
_err = errors.Join(_err, rd.Close())
|
||||||
if err == nil {
|
|
||||||
err = err1
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var out io.Writer
|
var out io.Writer
|
||||||
@@ -74,9 +72,10 @@ func (c *command) execute(infile string, outfile string) (err error) {
|
|||||||
return fmt.Errorf("create: %w", err)
|
return fmt.Errorf("create: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err1 := outf.Close()
|
if _err != nil {
|
||||||
if err == nil {
|
_err = errors.Join(_err, os.Remove(outfile))
|
||||||
err = err1
|
} else {
|
||||||
|
_err = errors.Join(_err, outf.Close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
out = outf
|
out = outf
|
||||||
|
|||||||
67
main_test.go
67
main_test.go
@@ -2,8 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -13,18 +14,20 @@ func TestExecute(t *testing.T) {
|
|||||||
var _foo = []byte("foo foo")
|
var _foo = []byte("foo foo")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
fixture func(*testing.T, string)
|
fixture func(*testing.T, string)
|
||||||
infile string
|
flattener func(io.ReadSeeker, io.Writer) error
|
||||||
outfile string
|
infile string
|
||||||
wantErr string
|
outfile string
|
||||||
|
wantErr string
|
||||||
|
assertion func(*testing.T, string)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "ok passthrough via stdout",
|
name: "ok passthrough via stdout",
|
||||||
infile: "t10-in.txt",
|
infile: "t10-in.txt",
|
||||||
fixture: func(t *testing.T, dir string) {
|
fixture: func(t *testing.T, dir string) {
|
||||||
fname := filepath.Join(dir, "t10-in.txt")
|
fname := filepath.Join(dir, "t10-in.txt")
|
||||||
if err := ioutil.WriteFile(fname, _foo, 0644); err != nil {
|
if err := os.WriteFile(fname, _foo, 0644); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -35,12 +38,37 @@ func TestExecute(t *testing.T) {
|
|||||||
infile: "t20-in.txt",
|
infile: "t20-in.txt",
|
||||||
fixture: func(t *testing.T, dir string) {
|
fixture: func(t *testing.T, dir string) {
|
||||||
fname := filepath.Join(dir, "t20-in.txt")
|
fname := filepath.Join(dir, "t20-in.txt")
|
||||||
if err := ioutil.WriteFile(fname, _foo, 0644); err != nil {
|
if err := os.WriteFile(fname, _foo, 0644); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
outfile: "t20-out.txt",
|
outfile: "t20-out.txt",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "bad flattener should remove the file",
|
||||||
|
infile: "t30-in.txt",
|
||||||
|
fixture: func(t *testing.T, dir string) {
|
||||||
|
fname := filepath.Join(dir, "t30-in.txt")
|
||||||
|
if err := os.WriteFile(fname, _foo, 0644); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
flattener: flattenBad,
|
||||||
|
outfile: "t30-out.txt",
|
||||||
|
wantErr: "some error",
|
||||||
|
assertion: func(t *testing.T, dir string) {
|
||||||
|
d, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if len(d) != 1 {
|
||||||
|
t.Fatalf("expected 1 entry, got %d", len(d))
|
||||||
|
}
|
||||||
|
if d[0].Name() != "t30-in.txt" {
|
||||||
|
t.Fatalf("expected to find only t30-in.txt, got %s", d[0].Name())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "infile does not exist",
|
name: "infile does not exist",
|
||||||
infile: "t3-does-not-exist.txt",
|
infile: "t3-does-not-exist.txt",
|
||||||
@@ -57,7 +85,10 @@ func TestExecute(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
c := &command{Stdout: &stdout}
|
if tt.flattener == nil {
|
||||||
|
tt.flattener = flattenPassthrough
|
||||||
|
}
|
||||||
|
|
||||||
if tt.fixture != nil {
|
if tt.fixture != nil {
|
||||||
tt.fixture(t, dir)
|
tt.fixture(t, dir)
|
||||||
}
|
}
|
||||||
@@ -65,9 +96,14 @@ func TestExecute(t *testing.T) {
|
|||||||
tt.outfile = filepath.Join(dir, tt.outfile)
|
tt.outfile = filepath.Join(dir, tt.outfile)
|
||||||
}
|
}
|
||||||
inf := filepath.Join(dir, tt.infile)
|
inf := filepath.Join(dir, tt.infile)
|
||||||
c.flattener = flattenPassthrough
|
|
||||||
|
|
||||||
|
c := &command{Stdout: &stdout, flattener: tt.flattener}
|
||||||
err := c.execute(inf, tt.outfile)
|
err := c.execute(inf, tt.outfile)
|
||||||
|
|
||||||
|
if tt.assertion != nil {
|
||||||
|
tt.assertion(t, dir)
|
||||||
|
}
|
||||||
|
|
||||||
if tt.wantErr != "" {
|
if tt.wantErr != "" {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
@@ -78,21 +114,22 @@ func TestExecute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var out []byte
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
var out []byte
|
||||||
if tt.outfile == "-" {
|
if tt.outfile == "-" {
|
||||||
out = stdout.Bytes()
|
out = stdout.Bytes()
|
||||||
} else {
|
} else {
|
||||||
out, err = ioutil.ReadFile(tt.outfile)
|
out, err = os.ReadFile(tt.outfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !bytes.Equal([]byte("foo foo"), out) {
|
if !bytes.Equal([]byte("foo foo"), out) {
|
||||||
t.Errorf("out != foo foo: %s", string(out))
|
t.Errorf("out != foo foo: %q", string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,3 +138,7 @@ func flattenPassthrough(r io.ReadSeeker, w io.Writer) error {
|
|||||||
_, err := io.Copy(w, r)
|
_, err := io.Copy(w, r)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flattenBad(_ io.ReadSeeker, _ io.Writer) error {
|
||||||
|
return errors.New("some error")
|
||||||
|
}
|
||||||
|
|||||||
37
release
37
release
@@ -1,32 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
err() {
|
_err(){ >&2 echo "ERROR: $*"; exit 1; }
|
||||||
>&2 echo "ERROR: $*"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ -n "$(git status --porcelain)" ]] && \
|
git status --porcelain | grep -q "" &&
|
||||||
err "working tree is dirty, commit your changes first."
|
_err "working tree is dirty, commit your changes first."
|
||||||
|
|
||||||
[[ ! "$1" =~ ^v([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]] && \
|
[[ "$1" =~ ^v([0-9]+)\.([0-9]+)(\.([0-9]+))?(-rc([0-9]+))?$ ]] || \
|
||||||
err "arg1 accepts the following formats: v1.0 v1.0.0"
|
_err "arg1 accepts the following formats: v1.0 v1.0.0 v1.0-rc1 v1.0.1-rc1"
|
||||||
|
|
||||||
[[ -n "$(git tag | grep "^$1$")" ]] && \
|
git tag | grep -q "^$1$" &&
|
||||||
err "tag $1 already exists"
|
_err "tag $1 already exists"
|
||||||
|
|
||||||
|
# sanity test: do the tests pass?
|
||||||
|
make -B -j"$(nproc)" test lint
|
||||||
|
|
||||||
last_tag=$(git tag | tail -1)
|
last_tag=$(git tag | tail -1)
|
||||||
|
|
||||||
make -B -j$(nproc) VSN=$1 sha256sum.txt.asc
|
|
||||||
|
|
||||||
{
|
{
|
||||||
echo undocker $1
|
echo undocker "$1"
|
||||||
echo
|
echo
|
||||||
echo Changelog since $last_tag:
|
echo Changelog since "$last_tag":
|
||||||
git log --pretty=format:"- [%cn] %s" $last_tag..HEAD
|
git log --pretty=format:"- [%an] %s" "$last_tag"..HEAD
|
||||||
echo
|
} | git tag -F - "$1"
|
||||||
echo
|
|
||||||
echo sha256sums of released binaries:
|
|
||||||
cat sha256sum.txt
|
|
||||||
echo
|
|
||||||
} | git tag -u motiejus@jakstys.lt -F - "$1"
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func Flatten(rd io.ReadSeeker, w io.Writer) (_err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
layerOffsets[hdr.Name] = here
|
layerOffsets[strings.TrimPrefix(hdr.Name, "./")] = here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ func Flatten(rd io.ReadSeeker, w io.Writer) (_err error) {
|
|||||||
for i, name := range manifest[0].Layers {
|
for i, name := range manifest[0].Layers {
|
||||||
layers[i] = nameOffset{
|
layers[i] = nameOffset{
|
||||||
name: name,
|
name: name,
|
||||||
offset: layerOffsets[name],
|
offset: layerOffsets[strings.TrimPrefix(name, "./")],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,12 +144,7 @@ func Flatten(rd io.ReadSeeker, w io.Writer) (_err error) {
|
|||||||
|
|
||||||
tw := tar.NewWriter(w)
|
tw := tar.NewWriter(w)
|
||||||
defer func() {
|
defer func() {
|
||||||
// Avoiding use of multierr: if error is present, return
|
_err = errors.Join(_err, tw.Close())
|
||||||
// that. Otherwise return whatever `Close` returns.
|
|
||||||
err1 := tw.Close()
|
|
||||||
if _err == nil {
|
|
||||||
_err = err1
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
// iterate through all layers, all files, and write files.
|
// iterate through all layers, all files, and write files.
|
||||||
for i, no := range layers {
|
for i, no := range layers {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.sr.ht/~motiejus/undocker/rootfs/internal/tartest"
|
"git.jakstys.lt/motiejus/undocker/rootfs/internal/tartest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
Reference in New Issue
Block a user