溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

golang語(yǔ)言項(xiàng)目是如何配置Gitlab CI的

發(fā)布時(shí)間:2021-12-08 15:11:16 來(lái)源:億速云 閱讀:273 作者:iii 欄目:編程語(yǔ)言

這篇文章主要講解了“golang語(yǔ)言項(xiàng)目是如何配置Gitlab CI的”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“golang語(yǔ)言項(xiàng)目是如何配置Gitlab CI的”吧!

pipeline流程

  • 使用golangci-lint 檢查代碼

  • 編譯代碼

  • 部署二進(jìn)制

before_script 設(shè)置環(huán)境變量

主要 GOPROXY設(shè)置

before_script:
  - echo "before_script"
  - git version
  - go env -w GOPRIVATE=code.haiziwang.com
  - mkdir -p .go
  - go version
  - go env -w GO111MODULE=on
  - go env -w GOPROXY="https://goproxy.io,direct"

golangci-lint

默認(rèn)集成了很多開(kāi)箱即用的linter

golang語(yǔ)言項(xiàng)目是如何配置Gitlab CI的

https://golangci-lint.run/

golangci-lint:
    image: golangci/golangci-lint:v1.27.0
    stage: lint
    extends: .go-cache
    allow_failure: true
    script:
      - golangci-lint run -v

allow_failure 表示失敗了可以繼續(xù)跑后續(xù)的job

編譯

compile:
    stage: build
    extends: .go-cache
    script:
      - go mod download
      - go build -race -o $OUTPUT_NAME
    artifacts:
      paths:
        - $OUTPUT_NAME

緩存 go mod

.go-cache:
    variables:
        GOPATH: $CI_PROJECT_DIR/.go
    cache:
      paths:
        - .go/pkg/mod/

full example

# This file is a template, and might need editing before it works on your project.
image: hub-mirror.c.163.com/library/golang:latest

.go-cache:
    variables:
        GOPATH: $CI_PROJECT_DIR/.go
    cache:
      paths:
        - .go/pkg/mod/

variables:
  OUTPUT_NAME: helloworld-app

stages:
    - lint
    - build
    - deploy

before_script:
  - echo "before_script"
  - git version
  - go env -w GOPRIVATE=code.haiziwang.com
  - mkdir -p .go
  - go version
  - go env -w GO111MODULE=on
  - go env -w GOPROXY="https://goproxy.io,direct"

golangci-lint:
    image: golangci/golangci-lint:v1.27.0
    stage: lint
    extends: .go-cache
    allow_failure: true
    script:
      - golangci-lint run -v

compile:
    stage: build
    extends: .go-cache
    script:
      - go mod download
      - go build -race -o $OUTPUT_NAME
    artifacts:
      paths:
        - $OUTPUT_NAME

deploy-dev:
    stage: deploy
    script:
      - echo "deploy dev environment"

感謝各位的閱讀,以上就是“golang語(yǔ)言項(xiàng)目是如何配置Gitlab CI的”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)golang語(yǔ)言項(xiàng)目是如何配置Gitlab CI的這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI