.gitlab-ci.yml 3.03 KB
Newer Older
jxtxzzw's avatar
jxtxzzw committed
1
image: node:latest
jxtxzzw's avatar
jxtxzzw committed
2

jxtxzzw's avatar
jxtxzzw committed
3
stages:
jxtxzzw's avatar
jxtxzzw committed
4 5 6 7
  - build
  - deploy
  - test

jxtxzzw's avatar
jxtxzzw committed
8
cache:
jxtxzzw's avatar
jxtxzzw committed
9
  key: resume
jxtxzzw's avatar
jxtxzzw committed
10
  paths:
jxtxzzw's avatar
jxtxzzw committed
11 12 13 14
    - node_modules/
    - assets/data/
    - static/data/

jxtxzzw's avatar
jxtxzzw committed
15
before_script:
jxtxzzw's avatar
jxtxzzw committed
16 17 18 19 20 21
  - mkdir -vp ~/.ssh
  - eval $(ssh-agent -s)
  - echo "${HOST_NAME}","${HOST_KEY}" > ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts -v
  - echo "${SSH_PRIVATE_KEY}" > ~/.ssh/key.pem
  - chmod 600 ~/.ssh/key.pem -v
jxtxzzw's avatar
jxtxzzw committed
22

jxtxzzw's avatar
jxtxzzw committed
23
load_resources:
jxtxzzw's avatar
jxtxzzw committed
24
  stage: .pre
jxtxzzw's avatar
jxtxzzw committed
25
  script:
jxtxzzw's avatar
jxtxzzw committed
26 27 28 29 30 31 32
    - ssh -i ~/.ssh/key.pem -v ${USER}@${HOST_NAME} "cd ${CICD_DIR} && sh ${SCRIPT_FILENAME}.sh"
    - rm -rfv ./assets/data
    - rm -rfv ./static/data
    - scp -i ~/.ssh/key.pem -rv ${USER}@${HOST_NAME}:${RESOURCES_DIR}/assets-data ./assets/data
    - scp -i ~/.ssh/key.pem -rv ${USER}@${HOST_NAME}:${RESOURCES_DIR}/static-data ./static/data
    - RESUME_DATE=`date +%Y-%m-%d`
    - echo ${RESUME_DATE}
jxtxzzw's avatar
jxtxzzw committed
33
    - echo sed \"s/\\\"updated\\\":[ ]*\\\"[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\\"/\\\"updated\\\":\\\"${RESUME_DATE}\\\"/g\" > ./update_time.sh
jxtxzzw's avatar
jxtxzzw committed
34 35 36 37
    - cat ./update_time.sh
    - cat ./assets/data/setting.json | sh ./update_time.sh > ./assets/data/setting2.json
    - mv ./assets/data/setting2.json ./assets/data/setting.json -fv
    - cat ./assets/data/setting.json
jxtxzzw's avatar
jxtxzzw committed
38

jxtxzzw's avatar
jxtxzzw committed
39
install_dependencies:
jxtxzzw's avatar
jxtxzzw committed
40
  stage: .pre
jxtxzzw's avatar
jxtxzzw committed
41
  script:
jxtxzzw's avatar
jxtxzzw committed
42
    - npm install
jxtxzzw's avatar
jxtxzzw committed
43

jxtxzzw's avatar
jxtxzzw committed
44 45 46
generate:
  stage: build
  script:
jxtxzzw's avatar
jxtxzzw committed
47 48 49 50 51
    - cd static/
    - touch .nojekyll
    - rm -rfv ./data-sample
    - cd ../
    - npm run generate
jxtxzzw's avatar
jxtxzzw committed
52 53
  artifacts:
    paths:
jxtxzzw's avatar
jxtxzzw committed
54 55
      - dist/

jxtxzzw's avatar
jxtxzzw committed
56 57 58
resume:
  stage: deploy
  script:
jxtxzzw's avatar
jxtxzzw committed
59
    - scp -i ~/.ssh/key.pem -rv ./dist/* ${USER}@${HOST_NAME}:${DEPLOY_LOCAL}/
jxtxzzw's avatar
jxtxzzw committed
60

jxtxzzw's avatar
jxtxzzw committed
61 62 63
pages:
  stage: deploy
  script:
jxtxzzw's avatar
jxtxzzw committed
64 65
    - mkdir -vp ./public
    - mv ./dist/* ./public/ -v
jxtxzzw's avatar
jxtxzzw committed
66 67
  artifacts:
    paths:
jxtxzzw's avatar
jxtxzzw committed
68
      - public
jxtxzzw's avatar
jxtxzzw committed
69
  only:
jxtxzzw's avatar
jxtxzzw committed
70
    - master
jxtxzzw's avatar
jxtxzzw committed
71

jxtxzzw's avatar
jxtxzzw committed
72
git:
jxtxzzw's avatar
jxtxzzw committed
73 74
  stage: deploy
  script:
jxtxzzw's avatar
jxtxzzw committed
75 76 77 78 79 80 81 82 83 84 85
    - git config --global  user.email ${GIT_USER_EMAIL}
    - git config --global  user.name '${GIT_USER_NAME}'
    - echo https://"${GIT_USER_NAME}":"${GIT_PASSWORD}"@${GIT_DOMAIN} > .git-credentials
    - git config --global credential.helper store
    - git clone --progress --verbose https://"${GIT_USER_NAME}":"${GIT_PASSWORD}"@${GIT_DOMAIN}/${GIT_REPO_OWNER}/${GIT_REPO_NAME}
    - cd ${GIT_REPO_NAME}
    - rm -rfv ./*
    - cp -rv ../dist/* ./
    - git add .
    - CURRENT_TIME=`date +%FT%T%:z`
    - COMMIT_MESSAGE_HEAD="[GitLab CI/CD] ${CURRENT_TIME}"
jxtxzzw's avatar
jxtxzzw committed
86
    - COMMIT_MESSAGE_BODY="${CI_PIPELINE_IID} (global ID ${CI_PIPELINE_ID}), triggered by ${CI_PIPELINE_SOURCE}, on commit ${CI_COMMIT_SHORT_SHA} (${CI_COMMIT_TITLE}) at ${CI_COMMIT_TIMESTAMP}, from ${CI_SERVER_HOST} (${CI_SERVER_VERSION}, ${CI_SERVER_REVISION}) ${CI_PROJECT_PATH}, using Runner-${CI_RUNNER_ID} ${CI_RUNNER_SHORT_TOKEN} (${CI_RUNNER_VERSION}, ${CI_RUNNER_REVISION}), by ${GITLAB_USER_NAME}"
jxtxzzw's avatar
jxtxzzw committed
87 88 89 90 91
    - echo ${COMMIT_MESSAGE_HEAD}
    - echo ${COMMIT_MESSAGE_BODY}
    - git commit -m "${COMMIT_MESSAGE_HEAD}" -m "${COMMIT_MESSAGE_BODY}"
    - git push --verbose

92 93
sast:
  stage: test
jxtxzzw's avatar
jxtxzzw committed
94 95
include:
  - template: Security/SAST.gitlab-ci.yml
jxtxzzw's avatar
jxtxzzw committed
96 97 98
  - template: Dependency-Scanning.gitlab-ci.yml
  - template: Security/Secret-Detection.gitlab-ci.yml
  - template: Security/License-Scanning.gitlab-ci.yml