Personal blog backend and part of frontend. Live demo can find krzysztofbrzozowski.com
Project is based on Django 5, PostgreSQL, NGINX and Docker. All of the code is available widely except static files.
More description can be found in article Django based website deployed using github actions
pg_dump -U postgres -a -t projects_projectsmeta srcdb | psql -U <db_user> destdb;
pg_dump --column-inserts -a -t zones_seq -t interway -t table_3 ... > /tmp/zones_seq.sql
In project docker-gen generates reverse proxy configs -> more info
Clone a repo. Repository contains submodules. To download those run (be aware not all of them are public)
git config --global submodule.recurse true
or
git submodule update --init --recursive
Run Docker compose
docker compose -f "docker-compose.yml" up -d --build
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose
docker compose version
The authenticity of host '<<IP address>>' port <<port#>>: can't be established.
ECDSA key fingerprint is SHA256:<<some_sha>>.
Are you sure you want to continue connecting (yes/no)?
Just try to initialize any other repo via SSH on VPS and type 'yes'
More info Post-installation steps for Docker Engine
---
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:
---
Solution:
sudo groupadd docker
sudo usermod -aG docker ${USER}
su -s ${USER}
or
sudo chmod 777 /var/run/docker.sock
udo ss -tulnp | grep LISTEN
or from ext server
nmap dev.krzysztofbrzozowski.com
then
sudo ufw deny 5432
Docker compose (to run project)
docker compose -f "docker-compose.yml" up -d --build
See logs nginx
docker logs <container id>
docker logs 2677eef108c4
Run shell in Docker container
docker exec -it <container id> sh
docker exec -it 90c39aabcab0 sh
See logs per container
docker logs --tail 1000 -f <container id>
docker logs --tail 1000 -f 90c39aabcab0
Create new DB
sudo -u postgres psql
in container you can use:
psql -U postgres
CREATE DATABASE db;
Kill all containers
docker kill $(docker ps -q)
Clean every docker image, container
docker system prune
How to copy PostgreSQL DB
On server side
$ export PGPASSWORD="passwd" ; pg_dump -U <db_user | default: postgres> your_db > place/to/store/db.pgsql
In Docker Container
$ psql -U <db_user | default: postgres> db < place/to/store/db.pgsql
Send some file using SCP
scp -r src_dir root@dest_ip:/home/user/dsc_dir
Add secret key to your env variables (macOS)
echo "export SECRET_KEY_KB=!secret!" >> ~/.zshenv
source ~/.zshenv
List of used env variables (macOS, Ubuntu)
env
Your secret key shall be copied into Docker image if you are developing page locally e.g.
environment:
- SECRET_KEY_KB=${SECRET_KEY_KB}
Generate random secret key
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
in file e.g. /etc/nginx/vhost.d/dev.krzysztofborzowski.com put your stitic or media files such as
location /media/ {
alias /usr/src/app/media/;
}