containers/buildah

Buildah isn't able to use packages added to the image?

ffarah-chegg opened this issue · 1 comments

Hello,

Part of the build process is to run Gradle which in turn runs this command (aws codeartifact get-authorization-token $commonCodeArtifactParams --query authorizationToken --output text) amongst other aws commands, however, that's failing because it's not finding the aws package during build even though aws-cli is installed.

This is the Dockerfile that builds the buildah image (which is used to build images on Gitlab):

FROM quay.io/buildah/stable:v1.35.4

RUN yum update && \
    yum -y install awscli2 \
    cmake3 \
    git \
    groff \
    jq \
    libffi-devel \
    make \
    sed \
    unzip && \
    yum -y clean all && rm -fr /var/cache 

COPY scripts /scripts

ENV PATH=$PATH:/bin:/scripts
ENV BIN_PATH=/scripts

This is the command we use to build the image:

buildah bud -f ${CI_PROJECT_DIR}/Dockerfile -t ${ECR_IMAGE_TAG_ENV} ${BUILD_LABELS} ${BUILD_ARGS} ${CUSTOM_BUILD_ARGS} --retry=3 --layers --cache-from=xxxxx.dkr.ecr.us-west-2.amazonaws.com/company/reference-implementations/project/cache --cache-to=xxxxx.dkr.ecr.us-west-2.amazonaws.com/company/reference-implementations/project/cache

Locally I'm able to run aws (when logged into the container) and $PATH looks correct:

[root@b6f5bf487770 /]# aws --version
aws-cli/2.17.0 Python/3.12.3 Linux/6.6.31-linuxkit source/x86_64.fedora.40
[root@b6f5bf487770 /]# which aws
/usr/bin/aws
[root@b6f5bf487770 /]# echo $PATH
/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/bin:/scripts

However during build (on Gitlab) aws is not found and $PATH is not correct:

[1/2] STEP 16/18: RUN echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

[1/2] STEP 17/18: RUN aws --version
/bin/sh: aws: No such file or directory
subprocess exited with status 127
subprocess exited with status 127
Error: building at STEP "RUN aws --version": exit status 127

The actual blocker is this:

Welcome to Gradle 8.7!
Here are the highlights of this release:
 - Compiling and testing with Java 22
 - Cacheable Groovy script compilation
 - New methods in lazy collection properties
For more details see https://docs.gradle.org/8.7/release-notes.html
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.7/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build 
> Configure project :
Executing build script: https://company-gradle.test.devx.company.services/company-gradle/scripts/boots-build.5/application.gradle
Executing build script: https://company-gradle.test.devx.company.services/company-gradle/scripts/boots-build.5/internal/company-repository.gradle
Using AWS CLI to get CodeArtifact repo URL
Executing: aws codeartifact get-repository-endpoint  --domain company --domain-owner xxxxx --region us-west-2 --repository java-company --format maven --query repositoryEndpoint --output text
 AWS CLI isn't installed, please install it to use CodeArtifact 
 See Authenticating with AWS CodeArtifact: http://go/authenticating-with-aws-codeartifact  
FAILURE: Build failed with an exception.

Is this something that's supported? If so, what am I doing wrong?

Got it to work, I am new to buildah which is why I was having this issue.

The way I got things to work is by adding doing two things:

  • Added --env PATH=${PATH} to update the build container ${PATH} to use the same value
  • Added -v /path/to/bin which mounts the "host" bin dir that contains the aws-cli package onto the build container.

So basically buildah -v /path/to/bin --env PATH=${PATH} ....