gokrazy / tools

this repository contains the gok CLI tool of gokrazy
https://gokrazy.org
BSD 3-Clause "New" or "Revised" License
50 stars 26 forks source link

Using `.` for parent_dir causes issues #57

Open daenney opened 1 year ago

daenney commented 1 year ago

When I try to use --parent_dir . things go wrong for ExtraFilePaths. At that point it no longer resolves relative paths by the instance/next to the config.json, but seems to use the build directory instead.

I suspect this is in the same ballpark as #50?

~/D/g/gotopi  (main) ❯❯❯ gok --version
https://github.com/gokrazy/tools/commit/cd4073ee8575

config.json:

{
    "Hostname": "gotosocial",
    "Packages": [
...
        "github.com/superseriousbusiness/gotosocial/cmd/gotosocial"
    ],
    "PackageConfig": {
...
        "github.com/superseriousbusiness/gotosocial/cmd/gotosocial": {
            "ExtraFilePaths": {
                "/usr/share/gotosocial/web": "assets/web"
            },
...
        }
    },
    "SerialConsole": "disabled",
    "InternalCompatibilityFlags": {}
}
Filesystem layout ``` ~/D/g/gotopi (main) ❯❯❯ pwd /home/daenney/Development/github.com/gotopi ~/D/g/gotopi (main) ❯❯❯ tree . ├── gotosocial │   ├── assets │   │   ├── LICENSE │   │   └── web │   │   ├── assets │   │   │   ├── default_avatars │   │   │   │   ├── GoToSocial_icon1.png │   │   │   │   ├── GoToSocial_icon2.png │   │   │   │   ├── GoToSocial_icon3.png │   │   │   │   ├── GoToSocial_icon4.png │   │   │   │   ├── GoToSocial_icon5.png │   │   │   │   └── GoToSocial_icon6.png │   │   │   ├── default_header.png │   │   │   ├── dist │   │   │   │   ├── base.css │   │   │   │   ├── _colors.css │   │   │   │   ├── frontend.js │   │   │   │   ├── index.css │   │   │   │   ├── profile.css │   │   │   │   ├── settings.js │   │   │   │   ├── settings-style.css │   │   │   │   └── status.css │   │   │   ├── fonts │   │   │   │   ├── noto-sans-v27-latin-700.woff │   │   │   │   ├── noto-sans-v27-latin-700.woff2 │   │   │   │   ├── noto-sans-v27-latin-regular.woff │   │   │   │   ├── noto-sans-v27-latin-regular.woff2 │   │   │   │   └── OFL.txt │   │   │   ├── Fork-Awesome │   │   │   │   ├── CONTRIBUTORS.md │   │   │   │   ├── css │   │   │   │   │   ├── fork-awesome.css │   │   │   │   │   ├── fork-awesome.min.css │   │   │   │   │   ├── fork-awesome.min.css.map │   │   │   │   │   ├── v5-compat.css │   │   │   │   │   ├── v5-compat.min.css │   │   │   │   │   └── v5-compat.min.css.map │   │   │   │   ├── fonts │   │   │   │   │   ├── forkawesome-webfont.eot │   │   │   │   │   ├── forkawesome-webfont.svg │   │   │   │   │   ├── forkawesome-webfont.ttf │   │   │   │   │   ├── forkawesome-webfont.woff │   │   │   │   │   └── forkawesome-webfont.woff2 │   │   │   │   └── LICENSES │   │   │   ├── LICENSE │   │   │   ├── logo.png │   │   │   ├── logo.svg │   │   │   ├── mastodon.svg │   │   │   ├── plyr.svg │   │   │   ├── swagger.yaml │   │   │   └── tusky.svg │   │   └── template │   │   ├── 404.tmpl │   │   ├── about.tmpl │   │   ├── authorize.tmpl │   │   ├── confirmed.tmpl │   │   ├── domain-blocklist.tmpl │   │   ├── email_confirm.tmpl │   │   ├── email_new_report.tmpl │   │   ├── email_report_closed.tmpl │   │   ├── email_reset.tmpl │   │   ├── email_test.tmpl │   │   ├── error.tmpl │   │   ├── finalize.tmpl │   │   ├── footer.tmpl │   │   ├── frontend.tmpl │   │   ├── header.tmpl │   │   ├── index.tmpl │   │   ├── oob.tmpl │   │   ├── profile.tmpl │   │   ├── sign-in.tmpl │   │   ├── status.tmpl │   │   └── thread.tmpl │   ├── breakglass.authorized_keys │   ├── builddir │   │   ├── github.com │   │   │   ├── gokrazy │   │   │   │   ├── breakglass │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── fbstatus │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── firmware │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── gokrazy │   │   │   │   │   ├── cmd │   │   │   │   │   │   ├── dhcp │   │   │   │   │   │   │   ├── go.mod │   │   │   │   │   │   │   └── go.sum │   │   │   │   │   │   ├── heartbeat │   │   │   │   │   │   │   ├── go.mod │   │   │   │   │   │   │   └── go.sum │   │   │   │   │   │   ├── ntp │   │   │   │   │   │   │   ├── go.mod │   │   │   │   │   │   │   └── go.sum │   │   │   │   │   │   └── randomd │   │   │   │   │   │   ├── go.mod │   │   │   │   │   │   └── go.sum │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── hello │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── kernel │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── rpi-eeprom │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   ├── serial-busybox │   │   │   │   │   ├── go.mod │   │   │   │   │   └── go.sum │   │   │   │   └── wifi │   │   │   │   ├── go.mod │   │   │   │   └── go.sum │   │   │   └── superseriousbusiness │   │   │   └── gotosocial │   │   │   └── cmd │   │   │   └── gotosocial │   │   │   ├── go.mod │   │   │   └── go.sum │   │   └── init │   │   ├── go.mod │   │   └── go.sum │   └── config.json └── README.md 34 directories, 96 files ```

