Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ilmsg/725f050f5dc4c428e06f85de4957b32b to your computer and use it in GitHub Desktop.
Save ilmsg/725f050f5dc4c428e06f85de4957b32b to your computer and use it in GitHub Desktop.

Revisions

  1. @zdtsw zdtsw created this gist Dec 4, 2019.
    101 changes: 101 additions & 0 deletions simple gitlab-ci pipeline (on golang)
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,101 @@
    Below is a simple exmple of how to use gitlab ci
    you need to have two different runner: one windows with tag "windows" and one linux with tag "linux"
    the pipeline basically try to do
    -some go static check
    -build go app on both window and linux parallel
    -run int test
    -deploy goapp to qa1 and qa2 parallel
    -deploy to production

    there is a lot room to improve this, say, qa1 could be a windows qa2 could be a linux, say, we do not really need runner but can use
    golang docker image instead etc etc
    but the purpose of this , is to show how gitlab-ci works and see if it is an option to replace our jenkins pipeline
    ##############################################################################################################

    >$git_root/.gitlab-ci.yml

    variables:
    REPO_NAME: git.comhem.com/devliery-tools/dashing-delivery-dashboard-onk8

    before_script:
    - echo "start job at :" `date`
    - echo "workspace is:" `pwd`

    after_script:
    - echo "done job at :" `date`

    stages:
    - check
    - build
    - integration
    - deployci
    - deployqa
    - prod

    syntaxcheck:
    stage: check
    script:
    - mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
    - ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
    - cd $GOPATH/src/$REPO_NAME
    - go fmt
    - go vet
    - go lint


    windows build:
    stage: build
    tags:
    - windows
    script:
    - GOOS=windows GOARCH=386 go build -o gojira-amd32
    - GOOS=windows GOARCH=amd64 go build -o gojira-amd64
    only:
    - master

    Linux build:
    stage: build
    tags:
    - linux
    script:
    GOOS=linux GOARCH=amd64 go build -o gojira
    only:
    refs:
    - master

    intergration test:
    stage: integration
    script:
    - echo "doing some test thing"

    deploy ci1:
    variables:
    env: ci1
    stage: deployci
    script:
    - echo "deploy it to ${env} "


    deploy qa2:
    variables:
    env: qa2
    stage: deployqa
    script:
    - echo "deploy it to ${env} "

    deploy qa1:
    variables:
    env: qa1
    stage: deployqa
    script:
    - echo "deploy it to ${env} "

    deploy prod:
    variables:
    env: prod
    stage: prod
    script:
    - echo "deploy it to ${env}"
    after_script:
    - echo "production deploy done"