wget -NP . https://dokku.com/install/v0.36.10/bootstrap.sh
sudo DOKKU_TAG=v0.36.10 bash bootstrap.sh

# make sure authorized_keys has value first
cat ~/.ssh/authorized_keys | dokku ssh-keys:add admin
dokku domains:set-global 45.56.68.144

sudo dokku apps:create mycrib
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
sudo dokku postgres:create mycrib
sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis
sudo dokku redis:create mycrib

sudo dokku postgres:link mycrib mycrib
sudo dokku redis:link mycrib mycrib

sudo dokku config:set --no-restart mycrib SECRET_KEY=wz%C*@^*wKZK9bV3CBMt7cj3wk2y^0vdu@2*pz7yco+p=7@sa%

dokku storage:mount mycrib /var/lib/dokku/data/storage/mycrib:/code/media/

# add remote dokku server as a remote repo in git
# this has to be done for git to be able to use the right key
Host mycribDev
	HostName 104.200.20.223
	User root
	PreferredAuthentications publickey
    IdentityFile /Users/treyt/.ssh/linode_88oakapps
	IdentitiesOnly yes
	AddKeysToAgent yes


git remote add dokku dokku@mycribDev:mycrib

# to push 
git push dokku@mycribDev:mycrib develop

sudo dokku domains:add mycrib mycrib.treytartt.com
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
sudo dokku config:set --no-restart --global DOKKU_LETSENCRYPT_EMAIL=mycrib@treymail.com
sudo dokku letsencrypt:set mycrib email mycrib@treymail.com
sudo dokku letsencrypt:enable mycrib
sudo dokku letsencrypt:cron-job --add
sudo dokku plugin:install https://github.com/dokku/dokku-redirect.git

# media
dokku storage:ensure-directory mycrib
dokku storage:mount mycrib /var/lib/dokku/data/storage/mycrib/media:/code/media


# Make sure your settings.py has:
MEDIA_URL = '/media/'
MEDIA_ROOT = '/code/media/'  # This matches the container path you mounted

dokku enter mycrib
chown -R dokku:dokku media # gives invalid user?
chmod -R 755 media

# make sure storage is listed
dokku storage:list mycrib
# list
/var/lib/dokku/data/storage/mycrib:/code/media/

# add location conf
nano /home/dokku/mycrib/nginx.conf.d/media.conf

# paste in 
location /media/ {
    alias /var/lib/dokku/data/storage/mycrib/;
}

 # Unmount storage (if needed)
dokku storage:unmount mycrib /var/lib/dokku/data/storage/mycrib:/app/media

# helpful commands
# restart app
dokku ps:restart mycrib

# enter docker container
dokku enter mycrib web

#check if debug
dokku run werkout python manage.py shell
from django.conf import settings
print(settings.DEBUG)
exit()

# clear out space
docker builder prune -a
docker system prune -a

# create super user
dokku run mycrib python manage.py createsuperuser

# postgres info
dokku postgres:info your-database-db
postgres://postgres:bf8f1cb443c35cd1ae0a58617ef348cd@dokku-postgres-your-database-db:5432/your_database_db
[database type]://[username]:[password]@[host]:[port]/[database name]

# show env
dokku config:show mycrib

# show how dokku is doing
dokku ps:report

# check workers are working
dokku ps:scale mycrib

# if not
dokku ps:scale mycrib web=1 worker=3 beat=1


# added this b/c claude told me to but doesnt look to be needed 
dokku config:set mycrib \
    SECURE_PROXY_SSL_HEADER="HTTP_X_FORWARDED_PROTO,https" \
    USE_X_FORWARDED_HOST="True"

# dev smtp stuff
dokku config:set --no-restart mycrib \
	EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend" \
	EMAIL_HOST="smtp.fastmail.com" \
	EMAIL_PORT="587" \
	EMAIL_USE_TLS="True" \
	EMAIL_HOST_USER="treytartt@fastmail.com" \
	EMAIL_HOST_PASSWORD="2t9y4n4t497z5863" \
	DEFAULT_FROM_EMAIL="MyCrib <crib@treymail.com>"

# for prod
dokku config:set mycrib \
	APNS_AUTH_KEY_PATH="/code/push_certs/AuthKey_5PP558G7W7.p8" \
	APNS_AUTH_KEY_ID="5PP558G7W7" \
	APNS_TEAM_ID="V3PF3M6B6U" \
	APNS_TOPIC="com.tt.mycrib.MyCribDev" \
	APNS_USE_SANDBOX="False"

dokku config:set casera-api \
APNS_AUTH_KEY_PATH=/app/push_certs/AuthKey_9R5Q7ZX874.p8 \
APNS_AUTH_KEY_ID=9R5Q7ZX874 \
APNS_TEAM_ID=V3PF3M6B6U \
APNS_TOPIC=com.tt.casera.CaseraDev \
APNS_PRODUCTION=true

Production (mycribProdText):
dokku config:set mycrib GUNICORN_WORKERS=6 GUNICORN_THREADS=2
dokku ps:scale mycrib web=3

Development (mycribDev):
dokku config:set mycrib GUNICORN_WORKERS=4 GUNICORN_THREADS=1
dokku ps:scale mycrib web=1

# view worker logs
dokku logs mycrib worker -t