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

Can't install to container, before doing a build in GitLab. (Missing package manager?) #1440

Closed
Cameronsplaze opened this issue Sep 30, 2020 · 8 comments
Labels
area/container For all bugs related to the kaniko container gitlab kind/question Further information is requested priority/p3 agreed that this would be good to have, but no one is available at the moment.

Comments

@Cameronsplaze
Copy link

Cameronsplaze commented Sep 30, 2020

Actual behavior
For running in GitLab, I have a yml similar to:

image: 
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  tags: [ docker ]
  stage: Deploy-staging
  script:
    # --- Login stuff here --- #
   # --- Setup more here? Like opkg install git? --- #
    - /kaniko/executor --context ${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/Dockerfile --destination ${REPO_URL}

That part works great, but I can't find how to do any setup before building the image. There's a couple repo's I'd like to git clone before getting to the build part, so everything's together. I can't find how to install git, or any other packages I might need in the future. Is there a package manager I'm just missing? It's busybox, so I tried opkg, but it says it's not found. I also tried apt, pacman, yum, etc without any luck.

Expected behavior
A package manager to install missing libraries to container, before building containers in a GitLab runner.

Additional Information

  • Dockerfile
    N/A
  • Build Context
    N/A
  • Kaniko Image (fully qualified with digest)
    gcr.io/kaniko-project/executor:debug

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
  • - [ X ]
Please check if the build works in docker but not in kaniko
Please check if this error is seen when you use --cache flag
Please check if your dockerfile is a multistage dockerfile
@Cameronsplaze
Copy link
Author

Cameronsplaze commented Oct 1, 2020

I think I got around this, by having another GitLab job (Ubuntu) download git, clone the repo, and upload an artifact with the files to the Kaniko job. Is this the intended way to add files for Kaniko to build with in GitLab? It seems slightly overkill just to add files to me, but I'm new to CI-CD. Maybe keeping jobs super small in gitlab is intended? Any way, thanks in advance for any advice you might have on this! I was stuck on it for a while now lol.
I stripped this down, so it might not be 100% accurate, but my solution was something like this:

Staging setup:
  image: ubuntu:18.04
  stage: Build-staging
  script:
    - apt update && apt install -y git
    - git clone <mylib.git repo>
  artifacts:
    name: "Lib-$CI_JOB_ID"
    paths:
      - mylib/
    exclude:
      - mylib/.git/**/*
    expire_in: 1 day

Staging build:
  image: 
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  tags: [ docker ]
  stage: Deploy-staging
  dependencies:
    - "Staging setup"
  script:
    # --- Login stuff here --- #
    # --- artifact is added to project by default, setup already done!! ---
    - /kaniko/executor --context ${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/Dockerfile --destination ${REPO_URL}

@cmorty
Copy link

cmorty commented Oct 16, 2020

@cjshowalter The problem is, that the script is executed in the context of the knaiko-Image. And that image has no git (because it isn't needed and does not belong there). I do not have a really good solution, but I can give some pointers:

@Cameronsplaze
Copy link
Author

Hey @cmorty, thanks for the reply!

I guess that's where I'm stuck. I don't know how to add git to the Kaniko image. It doesn't have any package manager I can find, or curl, make, and cmake for building it myself. I'll have to remember about the custom executors, I'd like to get podman working eventually too xD, I'm not sure if that lets you use git, or any other packages though.

@cmorty
Copy link

cmorty commented Oct 17, 2020

@cjshowalter You'll need a multistage build: https://docs.docker.com/develop/develop-images/multistage-build/

You can take the kaniko image and copy the executor into the alpine/git image. (You can do this using kaniko) and then upload that image to you registry and use that as your image.

You're Dockerfile should look something like

FROM kaniko AS kan
FROM alpine/git
COPY --from=kan /kaniko/executor /kaniko/

...to get the gist. ;)

@Cameronsplaze
Copy link
Author

Hey @cmorty, I missed the reply. Sorry about the late response xD.

Multistage builds is definitely a neat idea. I'm worried about it breaking though. Here, they mentioned that's not yet supported I think. (Second bullet point). Plus I'd have to re-build it every time kaniko pushes an update.

I'm guessing this isn't a common problem. People probably keep all the dependencies in the repo itself, or use submodules to pull additional ones before building. I control both repos I'm trying to combine into the container, and submodules are a pita to keep updated with the branch you're pulling from. I guess kaniko pushing a larger version of the container, before they strip out their package manager is one option. I'm not sure they're up to supporting something like that...

@akarnokd
Copy link

I have similar problem. I have to create the docker image and upload it into a remote git repo. Unfortunately, the image is over 1GB and it is too big for the artifacts:paths:image.tar approach to pass it to a subsequent stage. Any tips?

@mattduguid
Copy link

mattduguid commented Mar 14, 2022

have this problem as well, wanting to install wget to test connectivity but apt and apk arent available? looks like this might be a solution -> https://github.com/WoozyMasta/kaniko-tools

@aaron-prindle
Copy link
Collaborator

As mentioned in the thread, the options here for installing some helper tools into the kaniko image include:

Going to close this as I believe the question was answered in the thread and there isn't anything actionable here. Feel free to comment and I can re-open if there is more here, thanks

@aaron-prindle aaron-prindle added kind/question Further information is requested gitlab priority/p3 agreed that this would be good to have, but no one is available at the moment. area/container For all bugs related to the kaniko container labels Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/container For all bugs related to the kaniko container gitlab kind/question Further information is requested priority/p3 agreed that this would be good to have, but no one is available at the moment.
Projects
None yet
Development

No branches or pull requests

5 participants