azuredockergitlabazure-container-registry

Docker image is not updating on Azure container registry via gitlab


I am having an issue with my docker images which are uploaded on the Azure container registry via gitlab, but they seem not to be updating the current code, but locally they work.

What could be a problem to my .gitlab-ci.yml file ?

image:
  name: docker/compose:1.25.4
  entrypoint: [""]

services:
  - docker:dind

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2

stages:
  - develop

build-dev:
  stage: develop
  before_script:
    - export IMAGE=$CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
    - apk add --no-cache --upgrade bash
  script:
    - apk add --no-cache bash
    - chmod +x ./setup_env.sh
    - bash ./setup_env.sh
    - docker login $AZ_REGISTRY_IMAGE -u $AZ_USERNAME_REGISTRY -p $AZ_PASSWORD_REGISTRY
    - docker pull $AZ_REGISTRY_IMAGE/proj:tag || true
    - docker-compose build --no-cache
    - docker tag $AZ_REGISTRY_IMAGE/proj:tag $AZ_REGISTRY_IMAGE/pixsar:$(date +%Y%m%d%H%M)
    - docker push $AZ_REGISTRY_IMAGE/proj:$(date +%Y%m%d%H%M)
    - docker system prune -af
  only:
    - develop
    - fix-docker-1

Additonal files :

Dockerfile

# Use an official Python runtime as a parent image
FROM python:3.10

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

# Copy the project code into the container
COPY . /app/

# Expose port 8000 to the outside world
EXPOSE 8001

# Command to run the startup script
CMD ["./startup.sh"]

# Command to run the application
CMD ["daphne", "app.asgi:application", "--port", "8001", "--bind", "0.0.0.0"]

and docker-compose file :

version: '3.3'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8001:8001"
    env_file:
      - .env

Solution

  • This worked for me.

    • Note :- If you are using docker-compose version 1 you will receive warning but not error and it will also not build a new updated imaged.
    • Make sure in gitlab pipeline you are not getting error
    • For reference check this document.

    I pulled a nginx image and pushed to azure container registry

    .gitlab-ci.yml:

    docker-build:
     # Use the official docker image.
     image:  docker:cli
     stage:  build
     services:
     -  docker:dind
    
     script:
     -  docker  pull  nginx
     -  docker  login  vshandilyaacr.azurecr.io  -u  vshandilyaacr  -p  xxxxxxxxxxxxxx
     -  docker  tag  nginx  vshandilyaacr.azurecr.io/azuregitlab:docker
     -  docker  push  vshandilyaacr.azurecr.io/azuregitlab:docker
    
     rules:
     -  if:  $CI_COMMIT_BRANCH
     exists:
     -  Dockerfile
    

    OUTPUT: