Gitlab CI如何通过SSH部署应用程序 [英] Gitlab CI how to deploy an application via SSH
问题描述
我正在使用Hosted Gitlab来托管我的Git存储库,最近,我一直在使用它来将PHP和Java应用程序构建/部署到服务器.
我想做的是一旦构建完成,就使用SSH部署应用程序.有时,这可能只是通过SSH将最终版本的内容(PHP文件)上传到服务器,而有时它可能是上传已编译的.jar文件,然后在远程服务器上执行命令以重新启动服务.>
我已经将自己的Docker容器设置为构建环境,其中包括Java,PHP,Composer和Maven之类的内容,这些都是我完成构建所需要的.我正在使用此图像来运行构建.
我想知道的是,如何执行我可以在gitlab-ci.yaml文件中指定的部署命令的SSH到外部服务器?
您可以将SSH密钥作为秘密变量存储在 gitlab-ci.yaml
中,并在构建过程中使用它来执行SSH命令,有关更多详细信息,请参见我们的文档此处.
一旦拥有SSH访问权限,就可以使用诸如 rsync
和 scp
之类的命令将文件复制到服务器上.我在此处的另一篇文章中找到了一个示例可以作为参考.
I'm using Hosted Gitlab to host my Git repositories, and more recently I've been using it to build/deploy PHP and Java applications to servers.
What I'd like to do is once a build is complete, deploy the application using SSH. Sometimes this might just be uploading the contents of the final build (PHP files) to a server via SSH, or other times it may be uploading a compiled .jar file and then executing a command on the remote server to restart a service.
I've set up my own Docker container as a build environment, this includes things such as Java, PHP, Composer, and Maven all that I need for builds to complete. I'm using this image to run builds.
What I'd like to know is, how can I SSH into an external server in order to perform deployment commands that I can specify in my gitlab-ci.yaml file?
You can store your SSH key as a secret variable within gitlab-ci.yaml
and use it during your build to execute SSH commands, for more details please see our documentation here.
Once you have SSH access you can then use commands such as rsync
and scp
to copy files onto your server. I found an example of this in another post here which you can use as a reference.
这篇关于Gitlab CI如何通过SSH部署应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!