Home > Mobile >  Django project on AWS not updating code after git pull
Django project on AWS not updating code after git pull

Time:11-30

I am deploying a Django project on AWS. I am running Postgres, Redis, Nginx as well as my project on Docker there.

Everything is working fine, but when I change something on my local machine, push changes to git and then pull them on the AWS instance, the code is changing, files are updated but they are not showing on the website. Only the static files are updating automatically (I guess because of Nginx). Here is my docker-compose config:

version: '3.9'

services:
  redis:
    image: redis
    command: redis-server
    ports:
      - "6379:6379"
  postgres:
    image: postgres
    environment:
      - POSTGRES_USER=
      - POSTGRES_PASSWORD=
      - POSTGRES_DB=
    ports:
      - "5432:5432"
  web:
    image: image_name
    build: .
    restart: always
    command: gunicorn project.wsgi:application --bind 0.0.0.0:8000
    env_file:
      - envs/.env.prod
    ports:
      - "8000:8000"
    volumes:
      - ./staticfiles/:/tmp/project/staticfiles
    depends_on:
      - postgres
      - redis
  nginx:
    image: nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./staticfiles:/home/app/web/staticfiles
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/logs:/var/log/nginx
      - ./certbot/www:/var/www/certbot/:ro
      - ./certbot/conf/:/etc/nginx/ssl/:ro
    depends_on:
      - web

Can you please tell me what to do?

I tried deleting everything from docker and compose up again but nothing happened. I looked all over in here but I still don't understand... instance restart is not working as well. I tried cleaning redis cache because I have template caching and still nothing.

CodePudding user response:

After updating the code on the EC2 instance, you need to build a new web docker image from that new code. If you are just restarting things then docker-compose is going to continue to pick up the last docker image you built.

You need to run the following sequence of commands (on the EC2 instance):

docker-compose build web
docker-compose up -d

You are seeing the static files change immediately, without rebuilding the docker image, because you are mapping to those files via docker volume.

CodePudding user response:

I found the issue... it was because I had template caching. If I remove the cache and do what @MarkB suggested, all is updating. I don't understand why this happens since I tried flushing all redis cache after changes but I guess it solves my issues.

  • Related