trezor / trezord-go

:smiling_imp: Trezor Communication Daemon (written in Go)
GNU Lesser General Public License v3.0
245 stars 148 forks source link

Update Dockerfile and fix Docker build failed #299

Closed nekoteoj closed 10 months ago

nekoteoj commented 10 months ago

Problem: The current Dockerfile doesn't work when building the image. Consequently, the Docker compose file also doesn't work. This problem is caused by following issues.

  1. The latest go version (1.21) can't compile the source file usb/lowlevel/libusb/libusb.go with these error messages.
    usb/lowlevel/libusb/libusb.go:405:10: cannot define new methods on non-local type *C.struct_libusb_endpoint_descriptor
    usb/lowlevel/libusb/libusb.go:455:10: cannot define new methods on non-local type *C.struct_libusb_interface_descriptor
    usb/lowlevel/libusb/libusb.go:510:10: cannot define new methods on non-local type *C.struct_libusb_interface
    usb/lowlevel/libusb/libusb.go:557:10: cannot define new methods on non-local type *C.struct_libusb_config_descriptor
    usb/lowlevel/libusb/libusb.go:615:10: cannot define new methods on non-local type *C.struct_libusb_ss_endpoint_companion_descriptor
    usb/lowlevel/libusb/libusb.go:639:10: cannot define new methods on non-local type *C.struct_libusb_bos_dev_capability_descriptor
    usb/lowlevel/libusb/libusb.go:662:10: cannot define new methods on non-local type *C.struct_libusb_bos_descriptor
    usb/lowlevel/libusb/libusb.go:694:10: cannot define new methods on non-local type *C.struct_libusb_usb_2_0_extension_descriptor
    usb/lowlevel/libusb/libusb.go:721:10: cannot define new methods on non-local type *C.struct_libusb_ss_usb_device_capability_descriptor
    usb/lowlevel/libusb/libusb.go:749:10: cannot define new methods on non-local type *C.struct_libusb_container_id_descriptor
    usb/lowlevel/libusb/libusb.go:796:10: cannot define new methods on non-local type *C.struct_libusb_device_descriptor
    usb/lowlevel/libusb/libusb.go:866:10: cannot define new methods on non-local type *C.struct_libusb_transfer
    usb/lowlevel/libusb/libusb.go:895:10: cannot define new methods on non-local type *C.struct_libusb_version
  2. The current build process used go get outside of the go module directory. However, go get is no longer supported outside a module.

Solution:

  1. Fix the golang image version to 1.18 to ensure that the image can be successfully built. This is the same version that is used in the repository's GitHub workflow.
  2. Instead of using go get to get the source code in the image, the whole repository is copied to the image. Previously, only the run script was copied to the image.
sime commented 10 months ago

Hey @nekoteoj thanks for the contribution.

Does this PR resolve #297 ?

nekoteoj commented 10 months ago

Hey! Thanks for reviewing!

I think the error when building the docker image is the same as #297 due to golang 1.21. This PR doesn't resolve #297 since I only edited the Dockerfile. This PR changed the golang image version to 1.18 so the docker image could still be built (I think this is more like a workaround for building the image while we still cannot build the repo using golang 1.21). I also edit the build script in the Dockerfile since go get cannot run outside of go module directory now.

Also, the compiled trezord-go executable from the docker image run fine on my host os (Void Linux). So I think this can be used as an alternative build method for system with golang version >= 1.21 too.

nekoteoj commented 10 months ago

Yes, and the other reason is that I saw the github workflow used go 1.18 in check-go-validation.yml.