繁体   English   中英

如何通过 github 操作创建 CI/CD Go 应用程序

[英]How can I create a CI/CD Go app through github actions

我想创建一个作业操作来构建 Go 应用程序并在 digitalocean 上的液滴中部署。 我正在尝试使用它,但是

name: Countinus Deployments

on:
push:
 branches: [ master ]
pull_request:
branches: [ master ]

build:
runs-on: ubuntu-latest

- name: Checkout the repository
  uses: actions/checkout@v2
- name: Set up Go 1.13
  uses: actions/setup-go@v1
  with: 
    go-version: 1.13
  id: go    

 - name: Deploy and rebuild on server
  uses: appleboy/ssh-action@master
  with:
    host: xxxxxxxxxxx
    username: root
    key: ${{ secrets.serverKey }}
    port: 22
    script: 
      cd go/victorydash/ && 
      git pull origin master && 
      git status && 
      echo $PATH && 
      go build -o app  main.go && 
      systemctl restart goweb.service &&
      systemctl status goweb     

但是这些代码“go build -o app main.go &&”没有在服务器上构建有谁知道任何解决方案?

在 YAML 文件中你想要什么以及你在写什么不是很清楚。 我猜你需要在数字海洋上部署应用程序。

  1. 构建 golang 二进制文件 - 你实际上有 actions/setup-go@v1 。
  2. 通过 SCP 在数字海滴上复制文件。 scp 文件
  3. 使用 appleboy/ssh-action 重新启动服务 - 已经有了。

如果您想直接在主机上构建和部署 - 您需要手动克隆 repo 并安装 golang。 所以使用动作没有任何意义(仅用于触发)

我已经找到了解决方案

runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout the repository
  uses: actions/checkout@v2

- name: Set up Go 1.13
  uses: actions/setup-go@v1
  with: 
    go-version: 1.13         

- name: Build app 
  run: go build -o app main.go

- name: SCP to Ocean
  uses: appleboy/scp-action@master
  with:
    host: ${{ secrets.host }}
    username: ${{ secrets.user }}
    key: ${{ secrets.serverKey }}
    port: 
    source: "app"         
    target: "dist"    

- name: Deploy and rebuild on server
  uses: appleboy/ssh-action@master
  with:
    host: ${{ secrets.host }}
    username: ${{ secrets.user }}
    key: ${{ secrets.serverKey }}
    port: ${{ secrets.port }}
    script:           
      systemctl restart goweb.service &&
      systemctl status goweb       

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM