Skip to content

Earthly #672

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

Merged
merged 18 commits into from
Nov 29, 2023
Merged

Earthly #672

merged 18 commits into from
Nov 29, 2023

Conversation

joepio
Copy link
Member

@joepio joepio commented Oct 2, 2023

Thanks to @AlexMikhalev

TODO:

  • Get earthly JS build working
  • Get earthly Rust build working
  • pnpm proper caching
  • rust proper caching (only when code changes)
  • e2e tests
  • Replace github action steps with Earthly
  • Improve the developer experience for debugging CI fails - Github actions are far more granular, and the logs for earthly aren't great
  • Set up CI artifacts correctly. I have added --artifact but haven't yet verified if they work. No files were found with the provided path: ./test-results/. No artifacts will be uploaded.
  • Make sure the right satellites are used. Right now it looks like it's not using any cache at all. However, I do have an `EARTHLY
  • +test is not caching compilation step for some reason
  • Docker image should work on m1
  • Vitest should work
  • Set the right tags for publishing docker image
  • Docker push with auth

PR Checklist:

  • Link to related issues: Improve devops #576, replaces Earthly ci #671
  • Add changelog entry linking to issue, describe API changes
  • Add tests (optional)
  • (If new feature) add to description / readme

@joepio
Copy link
Member Author

joepio commented Oct 2, 2023

Got a few steps further! @AlexMikhalev

However, now I'm failing to build ring:

+build *failed* |    Compiling tokio v1.22.0
              +build *failed* | error: failed to run custom build command for `ring v0.16.20`

              +build *failed* | Caused by:
              +build *failed* |   process didn't exit successfully: `/app/target/release/build/ring-e93c24c67f562946/build-script-build` (exit status: 101)
              +build *failed* |   --- stdout
              +build *failed* |   OPT_LEVEL = Some("3")
              +build *failed* |   TARGET = Some("x86_64-unknown-linux-musl")
              +build *failed* |   HOST = Some("aarch64-unknown-linux-gnu")
              +build *failed* |   CC_x86_64-unknown-linux-musl = None
              +build *failed* |   CC_x86_64_unknown_linux_musl = None
              +build *failed* |   TARGET_CC = None
              +build *failed* |   CC = None
              +build *failed* |   CROSS_COMPILE = None
              +build *failed* |   CFLAGS_x86_64-unknown-linux-musl = None
              +build *failed* |   CFLAGS_x86_64_unknown_linux_musl = None
              +build *failed* |   TARGET_CFLAGS = None
              +build *failed* |   CFLAGS = None
              +build *failed* |   CRATE_CC_NO_DEFAULTS = None
              +build *failed* |   DEBUG = Some("false")
              +build *failed* |   CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

              +build *failed* |   --- stderr
              +build *failed* |   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" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/app/target/x86_64-unknown-linux-musl/release/build/ring-c180cf10afb91cb7/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
              +build *failed* |   cc1: error: unrecognized command-line option '-m64'
              +build *failed* |   thread 'main' panicked at 'execution failed', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.16.20/build.rs:656:9
              +build *failed* |   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
              +build *failed* | warning: build failed, waiting for other jobs to finish...
              +build *failed* | ERROR Earthfile line 35:2
              +build *failed* |       The command
              +build *failed* |           RUN cargo build --release --bin atomic-server --config net.git-fetch-with-cli=true --target x86_64-unknown-linux-musl
              +build *failed* |       did not complete successfully. Exit code 101
View logs at https://cloud.earthly.dev/builds/84a1171a-85e5-4dc8-9b9b-8d4e567753d1
Error(s) in logbus: 1 error occurred:
	* log streamer: 1 error occurred:
	* failed waiting for log stream server: rpc error: code = Internal desc = internal error

@joepio joepio mentioned this pull request Oct 2, 2023
@joepio joepio self-assigned this Oct 2, 2023
@AlexMikhalev
Copy link
Collaborator

