An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
Deploy nestjs project to VPS with dokku
Buy VPS
Search VPS or VDS in google
https://www.google.com/search?q=vps+vds+server
I choice this https://ztv.su/aff.php?aff=526 for Russia
Go to https://ztv.su/register.php?language=english
Select OS Ubuntu as OS for this server
Go to main dashboard https://ztv.su/clientarea.php
Wait 20 minuts...
Tune remote access
Open vscode and install ms-vscode-remote.vscode-remote-extensionpack
Add your local SSH key to new VPS from Windows PC
PS C:\Users\Admin> cat ~/.ssh/id_rsa.pub | ssh root@enter-server-ip-address "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"The authenticity of host 'enter-server-ip-address (enter-server-ip-address)' can't be established.ECDSA key fingerprint is SHA256:ShA-KeyY.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'enter-server-ip-address' (ECDSA) to the list of known hosts.root@enter-server-ip-address's password:
Connect to remote server with vscode
Click to PLUS and add new connection to ssh server
After connect you can see remote console and ip of server in left buttom panel
Tune server
Install all needed software
Update OS
sudo apt-get updatesudo apt-get upgradesudo apt-get dist-upgradesudo apt autoremovesudo apt install -f
Install dokku to server
wget https://raw.githubusercontent.com/dokku/dokku/v0.26.8/bootstrap.sh
sudo DOKKU_TAG=v0.26.8 bash bootstrap.sh
Wait...
Create application and add deploy script from github
Create application
dokku apps:create kaufman-bot
root@vpsXXXX:~# dokku apps:create kaufman-bot-----> Creating kaufman-bot...
Create ssh key for github in VPS
mkdir github
ssh-keygen -C "github" -f github/id_rsa
root@vpsXXXX:~# mkdir githubroot@vpsXXXX:~# ssh-keygen -C "github" -f github/id_rsaGenerating public/private rsa key pair.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in github/id_rsaYour public key has been saved in github/id_rsa.pubThe key fingerprint is:SHA256:HASH githubThe key's randomart image is:+---[RSA 3072]----+| .o*oo. |+----[SHA256]-----+
Add created public key to VPS authorized_keys
cat github/id_rsa.pub >> ~/.ssh/authorized_keys
Add created public key to dokku
dokku ssh-keys:add github ./github/id_rsa.pub
Show and copy private key
cat > github/id_rsa
Add server address to secret env in github
Add ci config for github .github/workflows/develop.deploy.yml
name: 'deploy'# yamllint disable-line rule:truthyon: push: branches: - feature/73jobs: deploy: runs-on: ubuntu-latest environment: dev steps: - name: Cloning repo uses: actions/checkout@v2 with: fetch-depth: 0 - name: Push to dokku uses: dokku/github-action@master with: branch: 'feature/73' git_remote_url: 'ssh://dokku@${{secrets.HOST}}:22/kaufman-bot' ssh_private_key: ${{secrets.SSH_PRIVATE_KEY}}
Add environment values in dokku server
dokku config:set kaufman-bot TELEGRAM_BOT_TOKEN=........................
root@vpsXXXX:~# dokku config:set kaufman-bot TELEGRAM_BOT_TOKEN=........................-----> Setting config vars TELEGRAM_BOT_TOKEN: ........................-----> Restarting app kaufman-bot ! App image (dokku/kaufman-bot:latest) not found
Run redeploy failed pipeline in github
After correct deploy, pipeline mark as green badge
Disable bot in heroku
Original Link: https://dev.to/endykaufman/deploy-nestjs-project-to-vps-with-dokku-31c5
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To