D
D
Dimka52018-09-19 15:31:06
linux
Dimka5, 2018-09-19 15:31:06

How to set up a non-root server and a Caistrano configuration file for a NodeJS project in order to deploy the application successfully?

I say right away that I’m new to all this, I’m doing it all for the first time, I don’t know how it should be, so I want the most detailed answer.
I want to deploy a NodeJS application on a test server, and then on a production one.
What I want and what I have now
K -
K1 computer - on Windows, here I edit the code in VSCode and from here I write cap ... deployand get remote access via SSH to the rest of
K2 - a virtual machine with CentOS 6.1 is configured and GitLab is running on it with the project repository already loaded, created user with administrator rights (nameusr ALL=(ALL) ALL), not added to the wheel group (it seems more secure), remote access to root is closed
K3 - virtual machine with CentOS 6.1 is a test application server, there is nvm, node, npm, compiled by Git (2.19.0), nginx, the user is made in the same way
K4 - VPS server, combat, until it is activated, I train on the test.
I set everything up myself. I would like to get closer to the real development.
So on K1, a project with Git connected and with Capistrano for deployment. I don’t understand what to write in configs deploy.rb, production.rband how to create and make some work dev.rb, I don’t understand what they should be. However, when I used root on the machines, I wrote cap production deployand everything worked somehow, changed to other users, access errors immediately went on, I decided many and ran into the last one, I don’t know how to allow access (with linux there is almost no experience).
(names are not really true)

# Файл deploy.rb
lock "~> 3.11.0"

set :application, "nameproject"
set :repo_url, "http://000.000.000.002/root/nameproject.git" # Это K2
set :password, "****" # Тут я сделал пароль что бы постоянно его не вводить но так не делают, верно?
# Какой-то SSH ключ надо? как это делается? куда его в Capistrano вписывать?

# Путь на К3 где хранится проект
set :deploy_to, "/var/www/nameproject/data/www/nameproject"

task :dev do
  on "[email protected]" do # настроен на К3
    execute "node #{release_path}/index.js" # пока без PM2 просто через node
  end
end

after "deploy:cleanup", :dev # Получилось запустить приложение после этого шага,
# после какого надо не знаю, подскажите

# Файл production.rb # Но по существу это должен быть dev.rb, я не знаю как Capistrano подхватывает
# файлы что бы написать cap dev deploy
server "000.000.000.003", user: "username", password: "****", roles: %w{app web}
# Тут тоже нужен SSH ключ? А его куда?

How to split into files and include dev.rb for K3 and production.rb for K4?
Error
Now, with these configs and server settings, an error occurs when executing with K1 cap production deployIt turns out that when executing the command
git ls-remote http://000.000.000.002/root/nameproject.git HEAD
with K3, that is, from the test server, as I understand it, there is a request to K2 where GitLab is and there are not enough rights for this, right, I understand? But if I log in via remote access to K3 and execute the same command, enter the login and password from the root (it is the default) account in GitLab, everything will work. I do not understand what to do with the rights?
PS D:\путь к проекту> cap production deploy
00:00 git:wrapper
      01 mkdir -p /tmp
    ✔ 01 [email protected] 10.899s
      Uploading /tmp/git-ssh-nameproject-production-winusr.sh 100.0%
      02 chmod 700 /tmp/git-ssh-nameproject-production-winusr.sh
    ✔ 02 [email protected] 0.421s
00:11 git:check
      01 git ls-remote http://000.000.000.002/root/nameproject.git HEAD
      01 remote: HTTP Basic: Access denied
      01 fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'
#<Thread:[email protected]:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.17.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as [email protected]: git
exit status: 128 (SSHKit::Runner::ExecuteError)
git stdout: Nothing written
git stderr: remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: git exit status: 128
git stdout: Nothing written
git stderr: remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'


Caused by:
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'

Tasks: TOP => deploy:check => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as [email protected]: git exit status: 128
git stdout: Nothing written
git stderr: remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


  INFO [24577c0e] Finished in 0.861 seconds with exit status 0 (successful).

  INFO [cb0a2907] Running /usr/bin/env git ls-remote http://000.000.000.002/root/nameproject.git HEAD as [email protected]

 DEBUG [cb0a2907] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/git-ssh-nameproject-production-winusr.sh" ; /usr/bin/env git ls-remote http://000.000.000.002/root/nameproject.git
HEAD )

 DEBUG [b9fda019]       remote: HTTP Basic: Access denied

fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'

  INFO ---------------------------------------------------------------------------

  INFO START 2018-09-19 13:45:48 +0300 cap production deploy

  INFO ---------------------------------------------------------------------------

  INFO [a8fe0d90] Running /usr/bin/env mkdir -p /tmp as [email protected]

 DEBUG [a8fe0d90] Command: /usr/bin/env mkdir -p /tmp

  INFO [fc9791c0] Finished in 10.899 seconds with exit status 0 (successful).

 DEBUG Uploading /tmp/git-ssh-nameproject-production-winusr.sh 0.0%

  INFO Uploading /tmp/git-ssh-nameproject-production-winusr.sh 100.0%

  INFO [1b17c9c5] Running /usr/bin/env chmod 700 /tmp/git-ssh-nameproject-production-winusr.sh as [email protected]

 DEBUG [1b17c9c5] Command: /usr/bin/env chmod 700 /tmp/git-ssh-nameproject-production-winusr.sh

  INFO [a7a946fa] Finished in 0.421 seconds with exit status 0 (successful).

  INFO [1c1909ea] Running /usr/bin/env git ls-remote http://000.000.000.002/root/nameproject.git HEAD as [email protected]

 DEBUG [1c1909ea] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/git-ssh-nameproject-production-winusr.sh" ; /usr/bin/env git ls-remote http://000.000.000.002/root/nameproject.git
HEAD )

 DEBUG [2f23f4d6]       remote: HTTP Basic: Access denied

fatal: Authentication failed for 'http://000.000.000.002/root/nameproject.git/'

help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2018-09-20
@Dimka5

1. No one will read such a stream of consciousness. Respect the people you ask questions - otherwise your question will simply be missed.
2. It is impossible to set up a server not from root.
(stream of consciousness skipped)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question