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

chore: magma deb build is bazelified #13749

Merged
merged 14 commits into from
Sep 14, 2022
Merged

Conversation

nstng
Copy link
Contributor

@nstng nstng commented Aug 26, 2022

Summary

This change introduces a first throw for a magma debian build with bazel.

  • this approach tries to be as near as possible to the make build - but there are differences
    • especially, the services are not packaged hermetically, i.e., common dependencies are only packaged once
  • far less dependencies are needed because bazel builds as hermetic as possible

known issues

  • the resulting package is very large (~900mb) and with --config=production even larger
  • there is some debug logging (basically warnings) during a build because files are overridden during packaging - these should only be generated proto files that are used by different services

Test Plan

  • build magma debian package on VM [edit] or bazelBase/devcontainer (the bazelBase/devcontainer sessiond services is currently not compatible with magma_deb)
  • copy the artifact to an accessible place[edit]: ~/magma$ cp bazel-bin/lte/gateway/release/magma_1.8.0_amd64.deb .
  • in lte/gateway/deploy/roles/magma_deploy/tasks/main.yml modify "Installing magma."
    • # name: "{{ packages }}"
    • add deb: "/home/vagrant/magma/magma_1.8.0_amd64.deb"
  • run ~/magma/lte/gateway$ vagrant up magma_deb
  • check magma_deb for issues, services running, logging, ...
  • integration tests can be run vs magma_deb

Additional Information

  • This change is backwards-breaking

@nstng nstng requested a review from a team August 26, 2022 11:03
@nstng nstng requested a review from a team as a code owner August 26, 2022 11:03
@nstng nstng requested review from LKreutzer and ajahl August 26, 2022 11:03
@pull-request-size pull-request-size bot added the size/XXL Denotes a Pull Request that changes 1000+ lines. label Aug 26, 2022
@nstng nstng changed the title Bazelify magma deb build chore: magma deb build is bazelified Aug 26, 2022
@github-actions
Copy link
Contributor

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions github-actions bot added component: agw Access gateway-related issue component: ci All updates on CI (Jenkins/CircleCi/Github Action) component: feg FEG-gateway related issues component: orc8r Orchestrator-related issue labels Aug 26, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

feg-workflow

    2 files  203 suites   40s ⏱️
374 tests 374 ✔️ 0 💤 0
388 runs  388 ✔️ 0 💤 0

Results for commit d500c9d.

♻️ This comment has been updated with latest results.

@nstng nstng linked an issue Aug 26, 2022 that may be closed by this pull request
3 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

dp-workflow

14 tests   14 ✔️  3m 7s ⏱️
  1 suites    0 💤
  1 files      0

Results for commit d500c9d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

cloud-workflow

1 129 tests   1 129 ✔️  2m 12s ⏱️
   368 suites         0 💤
       7 files           0

Results for commit d500c9d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

agw-workflow

615 tests   611 ✔️  4m 30s ⏱️
    2 suites      4 💤
    2 files        0

Results for commit d500c9d.

♻️ This comment has been updated with latest results.

@sebathomas
Copy link
Contributor

I just tried a build on my VM and I can't see the sctpd package described in the test plan.

vagrant@magma-dev:~/magma/bazel-bin/lte/gateway/release$ ls
magma_1.8.0_amd64.changes  magma_1.8.0_amd64.deb  magma_1.8.0_amd64.tar  magma_content.manifest  magma_deb_pkg.deb

@nstng
Copy link
Contributor Author

nstng commented Aug 29, 2022

I just tried a build on my VM and I can't see the sctpd package described in the test plan.

vagrant@magma-dev:~/magma/bazel-bin/lte/gateway/release$ ls
magma_1.8.0_amd64.changes  magma_1.8.0_amd64.deb  magma_1.8.0_amd64.tar  magma_content.manifest  magma_deb_pkg.deb

woops, c&p issue ... corrected in test plan.

@sebathomas
Copy link
Contributor

"far less dependencies are needed because bazel builds as hermetic as possible" - I noticed that the list is a lot smaller than in the latest release from focal-ci. So the reason is that pydep adds many more dependencies than needed?

@nstng
Copy link
Contributor Author

nstng commented Aug 29, 2022

"far less dependencies are needed because bazel builds as hermetic as possible" - I noticed that the list is a lot smaller than in the latest release from focal-ci. So the reason is that pydep adds many more dependencies than needed?

Almost all python3-foo dependencies are not needed anymore. But iirc a make built magma.deb has all python3-foo dependencies twice (i.e., the list feels a lot longer). I do not know if pydep adds unnecessary dependencies.

@sebathomas
Copy link
Contributor

From looking at the built magma.deb, the main difference in file size is because of the C++ services (mme, sessiond...). Is this because Bazel compiles all dependencies into the file or is there something else going on?

Copy link
Contributor

@sebathomas sebathomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing...

"../com_google_protobuf",
# external grpc is only needed during compile time
"../com_github_grpc_grpc",
"_solib_k8/libexternal_Scom_Ugithub_Ugrpc_Ugrpc_Slibgrpc.so",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment here too (whatever that thing is :)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will. The long description for the record: this is how bazel compiles dynamic libraries - separators like / and . are encoded -> libexternal/com.github.grpc.grpc/libgrpc.so. But it's still a library that is only needed during compile time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

