Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile (for Umbrel) #22

Merged
merged 1 commit into from
Nov 13, 2022
Merged

Add Dockerfile (for Umbrel) #22

merged 1 commit into from
Nov 13, 2022

Conversation

nickfarrow
Copy link
Collaborator

@nickfarrow nickfarrow commented Oct 16, 2022

Resolves #4

@DanGould
Copy link
Contributor

Umbrel requires images to be built from debian:buster-slim. Is alpine a subset of that image?

@nickfarrow nickfarrow force-pushed the docker branch 2 times, most recently from 93dd3b8 to 96025a7 Compare October 16, 2022 14:42
@nickfarrow
Copy link
Collaborator Author

Ill try switch it over, hopefully builds!

@nickfarrow nickfarrow force-pushed the docker branch 3 times, most recently from 1cf649d to 2c17b73 Compare October 24, 2022 11:51
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
@nickfarrow nickfarrow force-pushed the docker branch 3 times, most recently from 4e41105 to 5d2b4b6 Compare October 27, 2022 06:14
run_loin Outdated Show resolved Hide resolved
@DanGould
Copy link
Contributor

DanGould commented Nov 6, 2022

Why is this a draft? Aren't d51af09 and 44a6d80 in the release?

@nickfarrow
Copy link
Collaborator Author

nickfarrow commented Nov 7, 2022

Yep, built upon those and also #49. Let's get that merged. There's also a hardcoded local endpoint (here 0.0.0.0), so needs #53

@nickfarrow nickfarrow marked this pull request as ready for review November 7, 2022 00:44
@nickfarrow nickfarrow marked this pull request as draft November 7, 2022 00:45
@nickfarrow nickfarrow force-pushed the docker branch 2 times, most recently from f903e4b to 3d4dad6 Compare November 8, 2022 09:54
@DanGould
Copy link
Contributor

DanGould commented Nov 8, 2022

The prereq PRs are both merged. looks like we're ready to roll a 0.1.1 when this is in!

@nickfarrow nickfarrow marked this pull request as ready for review November 8, 2022 16:15
@DanGould
Copy link
Contributor

DanGould commented Nov 9, 2022

@0xBEEFCAF3 could you check this on Umbrel?

@0xBEEFCAF3
Copy link
Contributor

@0xBEEFCAF3 could you check this on Umbrel?

Yes I can do this today

@0xBEEFCAF3
Copy link
Contributor

Build failed
Std err logs:

