hashicorp / nomad-pack

Mozilla Public License 2.0
393 stars 51 forks source link

Panic when adding a repo over an already existing repo #390

Closed dani closed 1 year ago

dani commented 1 year ago

As there's no command to refresh a custom repo, the solution should be to add it again (nomad-pack registry add ) Problem: I can add my custom repo the first time, but if I try to add it again so its content gets refreshed, nomad-pack panic

[dbd@laptop-103 #]$ nomad-pack registry add dbd https://git.eht.local/dani/nomad.git
go-getter URL is https://git.eht.local/dani/nomad.git
Registry successfully cloned at /home/EHTRACE.COM/dbd/.cache/nomad/packs/nomad-pack-tmp
Processing pack entries at /home/EHTRACE.COM/dbd/.cache/nomad/packs/nomad-pack-tmp
found pack entry common
Processing pack common@latest
! Error Checking Pack Directory

  temp directory deleted
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xfb71b2]

goroutine 1 [running]:
github.com/hashicorp/nomad-pack/terminal.(*glintUI).ErrorWithContext(0x0?, {0x0?, 0x0}, {0x1310f88, 0x1d}, {0xc00004f680, 0x5, 0xc0006bf7e0?})
    github.com/hashicorp/nomad-pack/terminal/glint.go:370 +0x472
github.com/hashicorp/nomad-pack/internal/pkg/cache.(*Cache).processPackEntry(0xc0000158c0, 0xc0006bf9a8, {0x1638bb8?, 0xc00015f240?})
    github.com/hashicorp/nomad-pack/internal/pkg/cache/add.go:174 +0x50a
github.com/hashicorp/nomad-pack/internal/pkg/cache.(*Cache).addFromURI(0xc0000158c0, 0xc0006bfcd8)
    github.com/hashicorp/nomad-pack/internal/pkg/cache/add.go:112 +0x451
github.com/hashicorp/nomad-pack/internal/pkg/cache.(*Cache).Add(0xc0000158c0, 0xc0006bfcd8)
    github.com/hashicorp/nomad-pack/internal/pkg/cache/add.go:52 +0xab7
github.com/hashicorp/nomad-pack/internal/cli.(*RegistryAddCommand).Run(0xc000035ef0, {0xc0000340d0?, 0x2, 0x2})
    github.com/hashicorp/nomad-pack/internal/cli/registry_add.go:62 +0x771
github.com/mitchellh/cli.(*CLI).Run(0xc0001db7c0)
    github.com/mitchellh/cli@v1.1.4/cli.go:262 +0x5f8
github.com/hashicorp/nomad-pack/internal/cli.Main({0xc0000340a0?, 0x5, 0x5})
    github.com/hashicorp/nomad-pack/internal/cli/main.go:96 +0x2b0
main.main()
    github.com/hashicorp/nomad-pack/main.go:15 +0x77
[dbd@laptop-103 #]$ 

If I remove the cache (deleting ~/.cache/nomad/packs), I can add the repo. This is using the current nightly

pkazmierczak commented 1 year ago

Hi @dani, thanks for submitting the bug report. We made some changes to the way nomad-pack handles registries and the cache. I tried reproducing your issue with a github.com/hashicorp/nomad-pack-community-registry registry, but I couldn't.

$ ls ~/Library/Caches/nomad/packs/
$ nomad-pack registry list
No registries present in the cache.
$ nomad-pack registry add default github.com/hashicorp/nomad-pack-community-registry
go-getter URL is github.com/hashicorp/nomad-pack-community-registry
Registry successfully cloned at /Users/piotrkazmierczak/Library/Caches/nomad/packs/nomad-pack-tmp
Processing pack entries at /Users/piotrkazmierczak/Library/Caches/nomad/packs/nomad-pack-tmp
found pack entry alertmanager
Processing pack alertmanager@latest
Updating pack
Removing previous latest
Writing pack to /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/alertmanager@latest
Loading cloned pack from /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/alertmanager@latest
calculating SHA for latest
SHA ef86104 downloaded at UTC 2023-07-27 13:35:59.424362 +0000 UTC

...✄✄✄...

found pack entry wordpress
Processing pack wordpress@latest
Updating pack
Removing previous latest
Writing pack to /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/wordpress@latest
Loading cloned pack from /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/wordpress@latest
calculating SHA for latest
SHA ef86104 downloaded at UTC 2023-07-27 13:36:00.93157 +0000 UTC

  temp directory deleted
  Registry successfully added to cache.
  REGISTRY NAME |  REF   | LOCAL REF |                    REGISTRY URL
----------------+--------+-----------+-----------------------------------------------------
  default       | latest | ef86104   | github.com/hashicorp/nomad-pack-community-registry

$ ls ~/Library/Caches/nomad/packs/
default/
$ ls ~/Library/Caches/nomad/packs/default/
latest/
$ ls ~/Library/Caches/nomad/packs/default/latest/
alertmanager@latest/               drone@latest/                      loki@latest/                       prometheus_snmp_exporter@latest/
aws_ebs_csi@latest/                faasd@latest/                      metadata.json                      promtail@latest/
aws_efs_csi@latest/                fabio@latest/                      nextcloud@latest/                  rabbitmq@latest/
backstage@latest/                  grafana@latest/                    nginx@latest/                      redis@latest/
boundary@latest/                   haproxy@latest/                    nomad_autoscaler@latest/           simple_service@latest/
caddy@latest/                      hashicups@latest/                  nomad_ingress_nginx@latest/        sonarqube@latest/
ceph@latest/                       hello_world@latest/                opentelemetry_collector@latest/    tempo@latest/
ceph_rbd_csi@latest/               influxdb@latest/                   outline@latest/                    tfc_agent@latest/
chaotic_ngine@latest/              jaeger@latest/                     prometheus@latest/                 traefik@latest/
csi_openstack_cinder@latest/       jenkins@latest/                    prometheus_consul_exporter@latest/ vector@latest/
ctfd@latest/                       kibana@latest/                     prometheus_node_exporter@latest/   wordpress@latest/
$ nomad-pack registry add default github.com/hashicorp/nomad-pack-community-registry
go-getter URL is github.com/hashicorp/nomad-pack-community-registry
Registry successfully cloned at /Users/piotrkazmierczak/Library/Caches/nomad/packs/nomad-pack-tmp
Processing pack entries at /Users/piotrkazmierczak/Library/Caches/nomad/packs/nomad-pack-tmp
found pack entry alertmanager
Processing pack alertmanager@latest
Updating pack
Removing previous latest
Writing pack to /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/alertmanager@latest
Loading cloned pack from /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/alertmanager@latest
calculating SHA for latest
SHA ef86104 downloaded at UTC 2023-07-27 13:36:19.638168 +0000 UTC

...✄✄✄...

found pack entry wordpress
Processing pack wordpress@latest
Updating pack
Removing previous latest
Writing pack to /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/wordpress@latest
Loading cloned pack from /Users/piotrkazmierczak/Library/Caches/nomad/packs/default/latest/wordpress@latest
calculating SHA for latest
SHA ef86104 downloaded at UTC 2023-07-27 13:36:21.27324 +0000 UTC

  temp directory deleted
  Registry successfully added to cache.
  REGISTRY NAME |  REF   | LOCAL REF |                    REGISTRY URL
----------------+--------+-----------+-----------------------------------------------------
  default       | latest | ef86104   | github.com/hashicorp/nomad-pack-community-registry

$ ls ~/Library/Caches/nomad/packs/default/latest/
alertmanager@latest/               drone@latest/                      loki@latest/                       prometheus_snmp_exporter@latest/
aws_ebs_csi@latest/                faasd@latest/                      metadata.json                      promtail@latest/
aws_efs_csi@latest/                fabio@latest/                      nextcloud@latest/                  rabbitmq@latest/
backstage@latest/                  grafana@latest/                    nginx@latest/                      redis@latest/
boundary@latest/                   haproxy@latest/                    nomad_autoscaler@latest/           simple_service@latest/
caddy@latest/                      hashicups@latest/                  nomad_ingress_nginx@latest/        sonarqube@latest/
ceph@latest/                       hello_world@latest/                opentelemetry_collector@latest/    tempo@latest/
ceph_rbd_csi@latest/               influxdb@latest/                   outline@latest/                    tfc_agent@latest/
chaotic_ngine@latest/              jaeger@latest/                     prometheus@latest/                 traefik@latest/
csi_openstack_cinder@latest/       jenkins@latest/                    prometheus_consul_exporter@latest/ vector@latest/
ctfd@latest/                       kibana@latest/                     prometheus_node_exporter@latest/   wordpress@latest/

Could you try again with nomad-pack compiled from main and see if it perhaps resolves the issue?

dani commented 1 year ago

You're right. Building from main the problem doesn't exist. I'll close this issue. BTW I don't understand, I though the nightly build was ... built nightly, but it looks like the latest is from May 17