Appears to be some kind of context issue. I'm trying to figure out why this would work fine when spinning up a local Kubernetes cluser with Skaffold, but is failing to build the image properly when pushing to Azure.
Basic structure is:
test-app/
server/
requirements.txt
Dockerfile
azure-pipeline.yml
skaffold.yaml
I have the production server/Dockerfile
as the following:
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
WORKDIR '/app'
EXPOSE 5000
COPY ./server/requirements.txt .
RUN pip install -r requirements.txt
COPY ./server .
CMD ["python", "manage.py", "collectstatic"]
CMD ["gunicorn", "-b", ":5000", "--log-level", "info", "config.wsgi:application"]
I'm using the azure-pipelines.yml
that was generated for me in the Pipelines section of Azure DevOps:
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '<connection-string>'
imageRepository: 'testapp'
containerRegistry: 'testappcontainers.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/server/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
During the automated build it gets to COPY ./server/requirements.txt .
and the throws the error in the title.
Reading this question, I've tried a number of the suggested solutions with no resolution, like:
COPY ./server/requirements.txt /app
COPY server/requirements.txt /app
In addition, I've also just tried:
COPY requirements.txt /app
Still get the error.
So, kind of stumped on:
Actually, the example project has a similar project structure:
pipelines-javascript-docker/
app/
Dockerfile
And it runs fine... some I'm probably overlooking something apparently.
When I encountered this obstacle I resolved by setting up the property buildContext in the yml file.
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
containerRegistry: '$(ACR.Connector)'
repository: '$(imageName)'
command: 'buildAndPush'
Dockerfile: '$(Agent.BuildDirectory)/s/server/Dockerfile'
buildContext: '$(Agent.BuildDirectory)/s'
tags: '$(tag)'