11 Commits

Author SHA1 Message Date
eab7c3c1ef [release] fix nullglob issue 2021-09-06 15:36:50 +03:00
ec61d24fd4 [nit] Makefile style 2021-09-06 09:01:05 +03:00
d3933efd74 Update README
- add communication section
- remove systemd-nspawn section
2021-09-06 08:25:11 +03:00
a265915b21 Shellcheck release 2021-09-01 09:41:00 +03:00
8c00e74df9 Update release script
- fix paths of sha256sum
- check for old artifacts before doing the release
2021-09-01 09:38:13 +03:00
5e297827d3 update README with more actionable examples 2021-09-01 09:32:26 +03:00
dc03b29e6e Revert "add WithFilePrefix"
This reverts commit 436a866f5d.

This is not a good place for such auxiliary functionality; will be moved
elsewhere.
2021-08-29 18:40:11 +03:00
f02af98ac5 nit: shorter defer body 2021-08-29 18:39:43 +03:00
cca579d218 update Makefile and default target
Adds a `sha256sum-$(VSN).txt`. For easier CI.
2021-08-29 18:23:49 +03:00
436a866f5d add WithFilePrefix
This adds an option to prefix every file path with a given string.
2021-08-29 16:55:32 +03:00
71aab65b75 version sha256sum files 2021-08-29 07:49:32 +03:00
6 changed files with 54 additions and 51 deletions

View File

@@ -14,7 +14,7 @@ tasks:
- lint: |
make -C undocker -O -j$(nproc) lint
- binaries: |
make -C undocker -O -j$(nproc) sha256sum.txt
cat undocker/sha256sum.txt
make -C undocker -O -j$(nproc) all
cat undocker/sha256sum-*.txt
artifacts:
- undocker/coverage.html

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/undocker
/undocker-*
coverage.html
sha256sum.txt*

View File

@@ -1,6 +1,5 @@
SCRIPTS = $(shell awk '/#!\/bin\/(ba)?sh/&&FNR==1{print FILENAME}' $(shell git ls-files))
GODEPS = $(shell git ls-files '*.go' go.mod go.sum)
GOBIN = $(shell go env GOPATH)/bin/
GOOSARCHS = $(sort darwin/amd64 linux/amd64)
VSN ?= $(shell git describe --dirty)
@@ -24,12 +23,15 @@ $(foreach goosarch,$(GOOSARCHS),\
$(eval $(call undockertarget,$(word 1,$(subst /, ,$(goosarch))),$(word 2,$(subst /, ,$(goosarch))))))
.PHONY: all
all: $(UNDOCKERS)
all: $(UNDOCKERS) sha256sum-$(VSN).txt
.PHONY: sha256sum-asc
sha256sum-asc: sha256sum-$(VSN).txt.asc
.PHONY: lint
lint:
go vet ./...
$(GOBIN)staticcheck -f stylish ./...
$(shell go env GOPATH)/bin/staticcheck -f stylish ./...
shellcheck $(SCRIPTS)
.INTERMEDIATE: coverage.out
@@ -39,12 +41,12 @@ coverage.out: $(GODEPS)
coverage.html: coverage.out
go tool cover -html=$< -o $@
sha256sum.txt: $(UNDOCKERS)
sha256sum-$(VSN).txt: $(UNDOCKERS)
sha256sum $(UNDOCKERS) > $@
sha256sum.txt.asc: sha256sum.txt
sha256sum-$(VSN).txt.asc: sha256sum-$(VSN).txt
gpg --clearsign $<
.PHONY: clean
clean:
rm -f undocker-*-v* coverage.html sha256sum.txt sha256sum.txt.asc
rm -f undocker-*-v* coverage.html sha256sum*.txt sha256sum*.txt.asc

View File