error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/usr/src/nolooking/target/release/build/ring-05beccad6314eebf/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-musl")
  HOST = Some("aarch64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-musl
  CC_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_musl
  CC_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-musl
  CFLAGS_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_musl
  CFLAGS_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,llvm14-builtins-abi,sse,sse2")

  --- stderr
  running "musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitia
lized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/usr/src/nolooking/target/x86_64-unknown-linux-musl/release/build/ring-5921cfd37d58aa5a/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  cc1: error: unrecognized command line option '-m64'
  thread 'main' panicked at 'execution failed', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  stack backtrace:
     0: std::panicking::begin_panic
     1: build_script_build::run_command
     2: build_script_build::compile
     3: build_script_build::build_library::{{closure}}
     4: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
     5: core::option::Option<T>::map
     6: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next
     7: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
     8: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
     9: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
    10: core::iter::traits::iterator::Iterator::collect
    11: build_script_build::build_library
    12: build_script_build::build_c_code::{{closure}}
    13: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::for_each
    14: build_script_build::build_c_code
    15: build_script_build::ring_build_rs_main
    16: build_script_build::main
    17: core::ops::function::FnOnce::call_once
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `nolooking v0.1.0 (/usr/src/nolooking)`, intermediate artifacts can be found at `/usr/src/nolooking/target`
The command '/bin/sh -c cargo install --target x86_64-unknown-linux-musl --path .' returned a non-zero code: 101

@DanGould
Copy link
Contributor

DanGould commented Nov 10, 2022

@0xBEEFCAF3 that looks like a cargo error to me. I was able to build on my machine, but I just can't deploy it on an umbrel.

@nickfarrow what do you think is the best test for "passing" changes to this script into master in the future? I'd like to build a container for armv7 in this Dockerfile in the future, too

@nickfarrow
Copy link
Collaborator Author

What machine are you trying to build on? Mine is building from x86 with commands:

sudo docker run --privileged --rm tonistiigi/binfmt --install arm64,riscv64,arm

then

sudo docker buildx build --platform linux/arm64,linux/amd64 --tag satsale/nolooking:IMGNUMBER --output type=registry .

Maybe those will help?

@nickfarrow
Copy link
Collaborator Author

@0xBEEFCAF3 that looks like a cargo error to me. I was able to build on my machine, but I just can't deploy it on an umbrel.

@nickfarrow what do you think is the best test for "passing" changes to this script into master in the future? I'd like to build a container for armv7 in this Dockerfile in the future, too

Would github CI let you do a docker build? My guess is it would never finish arm image since I can barely build it on my 16g ram laptop

@DanGould
Copy link
Contributor

@nickfarrow I was doing it wrong. I just ran

docker buildx create --name umbrel
docker buildx use umbrel
docker buildx inspect --bootstrap

to get the builder. before I checked the logs and had only built the x86_64 version. I will put what's building now on dockerhub and then @0xBEEFCAF3 can run it from there as a smoke test

@DanGould
Copy link
Contributor

 => [linux/arm64 branch-version-arm64 3/4] RUN rustup target add aarch64-unknown-linux-musl                                                                          34.8s
 => ERROR [linux/arm64 branch-version-arm64 4/4] RUN cargo install --target aarch64-unknown-linux-musl --path .                                                     188.1s
------
 > [linux/arm64 branch-version-arm64 4/4] RUN cargo install --target aarch64-unknown-linux-musl --path .:
#0 4.471   Installing nolooking v0.1.0 (/usr/src/nolooking)
#0 19.38     Updating crates.io index
#0 187.7 Killed
------
Dockerfile:43
--------------------
  41 |     ENV AR_aarch64_unknown_linux_musl=llvm-ar
  42 |     ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"
  43 | >>> RUN cargo install --target aarch64-unknown-linux-musl --path .
  44 |     
  45 |     # We build for either x86_64 or ARM from above options using the docker $TARGETARCH
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo install --target aarch64-unknown-linux-musl --path ." did not complete successfully: exit code: 137

@nickfarrow
Copy link
Collaborator Author

Are you sure you ran the --install arm64 command? Either that or out of ram

@DanGould
Copy link
Contributor

DanGould commented Nov 10, 2022

yes I --install arm64

also 16gb ram machine. edit: maybe I can add swap space

@DanGould
Copy link
Contributor

still runs out of ram 🤔 why does it need so much
image

@nickfarrow
Copy link
Collaborator Author

I was thinking that this arm build just requires a lot of memory to produce (all the statically linked dependencies), but maybe there is something else going wrong?

Using shared local dependencies outside of docker may help, but i haven't tried yet
https://stackoverflow.com/questions/54952867/cache-cargo-dependencies-in-a-docker-volume

@DanGould
Copy link
Contributor

DanGould commented Nov 11, 2022

Finally got it built and on the chaincase dockerhub

Apparently there is a big memory leak in libgit2, a c library cargo depends on. Rust can still leak memory if it depends on c code 🤣 By passing --config "net.git-fetch-with-cli=true" to cargo install I was able to compile on aarch64. It took almost an hour. Big thanks to @asottile-sentry for finding the bug and making a video on it.

source of the memory leak: rust-lang/cargo#9167

Dockerfile Outdated Show resolved Hide resolved
Conditionally `cargo build` for platforms of x86_64 or ARM.
In the final Docker stage we copy the built binary to alpine,
and use a run_nolooking script to start nolooking with
the environment:
 - $LND_HOST, $LND_GRPC_PORT, $TLS_FILE, $MACAROON_FILE"
 - Binds to 0.0.0.0:4444 (exposed within docker)

Resolves payjoin#4
@DanGould DanGould merged commit ec4042c into payjoin:master Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Umbrel App
3 participants