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

Provide Statically Linked Binaries #1100

Open
MattHodge opened this issue Mar 3, 2024 · 2 comments
Open

Provide Statically Linked Binaries #1100

MattHodge opened this issue Mar 3, 2024 · 2 comments
Assignees
Labels

Comments

@MattHodge
Copy link

MattHodge commented Mar 3, 2024

Feature Request

Is your feature request related to a problem? Please describe:

I had to spend a fair amount of time trying to get kcl installed into a docker container, even a simple ubuntu:22.04 image.

The following images are all built and tested using the following commands:

  • Build: docker build --platform linux/amd64 -t kcl-test:latest .
  • Test: docker run kcl-test:latest

Attempt 1:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y --no-install-recommends \
  bash \
  curl \
  ca-certificates

ARG KCL_VERSION="v0.7.5"
ARG KCL_PLATFORM="linux-amd64"
RUN set -x && \
  mkdir -p /tmp/kclvm && \
  cd /tmp/kclvm && \
  curl --retry 5 --retry-connrefused -LO https://github.com/kcl-lang/kcl/releases/download/${KCL_VERSION}/kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  tar -zxvf kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  mv kclvm/bin/* /usr/local/bin && \
  chmod +x /usr/local/bin/kcl && \
  chmod +x /usr/local/bin/kclvm_cli && \
  rm -rf /tmp/kclvm

RUN echo 'foo = "bar"' > /tmp/foo.k
ENTRYPOINT [ "kcl", "/tmp/foo.k" ]

Error raised:

Error: run linker failed: stdout , stderr:

After a while I ended up reading the installation FAQ which told me I need gcc

Attempt 2 - Adding gcc

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y --no-install-recommends \
  bash \
  curl \
  ca-certificates \
  gcc

ARG KCL_VERSION="v0.7.5"
ARG KCL_PLATFORM="linux-amd64"
RUN set -x && \
  mkdir -p /tmp/kclvm && \
  cd /tmp/kclvm && \
  curl --retry 5 --retry-connrefused -LO https://github.com/kcl-lang/kcl/releases/download/${KCL_VERSION}/kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  tar -zxvf kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  mv kclvm/bin/* /usr/local/bin && \
  chmod +x /usr/local/bin/kcl && \
  chmod +x /usr/local/bin/kclvm_cli && \
  rm -rf /tmp/kclvm

RUN echo 'foo = "bar"' > /tmp/foo.k
ENTRYPOINT [ "kcl", "/tmp/foo.k" ]

Error raised:

Error: run linker failed: stdout , stderr: /usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

Attempt 3- Adding gcc-multilib:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y --no-install-recommends \
  bash \
  curl \
  ca-certificates \
  gcc \
  gcc-multilib

ARG KCL_VERSION="v0.7.5"
ARG KCL_PLATFORM="linux-amd64"
RUN set -x && \
  mkdir -p /tmp/kclvm && \
  cd /tmp/kclvm && \
  curl --retry 5 --retry-connrefused -LO https://github.com/kcl-lang/kcl/releases/download/${KCL_VERSION}/kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  tar -zxvf kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  mv kclvm/bin/* /usr/local/bin && \
  chmod +x /usr/local/bin/kcl && \
  chmod +x /usr/local/bin/kclvm_cli && \
  rm -rf /tmp/kclvm

RUN echo 'foo = "bar"' > /tmp/foo.k
ENTRYPOINT [ "kcl", "/tmp/foo.k" ]

🥳 This works:

foo: bar

Describe the feature you'd like:

I would like if the binaries were all statically linked so I didn't need to have any dependencies installed in my operating system for kcl to work.

@Peefy
Copy link
Contributor

Peefy commented Mar 3, 2024

Hello! Thank you for the feedback. We have the official built docker image kcllang/kcl. Have you tried it or used it as a basic mirror to construct other KCL ecosystem tools? Besides, the dockerfile is here: https://github.com/kcl-lang/cli/blob/main/Dockerfile

This is also what we are striving to do, removing the operating system compiler dependency from KCL.

@Peefy Peefy added release enhancement New feature or request labels Mar 3, 2024
@Peefy Peefy added this to the v0.9.0 Release milestone Mar 3, 2024
@MattHodge
Copy link
Author

Thanks for the quick reply @Peefy :)

The plan was to use KCL in a docker container used in CI, so was trying to make it reasonably small.

At least I have it working now! The static linking would allow for usage in images like scratch to keep them as light as possible. I'll just roll with the larger images for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants