5

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://learn.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:

  1. How to resolve this so it builds correctly in Pipelines and pushes to CRS...
  2. If it is a context issue, why isn't an issue in local dev when using Skaffold

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.

cjones
  • 8,384
  • 17
  • 81
  • 175

2 Answers2

3

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)'
Yunnosch
  • 26,130
  • 9
  • 42
  • 54
NPeniate
  • 31
  • 1
2

After looking at the example project more closely, which has the same structure as what I'm trying to do, I ended up copying its Dockerfile formatting. I ended up with this which is working fine:

FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
WORKDIR /app
EXPOSE 5000
COPY requirements*.txt ./
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "collectstatic"]
CMD ["gunicorn", "-b", ":5000", "--log-level", "info", "config.wsgi:application"]
cjones
  • 8,384
  • 17
  • 81
  • 175