@@ -23,16 +23,12 @@ Undocker has no dependencies outside Golang stdlib.
Installation
------------
We recommend using [officially released binaries][3]. To build the project
instead, run:
You may use [officially released binaries][3], or build it:
```
$ make undocker
```
The number of officially released binaries is quite limited. If you'd like me
to expand a list, please contribute a patch to the Makefile.
Usage: convert docker image to rootfs
-------------------------------------
@@ -40,50 +36,41 @@ Download `busybox` docker image from docker hub and convert it to a rootfs:
```
$ skopeo copy docker://docker.io/busybox:latest docker-archive:busybox.tar
$ undocker busybox.tar - | tar -tv | head -10
drwxr-xr-x 0/0 0 2021-05-17 22:07 bin/
-rwxr-xr-x 0/0 1149184 2021-05-17 22:07 bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/[[ link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/acpid link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/add-shell link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/addgroup link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/adduser link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/adjtimex link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/ar link to bin/[
hrwxr-xr-x 0/0 0 2021-05-17 22:07 bin/arch link to bin/[
$ undocker busybox.tar - | tar -xv | sponge | head -10; echo '<...>'
bin/
bin/[
bin/[[
bin/acpid
bin/add-shell
bin/addgroup
bin/adduser
bin/adjtimex
bin/ar
bin/arch
<...>
```
You can also refer [here][2] for other ways to download Docker images. There
are many.
Refer [here][2] for other ways to download Docker images. There are many.
Converting a [1.1GB Docker image with 77
layers](https://hub.docker.com/r/homeassistant/home-assistant) takes around 4
seconds and on a reasonably powerful Intel laptop.
On author's laptop converting a [1.1GB Docker image with 77
layers](https://hub.docker.com/r/homeassistant/home-assistant) takes around 3
seconds and uses ~65MB of residential memory.
Usage example: systemd-nspawn
-----------------------------
Start with systemd-nspawn:
```
systemd-nspawn -D $PWD busybox httpd -vfp 8080
```
Usage example: plain old systemd
--------------------------------
Usage example: systemd
----------------------
```
systemd-run \
--wait --pty --collect --service-type=exec \
-p RootDirectory=$PWD \
-p ProtectProc=invisible \
-p PrivateUsers=true \
-p DynamicUser=yes \
-p ProtectProc=invisible \
-p RootDirectory=$PWD \
-- busybox httpd -vfp 8080
```
Good things like `PrivateUsers`, `DynamicUser`, `ProtectProc` and other
[systemd protections][1] are available, just like to any systemd unit.
[Systemd protections][1] like `PrivateUsers`, `DynamicUser`, `ProtectProc` and
others are available, just like to any systemd unit.
Similar Projects
----------------
@@ -102,7 +89,7 @@ Contributions
The following contributions may be accepted:
- Pull requests (patchsets) with accompanying tests.
- Patchsets, with accompanying tests.
- Regression reports.
If you found a container that undocker cannot extract, or extracts incorrectly
@@ -113,6 +100,12 @@ Reports of regression reports must provide examples of "works before" and "does
not work after". Issues without an accompanying patch will most likely be
rejected.
Communication
-------------
Use [~motiejus/undocker@lists.sr.ht](mailto:~motiejus/undocker@lists.sr.ht) for
questions or patches. Subscribe [here][4].
LICENSE
-------
@@ -121,3 +114,4 @@ MIT
[1]: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
[2]: https://fly.io/blog/docker-without-docker/
[3]: http://git.sr.ht/~motiejus/undocker
[4]: https://lists.sr.ht/~motiejus/undocker

13
release
View File

@@ -9,7 +9,14 @@ err() {
git status --porcelain | grep -q "" &&
err "working tree is dirty, commit your changes first."
[[ ! "$1" =~ ^v([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]] && \
# https://raimue.blog/2010/09/09/bash-for-loop-with-glob-patterns/
shopt -s nullglob
for file in sha256sum-*; do
err "found $file from previous release, delete it first"
done
shopt -u nullglob
[[ "$1" =~ ^v([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]] || \
err "arg1 accepts the following formats: v1.0 v1.0.0"
git tag | grep -q "^$1$" &&
@@ -17,7 +24,7 @@ git tag | grep -q "^$1$" &&
last_tag=$(git tag | tail -1)
make -B -j"$(nproc)" VSN="$1" sha256sum.txt.asc
make -B -j"$(nproc)" VSN="$1" sha256sum-asc
{
echo undocker "$1"
@@ -27,6 +34,6 @@ make -B -j"$(nproc)" VSN="$1" sha256sum.txt.asc
echo
echo
echo sha256sums of released binaries:
cat sha256sum.txt
cat sha256sum-*.txt
echo
} | git tag -u motiejus@jakstys.lt -F - "$1"

View File

@@ -146,9 +146,8 @@ func Flatten(rd io.ReadSeeker, w io.Writer) (_err error) {
defer func() {
// Avoiding use of multierr: if error is present, return
// that. Otherwise return whatever `Close` returns.
err1 := tw.Close()
if _err == nil {
_err = err1
if err := tw.Close(); err != nil && _err == nil {
_err = err
}
}()
// iterate through all layers, all files, and write files.