Building with: gok --parent_dir /home/daenney/Development/github.com/gotopi -i gotosocial overwrite --root root.squashfs succeeds.

Building with gok --parent_dir . -i gotosocial overwrite --root root.squashfs fails with:

2023/06/19 13:49:53 open /home/daenney/Development/github.com/gotopi/gotosocial/builddir/github.com/superseriousbusiness/gotosocial/cmd/gotosocial/assets/web/assets/LICENSE: no such file or directory
stapelberg commented 1 year ago

Quick note: the expectation is that you use --parent_dir=.., but not --parent_dir=., which doesn’t make sense to me. I’ll need to read your message in more detail to better understand what you’re trying to do.

daenney commented 1 year ago

Mmm right, maybe my setup is weird.

I'm working on something reproducible for others, so I don't want things in ~/gokrazy/.... The --parent_dir seemed to be the right thing for that, and since I'm cded into that repository --parent-dir . made the most sense to me.

stapelberg commented 1 year ago

parent_dir is the right flag for it, just use --parent_dir=.. and -i matching the name of the current directory.

daenney commented 1 year ago

I'm not quite sure I follow. . is current directory, which is what I wanted.

My steps were basically this:

That in return created repo/instance for me, and within instance lives config.json.

If I'm standing at repo, I would expect gok --parent_dir . -i instance edit to work, and indeed it does, it opens repo/instance/config.json.

However, when I build the rootfs, the . seems to cause confusion for the builder, at least when resolving ExtraFilePaths. Whereas if I replace it with the absolute path to repo instead, it works. Both of these should be the same, so I'm not sure why it behaves differently?

stapelberg commented 1 year ago

However, when I build the rootfs, the . seems to cause confusion for the builder, at least when resolving ExtraFilePaths.

That might just be a bug. Relative paths should be resolved to absolute quite early, but maybe not everywhere/not correctly.

stapelberg commented 1 year ago

Maybe using --parent_dir $PWD unblocks you for now?

daenney commented 1 year ago

Yes, using the absolute paths seems to always work reliably. I'll do that for now and take a look at how the paths are resolved internally.

stapelberg commented 1 year ago

I can’t reproduce the issue:

% pwd
/tmp

% rm -rf parent
% mkdir parent
% cat > parent/config.json <<'EOT'
{
    "Hostname": "parent",
    "Update": {
        "HTTPPassword": "2tXVASTRRuI1ywgK5NS2"
    },
    "Packages": [
        "github.com/gokrazy/fbstatus",
        "github.com/gokrazy/hello",
        "github.com/gokrazy/serial-busybox",
        "github.com/gokrazy/breakglass",
    "github.com/superseriousbusiness/gotosocial/cmd/gotosocial"
    ],
    "PackageConfig": {
    "github.com/superseriousbusiness/gotosocial/cmd/gotosocial": {
            "ExtraFilePaths": {
                "/usr/share/gotosocial/web": "assets/web"
            }
        },
        "github.com/gokrazy/gokrazy/cmd/randomd": {
            "ExtraFileContents": {
                "/etc/machine-id": "a23b1f168437443aafb66b3ff4a834be\n"
            }
        }
    },
    "SerialConsole": "disabled"
}
EOT

% gok --parent_dir . -i parent overwrite --root /tmp/root.squashfs
gokrazy gok gcd4073+ on GOARCH=amd64 GOOS=linux

Build target: CGO_ENABLED=0 GOARCH=arm64 GOOS=linux
Build timestamp: 2023-06-24T19:27:02+02:00
Loading system CA certificates from /etc/ssl/certs/ca-certificates.crt
Building 5 Go packages:

  github.com/gokrazy/fbstatus

  github.com/gokrazy/hello

  github.com/gokrazy/serial-busybox

  github.com/gokrazy/breakglass

  github.com/superseriousbusiness/gotosocial/cmd/gotosocial

[done] in 2.87s                        

Including extra files for Go packages:

Including loadable kernel modules from:
/home/michael/go/pkg/mod/github.com/gokrazy/kernel@v0.0.0-20230622035841-e953d5bc6ad4/lib/modules

Feature summary:
  use GPT: true
  use PARTUUID: true
  use GPT PARTUUID: true

Creating root file system
[done] in 0.82s                           

Build complete!

To interact with the device, gokrazy provides a web interface reachable at:

    http://gokrazy:2tXVASTRRuI1ywgK5NS2@parent/

In addition, the following Linux consoles are set up:

    1. foreground Linux framebuffer console on HDMI

% unsquashfs -ll /tmp/root.squashfs|grep web
dr-xr-xr-x root/root                 3 2023-06-24 19:26 squashfs-root/usr/share/gotosocial/web

Can you provide updated steps to reproduce, ideally with a similarly self-contained transcript?