- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个配置了 GitLab CE 的 AWS Ubuntu 实例。现在我想配置 GitLab CI 以在每次提交后部署我的 NodeJS 应用程序。我没有任何适当的分步解决方案。
我的 NodeJS 应用程序在 /var/www/mean/my-app
中运行在 http://myapp.mydomain.com
并且托管由 Apache 代理处理,
<VirtualHost *:80>
ServerAdmin anshad@mydomain.com
ServerName gitlab.mydomain.com
ServerAlias www.gitlab.mydomain.com
ServerSignature Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Location />
Require all granted
ProxyPassReverse http://localhost:8080
ProxyPassReverse http://gitlab.mydomain.com/
</Location>
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\" %>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
</VirtualHost>
forever start app.js
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
给,
Checking GitLab Shell ...
GitLab Shell version >= 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 >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.3.1)
Your git bin path is "/usr/bin/git"
Git version >= 2.7.3 ? ... yes (2.7.4)
Active users: 1
Checking GitLab ... Finished
ssh -i API-Key.pem ubuntu@ec2-XX-XX-XXX-XXX.ap-south-1.compute.amazonaws.com
ssh-keygen -t rsa
/etc/gitlab-runner/config.toml
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]
.gitlab-ci.yml
test_async:
script:
- npm install
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 ...
.gitlab-ci.yml
的内容应该是什么文件将提交的代码部署到应用程序位置?
ssh
runner,那边应该是什么配置?
.pem
文件为
identity_file
,得到以下错误
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: ()
最佳答案
在你的/etc/gitlab-runner/config.toml
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]
你定义
ssh-copy-id
例如,我想在我的 gitlab 和我的构建主机之间设置无密码的 ssh 身份验证。
[root@gitlab ~]# ssh-copy-id -i /home/ubuntu/.ssh/id_rsa.pub ubuntu@build.home
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ubuntu@build.home's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'ubuntu@build.home'"
and check to make sure that only the key(s) you wanted were added.
请注意,在上面的示例中,我将公钥推送到远程主机。
[root@gitlab ~]# ssh -i /home/ubuntu/.ssh/id_rsa ubuntu@build.home
[ubuntu@build ~]$ hostname
build.home
尝试在 gitlab 主机和远程主机之间测试您的公钥身份验证并更新您的问题。
yum install gitlab-ci-multi-runner
并将我的远程 sshbuild.home VM 注册为 ssh runner
[root@gitlab gitlab-runner]# ssh-copy-id 192.168.0.43
The authenticity of host '192.168.0.43 (192.168.0.43)' can't be established.
ECDSA key fingerprint is b4:6a:1b:72:d1:7d:1f:34:f7:bb:ef:ad:69:42:11:13.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.0.43's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.0.43'"
and check to make sure that only the key(s) you wanted were added.
[root@gitlab gitlab-runner]# ssh 192.168.0.43
Last login: Fri Nov 18 17:05:06 2016 from 192.168.0.101
[root@sshbuild ~]# exit
然后我禁用了我的另一个运行器(shell 运行器)并创建了特定的新 SSH 运行器项目,以确保当我提交时 - 它会在 ssh 运行器上执行
[root@gitlab gitlab-runner]# cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[[runners]]
name = "sshbuild"
url = "http://gitlab.home/"
token = "2bc1825d8fbde09fd632637c60e9e7"
executor = "ssh"
[runners.ssh]
user = "root"
host = "192.168.0.43"
port = "22"
identity_file = "/root/.ssh/id_rsa"
[runners.cache]
P.S:如果我在 Web 界面的“设置”下为我的存储库禁用 HTTP,我会遇到与您类似的错误。但是错误不是 500,而是 403。
1 const http = require('http');
2
3 const hostname = '0.0.0.0';
4 const port = 3000;
5
6 const server = http.createServer((req, res) => {
7 res.statusCode = 200;
8 res.setHeader('Content-Type', 'text/plain');
9 res.end('Hello World!\n');
10 });
11
12 server.listen(port, hostname, () => {
13 console.log(`Server running at http://${hostname}:${port}/`);
14 });
我的目标是能够针对它运行测试用例。在这种情况下,我将运行简单
curl localhost:3000 | grep "Hello World"
但是我需要将它放入一个单独的脚本中,该脚本成功时退出状态为 0,失败时退出状态为非零
cat -n simpletest.sh
1 #!/bin/bash
2
3 cleanup ()
4 {
5 count=`netstat -anp|grep ":3000"|grep LISTEN|awk '{print $NF}'|cut -d\/ -f1|wc -l`
6 if [ $count -ne 0 ]
7 then
8 pid=`netstat -anp|grep ":3000"|grep LISTEN|awk '{print $NF}'|cut -d\/ -f1`;
9 echo "Need to kill PID $pid";
10 kill $pid
11 fi
12 }
13
14 echo "Running simple test"
15 curl localhost:3000|grep "Hello World"
16 if [ $? -eq 0 ]
17 then
18 echo "Test was successfull"
19 echo "Clean up node.js process"
20 cleanup
21 exit 0
22 else
23 echo "Test failed"
24 echo "Clean up node.js process"
25 cleanup
26 exit 1
27 fi
现在让我们介绍我的 .gitlab-ci.yml
cat -n .gitlab-ci.yml
1 test:
2
3 before_script:
4 - echo "Before script"
5 - hostname
6 - /bin/bash cleanup.sh
7
8 script:
9 - echo "Main Script"
10 - node server.js &
11 - sleep 3
12 - /bin/bash simpletest.sh
我有一个名为 test.In before_script 的工作,它运行 cleanup.sh 脚本,如果发现这种情况,它会简单地终止监听端口 3000 的 PID。
cat -n cleanup.sh
1 #!/bin/bash
2 count=`netstat -anp|grep ":3000"|grep LISTEN|awk '{print $NF}'|cut -d\/ -f1|wc -l`
3 if [ $count -ne 0 ]
4 then
5 pid=`netstat -anp|grep ":3000"|grep LISTEN|awk '{print $NF}'|cut -d\/ -f1`;
6 echo "Need to kill PID $pid";
7 kill $pid
8 fi
9 exit 0
在脚本下:它使用我的 server.js 运行 Node ,给它 3 秒的时间来启动,然后针对它运行测试。该测试还将在测试完成后处理终止 Node PID。
cat -n .gitlab-ci.yml
1 stages:
2 - test
3 - deploy
4
5 run_test_case:
6 stage: test
7 before_script:
8 - echo "Before script"
9 - hostname
10 - /bin/bash cleanup.sh
11
12 script:
13 - echo "Main Script"
14 - node server.js &
15 - sleep 3
16 - /bin/bash simpletest.sh
17
18 deploy_to_production:
19 stage: deploy
20 script:
21 - echo "Run code here to do production deployment"
22 environment:
23 name: production
git push 会成功。在第 21 行,我只是运行了 echo,但这可以替换为一个脚本,该脚本将推送到您的远程登台或生产环境。
关于node.js - 在 AWS Ubuntu 实例中为 NodeJS 部署设置 GitLab CI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40513215/
我正在尝试使用以下命令在远程 Ubuntu 服务器的后台运行进程: sshpass -p PASSWORD ssh root@HOST 'nohup COMMAND-THAT-BLOCKS &' 不幸
普通 Ubuntu 和 ARM Ubuntu 有什么区别。我可以运行所有应用程序吗也在 ARM Ubuntu 中的普通 Ubuntu 下运行? Ubuntu 更新会自动发生吗? Torrent 下载器
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我正在尝试预置 Xenial 图像,它工作得很好,除了分区。 cloud-init 只能增长根分区,并且在使用扩展分区内的根文件系统构建镜像时不起作用: NAME MAJ:MIN RM SIZ
我对 Ubuntu 和 OpenFoam 真的很陌生,所以尝试学习并做一些教程。我正在使用 Docker 在 Ubuntu 上使用 OpenFoam。 我将文件夹复制到特定目录,但是当我尝试使用终端访
我在使用系统启动设置运行软件时遇到问题。我有 ubuntu 20.04。我试图将这些行插入到 etc/rc.local #!/bin/bash /usr/bin/clamonacc 它不起作用。第二次
TARGETS = client server CL_OBJ = clientMain.o Controller.o UI.o List.o Movie.o Server.o Serializer.o
我有一个 ubuntu服务器系统是8.04 hardy ,我在哪里安装rabbitmq。 rabbitmq依赖于 erlang-nox (>= 1:12.b.3) ,但是在当前的 ubuntu 版本中
我有一个用于开发的 Ubuntu virtualbox 设置。当我在文件中处于 org-mode 时,org-mode 的任何热键都不起作用(例如 M-RETURN 用于创建新标题)。我该怎么做才能让
我的 SchemaCrawler(版本 15.01.03)模式图在 Ubuntu 18.04 LTS 上截断表名。看起来表格通常被画得太窄,因为“[TABLE]”符号也开箱即用。在我的 Mac 上渲染
在 Ubuntu 中,设置应用程序中有几个地方有一个非常漂亮的 ListView ,带有添加/删除按钮,包括外观、键盘布局、隐私、蓝牙等。他们使用什么小部件?我开始使用 Glade 开发我的第一个 U
需要帮助卸载 jjrofiler。没有意识到它需要许可证。通过 .sh 可执行文件安装。 最佳答案 如果您转到 jProfiler 安装目录,您将找到名为 uninstall 的可执行文件,只需从终端
我一直在寻找几天,我没有想出解决方案。我是 ruby 新手,但我想通过使用 spree 开发自己的在线商店。 我使用:rails:Rails 3.2.13 ruby :ruby-1.9.3-p42
我尝试使用以下命令从/usr/local/bin 中删除我的 python2.7 和 python3 文件夹:sudo rm -rf python2.7 和 sudo rm -rf python3。后
在 ubuntu 服务器中(使用 ssh 协议(protocol)), 如何更改因不活动而断开连接的时间? 最佳答案 你能在 .bash_profile 中加入“exec screen -R”,在 .
我使用以下配置在 /etc/apache2/site-available/mysite.local 中创建了一个虚拟主机: ServerAdmin webmaster@localhost
我为大约 210 个用户新设置了一个代理服务器。它运行 ubuntu server 2012 和 squid3。问题是在凌晨 1:30 之后,如果用户尝试打开 google.com、youtube.c
gitlab-ci-multi-runner 1.0.2 (ea19241) Using Shell executor... Running on ip-... Cloning repository.
我有一个备份服务器,它每小时接收许多 rsync 连接。由于打开太多 rsync 实例可能会导致崩溃,我想使用 Semaphore 来限制并发实例的数量。 .我的想法是这样的: ssh root@ba
我有同一个库的多个版本,我的程序动态链接到这些库。有时我想更改使用的版本。 我一直在阅读,出于安全原因,新版本的 Ubuntu 不再支持 LD_LIBRARY_PATH。我可以将路径添加到 /etc/
我是一名优秀的程序员,十分优秀!