Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 21, 2022 04:44 am GMT

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
Reg user

After login
After login

Click to create new server
Click to create new server

Open menu
Open menu

Select SSD type of VPS
Select SSD type of VPS

Select type of server
Select type of server

Select OS Ubuntu as OS for this server
Select OS Ubuntu as OS for this server

Order confirmation after pay
Order confirmation after pay

Go to main dashboard https://ztv.su/clientarea.php

Wait 20 minuts...

Tune remote access

Click to new your server
Click to new your server

Copy ip and password
Copy ip and password

Open vscode and install ms-vscode-remote.vscode-remote-extensionpack
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:

Add your local SSH key to new VPS from Windows PC

Connect to remote server with vscode
Connect to remote server with vscode

Click to PLUS and add new connection to ssh server
Click to PLUS and add new connection to ssh server

Select Linux platform
Select Linux platform

After connect you can see remote console and ip of server in left buttom panel
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
Show and copy private key

Create environment in github
Create environment in github

Add created key to github
Add created key to github

Add server address to secret env in github
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

Add environment values in dokku server

Run redeploy failed pipeline in github
Run redeploy failed pipeline in github

After correct deploy, pipeline mark as green badge
After correct deploy, pipeline mark as green badge

Disable bot in heroku

Disable bot in heroku

Test from telegram
Test from telegram

https://telegram.me/DevelopKaufmanBot


Original Link: https://dev.to/endykaufman/deploy-nestjs-project-to-vps-with-dokku-31c5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To