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

Build development RPMs from any OS without needing Docker #4758

Merged
merged 33 commits into from
Jul 8, 2020

Conversation

zrhoffman
Copy link
Member

@zrhoffman zrhoffman commented Jun 4, 2020

What does this PR (Pull Request) do?

  • This PR lets you build the ATC RPMs, targeted for CentOS 7, from any OS without needing Docker. See the table below for time comparisons
  • This PR includes various compatibility improvements to the build scripts:
    • Makes the build scripts run in Bourne shell (sh) instead of Bash for POSIX compatibility
    • Uses realpath instead of readlink where possible
    • Eliminates Perl as a build-time dependency for the Traffic Ops RPM
  • Fixes a bug from 4cf9529 where failing the environment check did not stop the build script
  • Statically links the Go binaries, which ends up making them a little smaller (see table Binary size: Static linking vs dynamic linking)
  • Expands Traffic Portal and Traffic Router Software Requirements sections in the docs

Comparison of time taken to build each component (RPM or tar.gz, depending on the component)

docs grove grovetccfg source traffic_monitor traffic_ops traffic_portal traffic_router traffic_stats Total
Docker on macOS 02:54.01 00:53.44 00:44.94 00:43.69 00:50.65 01:11.01 01:49.90 01:44.56 00:55.07 11:47.27
Docker on Linux 02:11.94 00:15.17 00:13.53 00:06.10 00:15.39 00:24.18 01:01.34 00:49.34 00:16.31 05:33.30
Natively on macOS 01:53.61 00:03.38 00:03.97 00:04.36 00:04.93 00:10.40 00:45.23 00:33.98 00:07.98 03:47.84
Natively on Linux 01:14.69 00:02.68 00:03.18 00:02.91 00:03.37 00:07.65 00:27.99 00:18.32 00:06.12 02:26.9

Some comments about the time comparisons table:

  • Docker refers to ./pkg -v [component], Natively refers to build/clean_build [component]
  • For components built natively: The repo is already copied to /tmp/go/src/github.com/apache/trafficcontrol , so the rsync command in clean_build.sh to copy the repo there only affects files that have changed since the last native build.
  • Each ./pkg command bootstraps docker-compose, which takes ~1.6 seconds.
  • For components built using Docker: Because /tmp/go/src/github.com/apache/trafficcontrol is not a volume, the rsync command in clean_build.sh always copies the entire repo.
    • Running Docker on Linux, this rsync takes on average ~3.2 seconds.
    • In Docker for Mac, it takes ~34 seconds.

Binary size: Static linking vs dynamic linking

Since this PR makes the Go binaries statically linked, whereas before they were dynamically linked, I expected the binaries to be a little larger, but it ends up saving a very small amount of space instead.

grove grovetccfg traffic_monitor traffic_ops_golang atstccfg traffic_stats
Dynamic linking (KiB) 7261 9358 11189 18473 10077 9983
Static linking (KiB) 7223 9300 11127 18404 10019 9917
Space saved (KiB) 38 58 62 69 58 66

Some comments about the static vs. dynamic linking table:

  • Dynamically linked binaries were built with go build -ldflags '-s -w' and were then stripped of symbols (strip [binary name])
  • Statically linked binaries were built with go build -ldflags '-s -w' -tags 'osusergo netgo' and were then stripped of symbols (strip [binary name])

Besides being a tiny bit smaller, the static binaries will load trivially faster at runtime. However, our statically-linked Go binaries on average take about 1.2 seconds longer to build each.

Which Traffic Control components are affected by this PR?

  • Build system
  • CDN in a Box
  • Documentation

