scp and ssh of GitHub Actions True Fragrance Series

Original link: https://qq52o.me/2817.html

github-actions.png

Although k8s is now used as a deployment service, some businesses still use the traditional method of using LNMP to deploy websites on the server.

This article is produced to solve the deployment problem. The scenario is as follows:

  1. R&D uses Git for development collaboration;
  2. Continuous deployment of the test environment is required after submission;
  3. After the iteration is completed, it needs to go online;
  4. Not all R&D has a server environment;
  5. The production environment has a fixed site directory, does not use Git to pull the code, shares the directory, and uses Docker to deploy;
  6. The original deployment service was somewhat complicated.

test environment

The test environment is currently equivalent to my development environment, but the database is differentiated, one is a local database, and the other is a cloud database.

When developing locally, use the ftp function that comes with PhpStorm to upload.

After other research and development push codes, use webhook to perform pull operations.

webhook here uses sy-records/git-deploy developed by me to automatically pull code and support GitHub, Gitee, GitLab and Gitea.

Need to rely on PHP and Swoole environment, if not, you can also use swoole-cli to start directly.

Production Environment

Before deploying the production environment, some packaging operations are required. This is also implemented in Actions , but the problem lies in how to deploy.

At first, I thought about configuring public and private keys and the like, and then copied and decompressed.

It didn’t work after I tried it, so I asked my colleagues and recommended a ssh-action for executing remote ssh commands.

 name: remote ssh command on: [push] jobs: build: name: Build runs-on: ubuntu-latest steps: - name: executing remote ssh commands using password uses: appleboy/[email protected] with: host: $ username: $ password: $ port: $ script: whoami

This action can execute remote ssh through password or private key. The specific use can be considered by yourself. For me, it can perform decompression and other operations, but I didn’t use this in the end.

I looked through the author’s GitHub and found that there is another scp-action , which is more in line with my needs: copy the compressed code package to another download machine, and then download it from the production environment, and then Unzip for deployment.

 scp $(PROJECT)-$(COMMIT).tar.gz [email protected]:/home/lufei/workspace/download/web

Change to action:

 - name: copy file to download uses: appleboy/[email protected] with: host: $ username: $ password: $ port: 22 source: '*.tar.gz' target: '/home/lufei/workspace/download/web'

The above also simplifies a lot of operations. Now the deployment only needs to go to the server, execute a PHP script, and write the download link to deploy.

Of course, it can also be deployed directly based on ssh-action operation, but due to other reasons, it is manually executed.

This article is transferred from: https://qq52o.me/2817.html
This site is only for collection, and the copyright belongs to the original author.