apache / skywalking

APM, Application Performance Monitoring System
https://skywalking.apache.org/
Apache License 2.0
23.92k stars 6.53k forks source link

[Feature] Improve the compilation of skywalking-rover #12789

Closed tsint closed 1 hour ago

tsint commented 5 days ago

Search before asking

Description

When compiling skywalking-rover, add buildvcs=false to prevent compilation failures caused by Git in container environments. Additionally, include the flags -tags osusergo,netgo to achieve fully static compilation, avoiding runtime issues caused by incompatible versions of the glibc library.

For more infomation, see:

Use case

No response

Related issues

No response

Are you willing to submit a pull request to implement this on your own?

Code of Conduct

mrproliu commented 5 days ago
  1. For buildvcs=false, could you describe the scenario when it would cause failure? We already use volume mount when building the binary in the container.
  2. For the -tags osusergo,netgo, we already disable the gclib library in https://github.com/apache/skywalking-rover/blob/main/docker/Dockerfile.build#L26. So I think these two tags are not necessary.
tsint commented 5 days ago
  1. For buildvcs=false, could you describe the scenario when it would cause failure? We already use volume mount when building the binary in the container.
  2. For the -tags osusergo,netgo, we already disable the gclib library in https://github.com/apache/skywalking-rover/blob/main/docker/Dockerfile.build#L26. So I think these two tags are not necessary.
  1. Many scenarios could lead to issues, such as the code directory not being set as a safe.directory, a change in the directory owner. Or the presence of a .git directory in a parent directory, or corruption of the .git directory itself. In short, setting this causes no harm and helps avoid unnecessary compilation failures.
  2. Based on my actual execution of the ldd command, it does not appear to be as you described.
    $ ldd bin/skywalking-rover-latest-linux-amd64
        linux-vdso.so.1 (0x00007ffc287e8000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007faeb7800000)
        /lib64/ld-linux-x86-64.so.2 (0x00007faeb7b93000)

    If go tags are added, it becomes noticeably different.

    $ ldd bin/skywalking-rover-latest-linux-amd64
        not a dynamic executable

    Setting ENV CGO_ENABLED=0 has no effect on Docker's RUN command. Moreover, if CGO_ENABLED=0 is added to the compilation command, importing "c" will result in a compilation failure.

mrproliu commented 5 days ago

Many scenarios could lead to issues, such as the code directory not being set as a safe.directory, a change in the directory owner. Or the presence of a .git directory in a parent directory, or corruption of the .git directory itself. In short, setting this causes no harm and helps avoid unnecessary compilation failures.

Make sense to me, please add this parameter.

Setting ENV CGO_ENABLED=0 has no effect on Docker's RUN command. Moreover, if CGO_ENABLED=0 is added to the compilation command, importing "c" will result in a compilation failure.

Then, we should consider why the CGO_ENABLED is not working?

tsint commented 4 days ago

Many scenarios could lead to issues, such as the code directory not being set as a safe.directory, a change in the directory owner. Or the presence of a .git directory in a parent directory, or corruption of the .git directory itself. In short, setting this causes no harm and helps avoid unnecessary compilation failures.

Make sense to me, please add this parameter.

Setting ENV CGO_ENABLED=0 has no effect on Docker's RUN command. Moreover, if CGO_ENABLED=0 is added to the compilation command, importing "c" will result in a compilation failure.

Then, we should consider why the CGO_ENABLED is not working?

Sorry, I found that it was my mistake about failure to build a static executable file.
I manually executed make linux inside the container because I didn't want to create an image and push it to the local Docker repository, and also to speed up the compilation process.
Although setting ENV CGO_ENABLED=0 is fine, I would like to add CGO_ENABLED=0 to the build command and also add a generate dependency to the build process. This would make it easier to compile manually inside the container.