cross icon indicating copy to clipboard operation
cross copied to clipboard

Port Forwarding / Accessing a host port during build

Open D1plo1d opened this issue 5 years ago • 4 comments

I am using sqlx which requires a connection to my local postgres db at build time. Is it possible to port forward postgres into the cross container or alternatively is there an environment variable to get the IP address of the host from the container?

Related: conversation about removing this build-time network dependency in sqlx: https://github.com/launchbadge/sqlx/issues/60#issuecomment-586634589

D1plo1d avatar Feb 15 '20 19:02 D1plo1d

I faced the same issue. In the meantime there's no fix for this, i figured a workaround using a couple docker containers.

This one to emulate an architecture with qemu, allowing to run containers meant for different architectures, like this one with the same arch as the Raspberry PI 2/3

(you may need to setup a docker network to access the sql server, but it depends on your setup)

You can then run the container, install rust and whatever dependencies you may need, and just use cargo build like normal to compile the application.

Using this method takes way longer to compile the application, but that's expected given it's emulating an architecture.

vicky5124 avatar Apr 15 '20 09:04 vicky5124

That is very interesting. I'll look into these. Docker buildx might be another potential avenue to achieve a very similar result. I would love to see a docker-inside-qemu solution like this baked into cross some day.

D1plo1d avatar Apr 15 '20 16:04 D1plo1d

We now pre-ship containers with cross installed, such as ghcr.io/cross-rs/cross:main. This might make it a bit simpler. I'll see if I can get port forwarding to work, however.

Alexhuszagh avatar Jul 15 '22 18:07 Alexhuszagh

using CROSS_CONTAINER_OPTS="--network host" should solve this without needing dind

sqlx also has support for offline building via offline feature flag

Emilgardis avatar Jul 16 '22 00:07 Emilgardis