What is the best way to verify this PR?

  • Verify that the target OS of the RPMs is Linux

    rpm -qp --qf '%{os}\n' *.rpm

    Expected output:

    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
    linux
  • Verify that the RPM compression format is XZ

    rpm -qp --qf '%{payloadcompressor}\n' *.rpm

    Expected output:

    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
    xz
  • Verify that all of the packaged Go binaries are statically linked (have no dynamic section). Example for traffic_ops_golang:

    docker run --rm -v$(pwd):/mnt centos:7 readelf -d /mnt/traffic_ops_golang

    Expected output is

    
    There is no dynamic section in this file.
    
  • In the CDN-in-a-Box directory, run make to build the RPMs and verify that CiaB works

    • On docs/source/development/building.rst under Build the RPMs Natively, follow the Install the Dependencies instructions for your OS
    • In the CiaB directory, run make native to build the RPMs and verify that CiaB works
    • For ./pkg -v (Docker), verify the RPMs and gzipped TARs that CDN-in-a-Box does not use:
      - apache-trafficcontrol-4.2.0-docs.tar.gz
      - apache-trafficcontrol-4.2.0.tar.gz
      -             grove-0.2-#####.XXXXXXXX.x86_64.rpm
      -        grovetccfg-0.2-#####.XXXXXXXX.x86_64.rpm
      -     traffic_ops-4.2.0-#####.XXXXXXXX.el7.src.rpm
      - traffic_ops_ort-4.2.0-#####.XXXXXXXX.el7.src.rpm
      - traffic_ops_ort-4.2.0-#####.XXXXXXXX.el7.x86_64.rpm
      -  traffic_portal-4.2.0-#####.XXXXXXXX.el7.src.rpm
      -   traffic_stats-4.2.0-#####.XXXXXXXX.el7.src.rpm
      
    • For build/clean_build.sh (native), verify the RPMs and gzipped TARs that CDN-in-a-Box does not use

If this is a bug fix, what versions of Traffic Control are affected?

For the environment check bugfix:

For #3527:

Otherwise, not a bug fix.

The following criteria are ALL met by this PR

  • This PR does not contain tests because our CI pipeline tests the build system
  • This PR includes documentation
  • This PR includes an update to CHANGELOG.md
  • This PR includes any and all required license headers
  • This PR does not include a database migration
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

@zrhoffman
Copy link
Member Author

Rebased to fix merge conflicts.

@srijeet0406
Copy link
Contributor

I tested out these changes locally and they work great for me. 👍

Copy link
Contributor

@srijeet0406 srijeet0406 left a comment

Choose a reason for hiding this comment

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

Tested the changes on my local machine and they worked fine 👍

@zrhoffman
Copy link
Member Author

Now that #4671 is merged, rebased to support make native cache/traffic_ops_ort.rpm

… already run

- Do not copy dist directory
- Gitignore grove and grovetccfg binaries
  - Specify that we want to build for Linux, regardless of host OS
  - Use awk to print the first field of wc, since BSD wc starts with a tab
  - Support stat -c on BSD systems
  - npm, bower, and grunt are already in the path, do not prefix with /usr/bin/
  - Specify recursive copy with -R, not -r
  - Use ${file.separator} in Traffic Router POMs
  - If the build environment is Cygwin, use a Windows GOPATH
    stop the build script
  - Specify environment requirements by component
The Traffic Portal Developer Environment" section
  - Move Compass instructions to "Software Requirements" section
  - Add reference labels
  - Change directories to the repo before running if we are not already
    there
  - Clean build the tarball to exclude gitignored files
  - If no projects are provided to clean_build.sh, build them all
  - Fix label references
  - Fix some typos
  - Link to the Windows footnote from the Chocolatey package row
  - Use the sphinx module to build the docs, not the sphinx-build executable
  - check for python3, not python
@zrhoffman
Copy link
Member Author

Rebased onto master

@mitchell852 mitchell852 merged commit db6d10b into apache:master Jul 8, 2020
@zrhoffman zrhoffman deleted the native_rpms branch July 8, 2020 19:57
@zrhoffman zrhoffman mentioned this pull request Aug 18, 2020
7 tasks
@zrhoffman zrhoffman mentioned this pull request Oct 21, 2020
7 tasks
@zrhoffman zrhoffman mentioned this pull request Nov 21, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build related to the build process new feature A new feature, capability or behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traffic Portal build system uses local dependencies
4 participants