summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 2a5215eadac15b2df46ff873d21a929ab5e2843b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 自定义生命周期
stages:
  - gen_git-log
  - build_project
  - test
  - build_image

cache:
  key:
    files:
      - package.json
  paths:
    - node_modules
#    - dist/

before_script:
  - export CNUI_TAG=$(date +%Y%m%d%H%M%S)

generate_git-log:
  stage: gen_git-log
  script:
    - if (( `grep git-log.html ./public/index.html | wc -l` == 0 )); then         sed -i 's+</body>+<a style="position:fixed;top:0;left:0;z-index:999;font-size:12px;color:transparent;text-decoration:none;display:none;" target="_blank" href="./git-log.html">R</a>\n</body>+g' ./public/index.html;         echo "添加更新记录链接"; fi;
    - echo "最近的100个提交记录"
    - echo "<!DOCTYPE html><html><head><meta charset='utf-8'></head><body><pre>" > ./public/git-log.html
    - "git log -100 --pretty=format:'%ad : %s' >> ./public/git-log.html"
    - echo "</pre></body></html>" >> ./public/git-log.html
    - echo "处理 git-log.html 结束"
  artifacts:
    paths:
      - public/index.html
      - public/git-log.html
  only:
    - dev
  tags:
    - galaxy


build_project:
  stage: build_project
  script:
    - echo "npm install ..."
    - npm install --save-dev --unsafe-perm
    - echo "npm run build"
    - npm run build
  artifacts:
    name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
    when: on_success
    paths:
      - dist/
  only:
    - dev
    - tags
  tags:
    - galaxy

test:
  stage: test
  script:
    - cnpm run test
  when: on_success
  only:
    - dev
  tags:
    - galaxy

build_image:
  dependencies:
    - build_project
  stage: build_image
  script:
    - echo "docker build"
    - sudo docker build --no-cache -t cn-ui-$CI_COMMIT_REF_NAME:$CNUI_TAG .
    - echo "docker tag"
    - sudo docker tag cn-ui-$CI_COMMIT_REF_NAME:$CNUI_TAG 192.168.40.153:9080/cyber-narrator/cn-ui-$CI_COMMIT_REF_NAME:$CNUI_TAG
    - echo "docker push"
    - sudo docker push 192.168.40.153:9080/cyber-narrator/cn-ui-$CI_COMMIT_REF_NAME:$CNUI_TAG
  when: on_success
  only:
    - dev
  tags:
    - galaxy


build_release_image:
  dependencies:
    - build_project
  stage: build_image
  script:
    - echo 'tag名称是'
    - echo $CI_COMMIT_TAG
    - echo '提交的版本是'
    - echo $CI_COMMIT_REF_NAME
    - echo "docker build"
    - sudo docker build --no-cache -t cn-ui:$CI_COMMIT_TAG .
    - echo "docker tag"
    - sudo docker tag cn-ui:$CI_COMMIT_TAG 192.168.40.153:9080/cyber-narrator/cn-ui:$CI_COMMIT_TAG
    - echo "docker push"
    - sudo docker push 192.168.40.153:9080/cyber-narrator/cn-ui:$CI_COMMIT_TAG
  only:
    - tags
  tags:
    - galaxy