据GitLab网站所述,可以在将代码推送到存储库后使用其进行自动部署,但我无法弄清楚如何操作。虽然有很多Ruby教程,但没有Meteor或Node的相关内容。
基本上,我只需要在将代码推送到主分支后重建我的服务器上的Docker容器。有人知道如何实现吗?我对.gitlab-ci.yml不熟悉,非常感谢帮助。
据GitLab网站所述,可以在将代码推送到存储库后使用其进行自动部署,但我无法弄清楚如何操作。虽然有很多Ruby教程,但没有Meteor或Node的相关内容。
基本上,我只需要在将代码推送到主分支后重建我的服务器上的Docker容器。有人知道如何实现吗?我对.gitlab-ci.yml不熟悉,非常感谢帮助。
在 DO droplet 上安装 Meteor。
在 DO 上安装 Gitlab(如果可能,请使用一键部署),或手动安装。确保您正在安装 Gitlab v.8.3.4 或更高版本。我已经在我的 droplet 上进行了一键部署。 启动 gitlab 服务器,并从浏览器登录 gitlab。打开您的项目,然后转到左侧菜单中的项目设置 -> Runners。
SSH to your DO server & configure a new upstart service on the droplet as root:
vi /etc/init/meteor-service.conf
示例文件:
#upstart service file at /etc/init/meteor-service.conf
description "Meteor.js (NodeJS) application for eaxmple.com:3000"
author "rohanray@gmail.com"
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on shutdown
# Automatically restart process if crashed
respawn
respawn limit 10 5
script
export PORT=3000
# this allows Meteor to figure out correct IP address of visitors
export HTTP_FORWARDED_COUNT=1
export MONGO_URL=mongodb://xxxxxx:xxxxxx@example123123.mongolab.com:59672/meteor-db
export ROOT_URL=http://<droplet_ip>:3000
exec /home/gitlab-runner/.meteor/packages/meteor-tool/1.1.10/mt-os.linux.x86_64/dev_bundle/bin/node /home/gitlab-runner/erecaho-build/server-alpha-running/bundle/main.js >> /home/gitlab-runner/erecaho-build/server-alpha-running/meteor.log
end script
Install gitlab-ci-multi-runner from here: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/linux-repository.md as per the instructions Cheatsheet:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
sudo apt-get install gitlab-ci-multi-runner
sudo gitlab-ci-multi-runner register
Enter details from step 2
Now the new runner should be green or activate the runner if required
Create .gitlab-ci.yml within the meteor project directory
Sample file:
before_script:
- echo "======================================"
- echo "==== START auto full script v0.1 ====="
- echo "======================================"
types:
- cleanup
- build
- test
- deploy
job_cleanup:
type: cleanup
script:
- cd /home/gitlab-runner/erecaho-build
- echo "cleaning up existing bundle folder"
- echo "cleaning up current server-running folder"
- rm -fr ./server-alpha-running
- mkdir ./server-alpha-running
only:
- master
tags:
- master
job_build:
type: build
script:
- pwd
- meteor build /home/gitlab-runner/erecaho-build/server-alpha-running --directory --server=http://example.org:3000 --verbose
only:
- master
tags:
- master
job_test:
type: test
script:
- echo "testing ----"
- cd /home/gitlab-runner/erecaho-build/server-alpha-running/bundle
- ls -la main.js
only:
- master
tags:
- master
job_deploy:
type: deploy
script:
- echo "deploying ----"
- cd /home/gitlab-runner/erecaho-build/server-alpha-running/bundle/programs/server/ && /home/gitlab-runner/.meteor/packages/meteor-tool/1.1.10/mt-os.linux.x86_64/dev_bundle/bin/npm install
- cd ../..
- sudo restart meteor-service
- sudo status meteor-service
only:
- master
tags:
- master
Check in above file in gitlab. This should trigger Gitlab CI and after the build process is complete, the new app will be available @ example.net:3000