Skip to content

alisher-nil/kittygram

Repository files navigation

Kittygram

Description

A small practice project to store pictures of cats. Practiced CI/CD, Docker and DRF

Build status

Kittygram Workflow

Working instance is available at: kittygram

Differences Between Production and Development

  • Production: Use docker-compose.production.yml to use images uploaded to docker hub.
  • Development: Use docker-compose.yml to build and run containers from local files.

Deployment

Run locally

  • Install docker On linux:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh

On other platforms: Docker Desktop

  • Clone the repo and move to the directory
https://github.com/alisher-nil/kittygram.git
cd kittygram/
  • Create a .env file in the root directory. An example is provided in .env.example. You can use the following command to create a copy:
cp .env.example .env
  • Deploy using docker:
docker compose up -d
  • Apply migrations and move static files to static volume:
docker compose exec backend python manage.py migrate
docker compose exec backend python manage.py collectstatic
docker compose exec backend cp -r /app/collected_static/. /backend_static/static/

Deployed project should be available on 127.0.0.1:9000. Port can be adjusted in .env file.


Run on a remote vm:

  • Move docker compose files and .env to remote vm using scp
scp /kittygram_final/docker-compose.production.yml <username>@<address>:/kittygram
scp /kittygram_final/.env <username>@<address>:/kittygram
  • log in to remote vm using ssh
ssh -i path/to/privatekey <username>@<address>
  • Install docker and nginx web server
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
sudo apt install nginx -y
sudo systemctl start nginx
  • Run containers, apply migrations, move static files:
cd kittygram/
sudo docker compose -f docker-compose.production.yml up -d
sudo docker compose -f docker-compose.production.yml exec backend python manage.py migrate
sudo docker compose -f docker-compose.production.yml exec backend python manage.py collectstatic --noinput
sudo docker compose -f docker-compose.production.yml exec backend cp -r /app/collected_static/. /backend_static/static/
  • adjust the nginx config
sudo nano /etc/nginx/sites-enabled/default
server {
    server_name <your host address>;
        ...
        location / {
            proxy_pass http://127.0.0.1:9000/;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
        ...
    }

Check config and reload nginx daemon

sudo nginx -t
sudo systemctl reload nginx

Author

Technologies Used

  • Python
  • Django
  • Docker
  • Nginx
  • CSS
  • HTML

About

practice project for CI/CD, docker and DRF

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published