"ebpf/byte_count.bpf.c",
"ebpf/common.bpf.h",
],
data = ["//lte/gateway/python/magma/kernsnoopd/ebpf:ebpf_data_files"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These might be duplicated somehow. I see them both in

└── var
    ├── opt
    │   └── magma
    │       ├── ebpf
    │       │   ├── ebpf_dl_handler.c
    │       │   ├── ebpf_manager.py
    │       │   ├── ebpf_ul_handler.c
    │       │   └── kernsnoopd
    │       │       ├── byte_count.bpf.c
    │       │       └── common.bpf.h
    │       └── envoy.yaml

and usr/local/lib/python3.8

│       │           │   ├── kernsnoopd
│       │           │   │   ├── ebpf
│       │           │   │   │   ├── byte_count.bpf.c
│       │           │   │   │   └── common.bpf.h
│       │           │   │   ├── handlers.py
│       │           │   │   ├── kernsnoopd
│       │           │   │   ├── main.py
│       │           │   │   ├── metrics.py
│       │           │   │   └── snooper.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch - seems like this is inconsistent to the make magma.deb file. I will have a look ...

nils@nilstng:~/Downloads$ dpkg -c magma_1.8.0-1661850050-5221f975_amd64.deb | grep "var/opt/magma/ebpf"
drwxr-xr-x 0/0               0 2022-08-30 11:05 ./var/opt/magma/ebpf/
-rw-r--r-- 0/0            3235 2022-08-30 09:09 ./var/opt/magma/ebpf/ebpf_ul_handler.c
drwxr-xr-x 0/0               0 2022-08-30 11:05 ./var/opt/magma/ebpf/kernsnoopd/
-rw-r--r-- 0/0            2336 2022-08-30 09:09 ./var/opt/magma/ebpf/kernsnoopd/byte_count.bpf.c
-rw-r--r-- 0/0            1042 2022-08-30 09:09 ./var/opt/magma/ebpf/kernsnoopd/common.bpf.h
-rw-r--r-- 0/0            2730 2022-08-30 09:09 ./var/opt/magma/ebpf/ebpf_dl_handler.c
-rw-r--r-- 0/0             991 2022-08-30 09:09 ./var/opt/magma/ebpf/BUILD.bazel
-rw-r--r-- 0/0           12416 2022-08-30 09:09 ./var/opt/magma/ebpf/ebpf_manager.py
nils@nilstng:~/Downloads$ dpkg -c magma_1.8.0-1661850050-5221f975_amd64.deb | grep "usr/local/lib/python3.8/dist-packages/magma/kernsnoopd"
drwxrwxr-x 0/0               0 2022-08-30 11:05 ./usr/local/lib/python3.8/dist-packages/magma/kernsnoopd/
-rw-r--r-- 0/0            1465 2022-08-30 09:09 ./usr/local/lib/python3.8/dist-packages/magma/kernsnoopd/main.py
-rw-r--r-- 0/0             853 2022-08-30 09:09 ./usr/local/lib/python3.8/dist-packages/magma/kernsnoopd/metrics.py
-rw-r--r-- 0/0            7578 2022-08-30 09:09 ./usr/local/lib/python3.8/dist-packages/magma/kernsnoopd/handlers.py
-rw-r--r-- 0/0             476 2022-08-30 09:09 ./usr/local/lib/python3.8/dist-packages/magma/kernsnoopd/__init__.py
-rw-r--r-- 0/0            4271 2022-08-30 09:09 ./usr/local/lib/python3.8/dist-packages/magma/kernsnoopd/snooper.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

# lte/protos/target_name/lte/protos/foo_pb2.py -> lte/protos/foo_pb2.py
return path.replace(prefix, "", 1).replace(file.owner.name + "/", "", 1)

print("Unhandle path: " + path) # buildifier: disable=print
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
print("Unhandle path: " + path) # buildifier: disable=print
print("Unhandled path: " + path) # buildifier: disable=print

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

# Contributed to https://github.com/aspect-build/rules_container under Apache-2.0

"""
This file represents a workaround for the current state of https://github.com/bazelbuild/rules_pkg.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it not be necessary any more in future versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would hope so ... there are a couple of open upstream issues where this topic is discussed (iirc some are open for several years).

Copy link
Contributor Author

@nstng nstng Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one argument is that python files should be pre-package, e.g., into a zip and then package the zip files. Problem here is that we have redundancy in our services. E.g., proto files (small) but also pip dependencies (and these sum up). This approach results in very large magma.debs (>2gb) ans also has other disadvantages during runtime (the zips are unpacked in a tmp folder - each time the service restarts).

Copy link
Contributor

@LKreutzer LKreutzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the tests

  • //lte/gateway/python/integ_tests/s1aptests:test_attach_service_with_multi_pdns_and_bearers_mt_data
  • //lte/gateway/python/integ_tests/s1aptests:test_attach_dl_udp_data

keep failing with an assertion error, can you reproduce this?

Unfortunately the standard query for deps, e.g. bazel query 'filter("(^[^@])", filter("^(?!.*external)", deps(//lte/gateway/release:magma_deb_pkg)))' --output graph | dot -Tsvg > magma_deb.svg does not work here. Is there a way to query the bazel structure of the package?

lte/gateway/release/magma-postinst-bazel Show resolved Hide resolved
bazel/runfiles.bzl Show resolved Hide resolved
lte/gateway/release/magma-postinst-bazel Outdated Show resolved Hide resolved
lte/gateway/release/BUILD.bazel Show resolved Hide resolved
@nstng
Copy link
Contributor Author

nstng commented Sep 5, 2022

Unfortunately the standard query for deps, e.g. bazel query 'filter("(^[^@])", filter("^(?!.*external)", deps(//lte/gateway/release:magma_deb_pkg)))' --output graph | dot -Tsvg > magma_deb.svg does not work here. Is there a way to query the bazel structure of the package?

@LKreutzer it works for me (it's just very very large and the resulting graph might not be a good visual aid) - what issue do you encounter?

@nstng
Copy link
Contributor Author

nstng commented Sep 5, 2022

For me the tests
* //lte/gateway/python/integ_tests/s1aptests:test_attach_service_with_multi_pdns_and_bearers_mt_data
* //lte/gateway/python/integ_tests/s1aptests:test_attach_dl_udp_data
keep failing with an assertion error, can you reproduce this?

@LKreutzer they were really unstable for me too - after restarting the trf server several times they became stable ¯\_(ツ)_/¯

SUMMARY: 2/2 tests were successful.
  //lte/gateway/python/integ_tests/s1aptests:test_attach_service_with_multi_pdns_and_bearers_mt_data: PASSED
  //lte/gateway/python/integ_tests/s1aptests:test_attach_dl_udp_data: PASSED

@github-actions github-actions bot removed the component: orc8r Orchestrator-related issue label Sep 7, 2022
@nstng
Copy link
Contributor Author

nstng commented Sep 7, 2022

From looking at the built magma.deb, the main difference in file size is because of the C++ services (mme, sessiond...). Is this because Bazel compiles all dependencies into the file or is there something else going on?

@sebathomas by the last commit the size of the debian package was decreased from 930mb to 390mb. This was possible because before we added debug symbols not only to the magma binaries, but also to the external dependencies. we might want to do further analysis if the size can be optimized, but I suggest to do this as follow-up tasks.

.bazelrc Show resolved Hide resolved
@nstng
Copy link
Contributor Author

nstng commented Sep 7, 2022

precommit tests on latest artifact:

vagrant@magma-test:~/magma$ ./bazel/scripts/run_integ_tests.sh --precommit
SUMMARY: 115/117 tests were successful.
  //lte/gateway/python/integ_tests/s1aptests:test_attach_ul_udp_data_with_mobilityd_restart: FAILED
  //lte/gateway/python/integ_tests/s1aptests:test_attach_detach_attach_dl_tcp_data: FAILED

vagrant@magma-test:~/magma$ ./bazel/scripts/run_integ_tests.sh --rerun-previously-failed
SUMMARY: 1/2 tests were successful.
  //lte/gateway/python/integ_tests/s1aptests:test_attach_ul_udp_data_with_mobilityd_restart: FAILED

vagrant@magma-test:~/magma$ ./bazel/scripts/run_integ_tests.sh --rerun-previously-failed
SUMMARY: 1/1 tests were successful.

Copy link
Contributor

@LKreutzer LKreutzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

Bazel rule tests are working too
Screenshot from 2022-09-08 08-39-34

pkg_mklink(
name = "pipelined_symlink",
link_name = "/etc/magma/pipelined.yml",
target = "/etc/magma/pipelined.yml_prod",
Copy link
Contributor

@jheidbrink jheidbrink Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just store pipelined.yml_prod at /etc/magma/pipelined.yml instead of symlinking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be possible, yes - for now this is the behavior of the make created .deb.
I can only speculate: I assume the reason is/was, to have a convenient way to switch between prod and test setups.

.bazelrc Show resolved Hide resolved
@sebathomas
Copy link
Contributor

From looking at the built magma.deb, the main difference in file size is because of the C++ services (mme, sessiond...). Is this because Bazel compiles all dependencies into the file or is there something else going on?

@sebathomas by the last commit the size of the debian package was decreased from 930mb to 390mb. This was possible because before we added debug symbols not only to the magma binaries, but also to the external dependencies. we might want to do further analysis if the size can be optimized, but I suggest to do this as follow-up tasks.

Wow, that makes huge difference. Good catch!

Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
…ifacts is decreased)

Signed-off-by: Nils Semmelrock <nils.semmelrock@tngtech.com>
@nstng nstng merged commit 935783d into magma:master Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: agw Access gateway-related issue component: ci All updates on CI (Jenkins/CircleCi/Github Action) component: feg FEG-gateway related issues size/XXL Denotes a Pull Request that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

magma.deb is bazelified
4 participants