I have following pipeline:
pipelines:
custom:
build:
- parallel:
- step:
name: scan for secrets
runs-on:
- 'self.hosted'
- 'linux'
script:
- pipe: atlassian/git-secrets-scan:0.5.1
- step:
name: build
image:
name: gradle:8.1.1
caches:
- gradle
runs-on:
- 'self.hosted'
- 'linux'
script:
- gradle build -x test
- mkdir -p $BITBUCKET_CLONE_DIR/dist
- cp build/libs/app.jar $BITBUCKET_CLONE_DIR/dist/
- ls -la dist
after-script:
- pipe: atlassian/checkstyle-report:0.3.0
artifacts:
paths:
- dist/**
- step:
name: test
runs-on:
- 'self.hosted'
- 'linux'
image:
name: gradle:8.1.1
caches:
- gradle
script:
- gradle test
- step:
name: dockerize
runs-on:
- 'self.hosted'
- 'linux'
image:
name: xxx.com/kaniko:v1.12.1-debug-4
username: $USERNAME
password: $PASSWORD
size: 2x
script:
- pwd
- ls -la
- find . -iname '*.jar'
- ./devops/pipelines/scripts/kaniko-login.sh
- /kaniko/executor --cache=true --cache-copy-layers=true --cache-repo="$DOCKER_DOMAIN/lalala/cache" --context="$BITBUCKET_CLONE_DIR" --dockerfile="$BITBUCKET_CLONE_DIR/Dockerfile" --destination="$DOCKER_DOMAIN/lalala:latest" --destination="$DOCKER_DOMAIN/lalala:$BITBUCKET_BUILD_NUMBER" --use-new-run --snapshot-mode=redo
And I have kaniko error:
error building image: error building stage: failed to optimize instructions: failed to get files used from context: failed to get fileinfo for /opt/atlassian/pipelines/agent/build/dist/app.jar: lstat /opt/atlassian/pipelines/agent/build/dist/app.jar: no such file or directory
As you can already see I tried to debug it so:
build
step on ls -la
command:
+ ls -la dist
total 58312
drwxrwxrwx 2 root root 4096 Jul 12 11:07 .
drwxrwxrwx 9 root root 4096 Jul 12 11:07 ..
-rw-rw-rw- 1 root root 59700452 Jul 12 11:07 app.jar
build
step in teardown part:
Searching for files matching artifact pattern dist/**
Artifact pattern dist/** matched 1 files with a total size of 56.9 MiB
Compressed files matching artifact pattern dist/** to 52.2 MiB in 1 seconds
Uploading artifact of 52.2 MiB
Successfully uploaded artifact in 4 seconds
dockerrize
step in build setup part:
Artifact "dist/**": Downloading
Artifact "dist/**": Downloaded 52.2 MiB in 3 seconds
Artifact "dist/**": Extracting
Artifact "dist/**": Extracted in 0 seconds
dockerize
step in find command output:
+ find . -iname '*.jar'
./gradle/wrapper/gradle-wrapper.jar
so no dist
Am I missing something?
So I found a problem. Even if dockerize
step is saying:
Artifact "dist/**": Downloading
Artifact "dist/**": Downloaded 52.2 MiB in 3 seconds
Artifact "dist/**": Extracting
Artifact "dist/**": Extracted in 0 seconds
it fails silently because kaniko
container doesn't have tar
etc. When I changed image into one created with this:
FROM gcr.io/kaniko-project/executor:v1.12.1-debug as kaniko
FROM atlassian/default-image:4.20230308
COPY --from=kaniko /kaniko/.docker /kaniko/.docker
ENV DOCKER_CONFIG /kaniko/.docker/
COPY --from=kaniko /kaniko/executor /kaniko/executor
then it worked.
Base issue is (but I do not know where to submit it) that pipeline doesn't ensure that tar
(and related gzip / bzip2 stuff) is present in container.