Skip to content

Conversation

@hsmatulis
Copy link
Contributor

@hsmatulis hsmatulis commented Jan 13, 2023

Description

Improve Dockerfile caching to speed up subsequent builds on the same machine. It now takes ~8 minutes on my machine to recompile the agent after changing the source code

Checklist:

  • Unit tests
    • Unit tests do not apply.
    • Unit tests have been added/modified and passed for this PR.
  • Integration tests
    • Integration tests do not apply.
    • Integration tests have been added/modified and passed for this PR.
  • Documentation
    • This PR introduces no user visible changes.
    • This PR introduces user visible changes and the corresponding documentation change has been made.
  • Minor version bump
    • This PR introduces no new features.
    • This PR introduces new features, and there is a separate PR to bump the minor version since the last release already.
    • This PR bumps the version.

@hsmatulis hsmatulis force-pushed the linux_dockerfile branch 15 times, most recently from 7a811b4 to b13ef60 Compare January 17, 2023 22:09
@hsmatulis hsmatulis marked this pull request as ready for review January 17, 2023 22:10
@hsmatulis hsmatulis force-pushed the linux_dockerfile branch 2 times, most recently from 3392b77 to 11219f1 Compare January 19, 2023 16:30
Co-authored-by: Jeff Erbrecht <89024676+jefferbrecht@users.noreply.github.com>
@hsmatulis hsmatulis merged commit 8951597 into master Jan 19, 2023
@hsmatulis hsmatulis deleted the linux_dockerfile branch January 19, 2023 19:37
Comment on lines +42 to +43
if [[ ! -f /work/google_cloud_ops_agent_engine ]]; then
go build -buildvcs=false -o "/work/google_cloud_ops_agent_engine" \
Copy link

Choose a reason for hiding this comment

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

@hsmatulisgoogle This changes break the build.sh if its run directly. For example,

$ BUILD_DISTRO=arch CODE_VERSION="${pkgver}" DESTDIR="$_destdir"  ./build.sh

See build output here: https://build.kilabit.info/karajo/job/log?id=aur_google-cloud-ops-agent-git&counter=51

Copy link
Member

Choose a reason for hiding this comment

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

build.sh is an implementation detail of Dockerfile and is not intended to be run standalone. Would you mind sharing the reason why you're building it that way instead of using Dockerfile -- is there something about Dockerfile that doesn't work for you?

Copy link

Choose a reason for hiding this comment

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

build.sh is an implementation detail of Dockerfile and is not intended to be run standalone.

I see. I thought it was for building the binaries (the usual make flow installed on $DESTDIR). I remember reading the rpm spec script and it execute the build.sh directly.

Would you mind sharing the reason why you're building it that way instead of using Dockerfile -- is there something about Dockerfile that doesn't work for you?

I use it to build the ops-agent package for Arch Linux [1] which is not available in Dockerfile.
In that case I will patch the build script manually, and run each .sh script manually.

@@ -72,6 +74,13 @@ build() {
        echo "destdir: $_destdir"

        cd "${pkgname}"
+
+       CGO_ENABLED=1 ./builds/otel.sh "$_destdir"
+       ./builds/fluent_bit.sh "$_destdir"
+       ./builds/systemd.sh "$_destdir"
+       ./builds/ops_agent_diagnostics.sh "$_destdir"
+
+       git apply "${srcdir}/0001-build-sh.patch"
        BUILD_DISTRO=arch CODE_VERSION="${pkgver}" DESTDIR="$_destdir" \
                ./build.sh
 }

It succesfully build last time I run, but need to test it on live image.

Sorry for the noise.

[1] https://aur.archlinux.org/packages/google-cloud-ops-agent-git

Copy link
Member

Choose a reason for hiding this comment

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

FYI build.sh was intended to function independently from Docker. I agree that this change now makes it impossible to do non-Docker builds.

archlinux-github pushed a commit to archlinux/aur that referenced this pull request Feb 16, 2023
Since PR #1038 merged to master, the build failed due to the $DESTDIR
now replaced with "/work" for building with docker. [1]

[1] GoogleCloudPlatform/ops-agent#1038 (comment)
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.

6 participants