Actually, works on my machine, linux amd64. Your host dependant rust:latest aarch64 doesn't have libssl dependencies - instant-acme and rcgen depend on rand with native openssl, while tokio uses rustls.
Try adding
RUN apt update && apt install -y librust-openssl-dev libssl-dev from this article
The best approach to manage combination of features between native and rustls I found here may be worth cherry picking what we can from there.

Error:
Error(s) in logbus: 1 error occurred:
* log streamer: 1 error occurred:
* failed waiting for log stream server: rpc error: code = Internal desc = internal error

Will go away as soon as you create a project earthly project create atomic-server. Then you can invite @Polleps and myself (on as needed basis) into the project and we share deployment secrets and satellite.

@joepio
Copy link
Member Author

joepio commented Oct 3, 2023

True! It works just fine in the CI :)

@AlexMikhalev
Copy link
Collaborator

The original ticket from Feb has a better example of cross-compilation than my commit. Funny.

@joepio
Copy link
Member Author

joepio commented Oct 3, 2023

pnpm is now working including proper caching.

Now I want Rust to be properly cached. It keeps re-compiling everything.

deps:
  COPY --dir server lib cli desktop Cargo.lock Cargo.toml .
  RUN cargo fetch

I'd expect a cache hit if no files are changed (seems properly working now) but also if the code changes but not the Cargo.lock.

We should only copy the Cargo.toml files maybe? Not sure.

@joepio
Copy link
Member Author

joepio commented Oct 3, 2023

I want to test the atomic-server docker image, instead of the compiled binary. However, I'm not quite sure how. There's a catch-22:

  • I can only run docker images performantly using the "earthly/dind" images.
  • If I want to run playwright, I need to install playwright, which requires node + pnpm, which kind of requires a pre-built image with node.

Another approach is to use the docker image of playwright, which has node built in. But it seems very inception, because now I have to pass the tests into the docker environment somehow.

e2e:
  FROM earthly/dind:alpine
  # https://docs.earthly.dev/best-practices#use-earthly-dind
  COPY browser/data-browser/e2e /e2e
  WITH DOCKER \
    --load test:latest=+docker \
    --pull mcr.microsoft.com/playwright:v1.38.0-jammy
    RUN docker run test:latest && \
    docker run mcr.microsoft.com/playwright:v1.38.0-jammy
  END

@joepio joepio mentioned this pull request Oct 8, 2023
@joepio joepio force-pushed the earthly branch 2 times, most recently from f512c90 to 9e9fc9c Compare November 13, 2023 16:12
@joepio
Copy link
Member Author

joepio commented Nov 14, 2023

Things are mostly working now.

Some TODO's / challenges (UPDATED OP)

  • Set the right tags for publishing docker image
  • Improve the developer experience for debugging CI fails - Github actions are far more granular, and the logs for earthly aren't great
  • Set up CI artifacts correctly

@joepio
Copy link
Member Author

joepio commented Nov 15, 2023

no space left on device while running +test (CI)

Hmm... I think this is because we do both a release build and a dev build (for test), which are both a couple of gigs.

@joepio
Copy link
Member Author

joepio commented Nov 20, 2023

       +build-server *failed* | error: internal compiler error: no errors encountered even though `delay_span_bug` issued

       +build-server *failed* | error: internal compiler error: broken MIR in Item(DefId(0:7908 ~ tantivy[4f46]::store::reader::{impl#3}::iter_raw::{closure#2})) (after phase change to runtime-optimized) at bb2[6]:
       +build-server *failed* |                                 Alias(Opaque, AliasTy { args: [ReErased], def_id: DefId(0:18092 ~ tantivy[4f46]::store::reader::{impl#3}::block_checkpoints::{opaque#0}) }) does not have fields
       +build-server *failed* |  --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/adapters/flatten.rs:52:9
       +build-server *failed* |   |
       +build-server *failed* | note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:94:25
       +build-server *failed* |          0: <rustc_errors::HandlerInner>::emit_diagnostic
       +build-server *failed* |          1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
       +build-server *failed* |          2: <rustc_const_eval::transform::validate::CfgChecker>::fail::<alloc::string::String>
       +build-server *failed* |          3: <rustc_const_eval::transform::validate::Validator as rustc_middle::mir::MirPass>::run_pass
       +build-server *failed* |          4: rustc_mir_transform::pass_manager::run_passes
       +build-server *failed* |          5: rustc_mir_transform::optimized_mir
       +build-server *failed* |          6: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
       +build-server *failed* |          7: <rustc_query_impl::query_impl::optimized_mir::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
       +build-server *failed* |          8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
       +build-server *failed* |          9: rustc_query_impl::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
       +build-server *failed* |         10: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
       +build-server *failed* |         11: rustc_metadata::rmeta::encoder::encode_metadata_impl
       +build-server *failed* |         12: rustc_data_structures::sync::parallel::disabled::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, (), ()>
       +build-server *failed* |         13: rustc_metadata::rmeta::encoder::encode_metadata
       +build-server *failed* |         14: rustc_metadata::fs::encode_and_write_metadata
       +build-server *failed* |         15: rustc_interface::passes::start_codegen
       +build-server *failed* |         16: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
       +build-server *failed* |         17: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
       +build-server *failed* |         18: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
       +build-server *failed* |         19: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
       +build-server *failed* |         20: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
       +build-server *failed* |                    at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/boxed.rs:2007:9
       +build-server *failed* |         21: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
       +build-server *failed* |                    at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/boxed.rs:2007:9
       +build-server *failed* |         22: std::sys::unix::thread::Thread::new::thread_start
       +build-server *failed* |                    at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys/unix/thread.rs:108:17
       +build-server *failed* |         23: <unknown>
       +build-server *failed* |         24: clone
       +build-server *failed* |  --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/adapters/flatten.rs:52:9

       +build-server *failed* | note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

       +build-server *failed* | note: rustc 1.74.0 (79e9716c9 2023-11-13) running on x86_64-unknown-linux-gnu

       +build-server *failed* | note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no

       +build-server *failed* | note: some of the compiler flags provided by cargo are hidden

       +build-server *failed* | query stack during panic:
       +build-server *failed* | end of query stack
       +build-server *failed* | error: could not compile `tantivy` (lib)
       +build-server *failed* | thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-chef-0.1.62/src/recipe.rs:204:27:
       +build-server *failed* | Exited with status code: 101
       +build-server *failed* | note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       +build-server *failed* | ERROR Earthfile line 36:2
       +build-server *failed* |       The command
       +build-server *failed* |           RUN cargo chef cook --release --recipe-path recipe.json --bin atomic-server --target x86_64-unknown-linux-musl
       +build-server *failed* |       did not complete successfully. Exit code 101```

@joepio
Copy link
Member Author

joepio commented Nov 20, 2023

Can't build on mac unfortunately:

       +build-server *failed* |   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" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/app/target/x86_64-unknown-linux-musl/release/build/ring-1b1a12a6cc58949e/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
       +build-server *failed* |   cc1: error: unrecognized command-line option '-m64'
       +build-server *failed* |   thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.16.20/build.rs:656:9:

Tried this:

  ENV RUSTFLAGS='-C linker=x86_64-linux-gnu-gcc'

But does not seem to help

@joepio joepio force-pushed the earthly branch 2 times, most recently from 2bb2072 to 238b667 Compare November 21, 2023 11:31
@joepio
Copy link
Member Author

joepio commented Nov 21, 2023

Earhtly failing to save directory:

earthly debugger | failed to save /app/data-browser/test-results: read /app/data-browser/test-results: is a directory

https://github.com/atomicdata-dev/atomic-server/actions/runs/6943171794/job/18887664712#step:6:7587

EDIT: probably this: earthly/earthly#2817

@joepio joepio force-pushed the earthly branch 2 times, most recently from d786362 to 9ea7747 Compare November 22, 2023 13:13
@joepio joepio mentioned this pull request Nov 27, 2023
4 tasks
#576 push to atomicdata

#576 Fix earthly pnpm

#576 get e2e tests in earthly working
Fix clippy

Less flaky test

#576 Fix earthly


WIP earthfile

run earthly github

CI

earthly main-pipeline

Fix test

add artefacts

CI tauri

Upload artifacts

tauri deps

deps

typo

Fix test

Fix test in build

fix test

Use explicit satellite

Fix use org

Disable test

Update contribute

Fix earthly try

fix ci

fix CI earthly

Fix clippy

Lint fix

less lint fails
@joepio
Copy link
Member Author

joepio commented Nov 27, 2023

vitest fails in CI:

        browser+test *failed* | svelte test:  FAIL  src/stores/getValue.test.ts [ src/stores/getValue.test.ts ]
        browser+test *failed* | svelte test: Error: Failed to resolve entry for package "@tomic/lib". The package may have incorrect main/module/exports specified in its package.json.
        browser+test *failed* | svelte test:  ❯ packageEntryFailure ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:28126:17
        browser+test *failed* | svelte test:  ❯ resolvePackageEntry ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:28123:5
        browser+test *failed* | svelte test:  ❯ tryNodeResolve ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:27862:20
        browser+test *failed* | svelte test:  ❯ Context.resolveId ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:27618:28
        browser+test *failed* | svelte test:  ❯ Object.resolveId ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:61935:64
        browser+test *failed* | svelte test:  ❯ TransformContext.resolve ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:61640:23
        browser+test *failed* | svelte test:  ❯ normalizeUrl ../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:59995:34
        browser+test *failed* | svelte test:  ❯ async file:[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:60153:47
        browser+test *failed* | svelte test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯
        browser+test *failed* | svelte test:  Test Files  2 failed (2)
        browser+test *failed* | svelte test:       Tests  no tests
        browser+test *failed* | svelte test:    Start at  16:15:40
        browser+test *failed* | svelte test:    Duration  1.53s (transform 1ms, setup 3ms, collect 0ms, tests 0ms, environment 0ms, prepare 367ms)
        browser+test *failed* | svelte test: Failed
        browser+test *failed* | /browser/svelte:
        browser+test *failed* |  ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @tomic/[email protected] test: `vitest run`
        browser+test *failed* | Exit status 1
        browser+test *failed* |  ELIFECYCLE  Test failed. See above for more details.
        browser+test *failed* | ERROR browser/Earthfile line 25:2

@joepio
Copy link
Member Author

joepio commented Nov 28, 2023

Docker run fails on m1

docker run -p 80:80 -p 443:443 --platform linux/amd64 -v atomic-storage:/atomic-storage joepmeneer/atomic-server:latest
rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2

@joepio
Copy link
Member Author

joepio commented Nov 28, 2023

I noticed the musl build failed #619, so reverted that. But I do want a smaller image. I tried the jeanblanchard/alpine-glibc:3.17.5 image, which apparently still missed some dependencies:

             +docker | --> RUN /atomic-server-bin --version
             +docker | Error relocating /lib/ld-linux-x86-64.so.2: unsupported relocation type 37
             +docker | Error relocating /atomic-server-bin: __register_atfork: symbol not found
             +docker | Error relocating /atomic-server-bin: gnu_get_libc_version: symbol not found
             +docker | Error relocating /atomic-server-bin: __res_init: symbol not found

I can apk add gcompat and that seems to fix that, but installing gcompat does fail.

ERROR: gcompat-1.1.0-r0: trying to overwrite lib/ld-linux-x86-64.so.2 owned by glibc-2.35-r1.
Executing glibc-bin-2.35-r1.trigger
1 error; 19 MiB in 26 packages

EDIT: I ended up ignoring this error, because the resulting binary does in fact run.

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.

2 participants