cd /var/www/sinfronteras/ git clone git@github.com:enriquecarlosdominguezbolivar-dot/gotagig.git # If the local repository was previously cloned: cd gotagig git pull origin main Database ======== # Install Docker + Docker Compose plugin sudo apt update sudo apt install -y docker.io docker-compose-plugin sudo systemctl enable --now docker systemctl status docker sudo usermod -aG docker $USER # So you can run docker without sudo (re-login after) docker compose up -d db # Start the DB container from the repo root (donde está docker-compose.yml) Deployment Fastapi ================== cd backend/ vi .env # Don't forget to create the env variables pyenv -v pyenv install --list pyenv install 3.12.10 pyenv versions pyenv local 3.12.10 python -m venv .venv source .venv/bin/activate which python which pip pip install --upgrade pip pip install -r requirements.txt pip list ls /etc/systemd/system sudo vi /etc/systemd/system/gotagit-backend.service ------- [Unit] Description=gotagit-backend After=network.target [Service] User=ubuntu Group=www-data WorkingDirectory=/var/www/sinfronteras/gotagit/backend Environment="PATH=/var/www/sinfronteras/gotagit/backend/.venv/bin" ExecStart=/var/www/sinfronteras/gotagit/backend/.venv/bin/gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8001 [Install] WantedBy=multi-user.target ------- sudo systemctl daemon-reload # We run this when we modify the service file (gotagit-backend.service) sudo systemctl start gotagit-backend sudo systemctl enable gotagit-backend sudo systemctl status gotagit-backend sudo journalctl -u gotagit-backend -n 50 # To checks log in case of any issues sudo systemctl restart gotagit-backend # If we make any changes to the app later sudo certbot --nginx -d api.gotagit.sinfrontera.net # The following step is not mandatory. It is only to ensure everything is in order so the certificate can renew: sudo certbot renew --dry-run systemctl list-timers | grep certbot # This should display something like "certbot.timer" sudo vi /etc/nginx/sites-available/api.gotagit.sinfrontera.net ------- server { listen 443 ssl http2; server_name api.gotagit.sinfrontera.net; ssl_certificate /etc/letsencrypt/live/api.gotagit.sinfrontera.net/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/api.gotagit.sinfrontera.net/privkey.pem; location / { proxy_pass http://127.0.0.1:8001; proxy_set_header Host $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; } } server { listen 80; server_name api.gotagit.sinfrontera.net; return 301 https://$host$request_uri; } ------- sudo ln -s /etc/nginx/sites-available/api.gotagit.sinfrontera.net /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx sudo systemctl restart nginx # Only if reload fails or Nginx behaves oddly Deployment Nextjs ================= cd frontend # ... If the local repository has already been cloned vi .env # Don't forget to create the env variables nvm install 24.18.0 # Creo que esto no sería necesario porque lo estamos haciendo bajo luego de "npm use" echo "24.18.0" > .nvmrc # Only needed if the file hasn't been created yet, or if you want to use a different version nvm use npm install npm run build pm2 start npm --name "gotagit-frontend" -- start # Port 3000 by default PORT=3001 pm2 start npm --name "gotagit-frontend" -- start # If we want to specify the port pm2 save # Save the process pm2 startup # Then we have to run the output returned by "pm2 startup". This is to be ran only once. So the first time we deploy an app with PM2. Not for every app. That command is only to install the boot hook once per machine. pm2 save # Save again # To verify it worked: pm2 status pm2 list systemctl status pm2-youruser pm2 restart gotagit-frontend # If we make any changes to the app later pm2 restart gotagit-frontend --update-env # If we make any changes to the app later that included the .env file sudo certbot --nginx -d gotagit.sinfrontera.net sudo vi /etc/nginx/sites-available/gotagit.sinfrontera.net ------- server { listen 443 ssl; server_name gotagit.sinfrontera.net; ssl_certificate /etc/letsencrypt/live/gotagit.sinfrontera.net/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/gotagit.sinfrontera.net/privkey.pem; location / { proxy_pass http://localhost:3001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } server { listen 80; server_name gotagit.sinfrontera.net; return 301 https://$host$request_uri; } ------- sudo ln -s /etc/nginx/sites-available/gotagit.sinfrontera.net /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx sudo systemctl restart nginx # Only if reload fails or Nginx behaves oddly