I’m trying to build a docker in a pipeline
My project structure is as follow (locally)
path/to/project/
├─ ci/
│ ├─ dockerfiles/
│ │ ├─ build.dockerfile
│ ├─ configs/
│ │ ├─ config.json
│ ├─ scripts/
│ │ ├─ templates/
│ | | ├─ build.azure-pipeline.yml
│ │ ├─ azure-pipeline.yml
├─ src/
And in its Azure DevOps repo:
ci/
├─ dockerfiles/
│ ├─ build.dockerfile
├─ configs/
│ ├─ config.json
├─ scripts/
│ ├─ templates/
| | ├─ build.azure-pipeline.yml
│ ├─ azure-pipeline.yml
src/
The interesting parts of the files are as follow:
azure-pipeline.yml file:
pool:
vmImage: ubuntu-latest
stages:
- stage: Build
jobs:
- template: templates/build.azure-pipeline.yml
parameters:
...
build.azure-pipeline.yml file:
parameters:
...
jobs:
- job: build_${{ parameters.build }}
steps:
- checkout: self
submodules: recursive
persistCredentials: true
- task: DockerInstaller@0
inputs:
dockerVersion: '20.10.9'
- task: Docker@2
displayName: Build
inputs:
repository: 'repositories/project'
command: 'build'
Dockerfile: 'ci/dockerfiles/build.dockerfile'
buildContext: '.'
arguments: ...
build.dockerfile file:
FROM ubuntu:22.04 AS build-env
SHELL ["/bin/bash", "-lc"]
WORKDIR /app
COPY 'ci/configs/config.json' '/app/config.json'
I can build it, with no issue, locally with the following command:
docker buildx build
-f ~/path/to/project/ci/dockerfiles/build.dockerfile
--load ~/path/to/project
But when running the pipeline in Azure DevOps, it throws the following error:
##[error]#29 [build-env 25/26] COPY ci/configs/config.json /app/config.json
##[error]#29 sha256:f99004049a1f734d017dee2ba835634a67abb44913e4dcbb5b2293a877ccb33d
##[error]#29 ERROR: failed to calculate checksum of ref 68fa3e36-3e48-46b1-9ff3-248c6f3575df::h23it1x41ylkkv9vx2ydspezg: "/ci/configs/config.json": not found
And I have the same error for every COPY command, be it with files in the ci folder or src folder.
I thought the buildContext: '.'
part of the build.azure-pipeline.yml file was the problem, so I tried with several other values '../../..'
or '../..'
to check if I had to put a relative path from the yml or dockerfile. I also tried with other values such as '$(Build.Repository.LocalPath)'
but nothing seems to work.
The only difference I see between the local build and the one from Azure is when loading the context.
Locally, I have:
=> [internal] load .dockerignore
=> => transferring context: 2B
=> [build-env 1/26] FROM docker.io/library/ubuntu:22.04
=> [internal] load build context
=> => transferring context: 1.32MB
And in Azure DevOps:
#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s
#18 [build-env 1/26] FROM docker.io/library/ubuntu:22.04
#18 DONE 0.0s
#5 [internal] load build context
#5 transferring context: 490.43kB 0.0s done
#5 DONE 0.1s
The Azure context is way smaller than the local one, I don’t know if it can explain the issue.
So here am I, asking, what did I do wrong ?