A small practice project to store pictures of cats. Practiced CI/CD, Docker and DRF
Working instance is available at: kittygram
- Production:
Use
docker-compose.production.ymlto use images uploaded to docker hub. - Development:
Use
docker-compose.ymlto build and run containers from local files.
- Install docker On linux:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.shOn other platforms: Docker Desktop
- Clone the repo and move to the directory
https://github.com/alisher-nil/kittygram.git
cd kittygram/- Create a
.envfile 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.
- 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/defaultserver {
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- Alisher Nildibaev alisher.nil@gmail.com
- Python
- Django
- Docker
- Nginx
- CSS
- HTML