Setting GitLab CI for NodeJS deployment in AWS Ubuntu Instance
<p>I have an AWS Ubuntu instance which has GitLab CE configured. Now I want to configure GitLab CI to deploy my NodeJS app after each commit.I don't have any proper step by step solution for this.</p>

<p>My NodeJS app running in <code>/var/www/mean/my-app</code> on <code>http://myapp.mydomain.com</code> and the hosting is handled by Apache Proxy,</p>

<pre><code>&lt;VirtualHost *:80&gt;
    ServerAdmin anshad@mydomain.com
    ServerName gitlab.mydomain.com
    ServerAlias www.gitlab.mydomain.com

    ServerSignature Off

    ProxyPreserveHost On

    AllowEncodedSlashes NoDecode

    &lt;Location /&gt;
       Require all granted
       ProxyPassReverse http://localhost:8080
       ProxyPassReverse http://gitlab.mydomain.com/
    &lt;/Location&gt;

    RewriteEngine on

    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_URI} ^/uploads/.*
    RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA,NE]

    DocumentRoot /home/git/gitlab/public

    LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %&gt;s %b" common_forwarded
    ErrorLog /var/log/apache2/gitlab_error.log
    CustomLog /var/log/apache2/gitlab_forwarded.log common_forwarded
    CustomLog /var/log/apache2/gitlab_access.log combined env=!dontlog
    CustomLog /var/log/apache2/gitlab.log combined
 &lt;/VirtualHost&gt;
</code></pre>

<p>And the app is bootstrapped using forever module </p>

<pre><code>forever start app.js
</code></pre>

<p>The gitlab config check <code>sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production</code> gives,</p>

<pre><code>Checking GitLab Shell ...

GitLab Shell version &gt;= 4.0.0 ? ... OK (4.0.0)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ... 
dev / my-app ... ok
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /home/git/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured with autocrlf=input? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory setup correctly? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ... 
dev / my-app ... yes
Redis version &gt;= 2.8.0? ... yes
Ruby version &gt;= 2.1.0 ? ... yes (2.3.1)
Your git bin path is "/usr/bin/git"
Git version &gt;= 2.7.3 ? ... yes (2.7.4)
Active users: 1

Checking GitLab ... Finished
</code></pre>

<p>I used to login to the instance using SSH from my system,</p>

<pre><code>ssh -i API-Key.pem ubuntu@ec2-XX-XX-XXX-XXX.ap-south-1.compute.amazonaws.com
</code></pre>

<p>Created key using command</p>

<pre><code>ssh-keygen -t rsa
</code></pre>

<p>Runner config on <code>/etc/gitlab-runner/config.toml</code></p>

<pre><code>concurrent = 1
check_interval = 0

[[runners]]
  name = "Production Runner"
  url = "http://gitlab.mydomain.com/ci"
  token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
  executor = "ssh"
  [runners.ssh]
    user = "ubuntu"
    host = "ip-XXX-XX-XX-XXX"
    identity_file = "/home/ubuntu/.ssh/id_rsa"
  [runners.cache]
</code></pre>

<p>Code on <code>.gitlab-ci.yml</code></p>

<pre><code>test_async:   
 script:    
  - npm install
</code></pre>

<p>Because of my bad configuration, the runner gives error,</p>

<pre><code>Running with gitlab-ci-multi-runner 1.7.1 (f896af7)
Using SSH executor...
ERROR: Preparation failed: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
Will be retried in 3s ...
</code></pre>

<p>My confusions are:</p>

<p>What should be the content of <code>.gitlab-ci.yml</code> file to deploy the committed code to the application location? </p>

<p>And how to configure a runner for this? If I have to use an <code>ssh</code> runner, what should be the configurations over there?</p>

<p><strong>Update:</strong></p>

<p>After providing <code>.pem</code> file as <code>identity_file</code>, getting the following error</p>

<pre><code>Running with gitlab-ci-multi-runner 1.7.1 (f896af7)
Using SSH executor...
Running on ip-xxx-xx-xx-xxx via ip-xxx-xx-xx-xxx...
Cloning repository...
Cloning into 'builds/a92f1b91/0/dev/my-app'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.mydomain.com/dev/my-app.git/': The requested URL returned error: 500
ERROR: Build failed: Process exited with: 1. Reason was:  ()
</code></pre>

<p>Now there is a problem, git clone with http not working but ssh cloning works.</p>

<p><strong>Note:</strong> Both gitlab and build environment are same host (same aws instance)</p>

<p><a href="https://gitlab.com/gitlab-org/gitlab-ce/issues/24388" rel="nofollow noreferrer">Bug</a> reported in GitLab as well (http clone issue).</p>