-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path.gitlab-ci.yml
95 lines (86 loc) · 3.19 KB
/
.gitlab-ci.yml
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
image: node:16.13.1
stages:
- build
- deploy
cache:
key: resume
paths:
- node_modules/
- assets/data/
- static/data/
before_script:
- 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
- node --version
- npm --version
load_resources:
stage: .pre
script:
- ssh -i ~/.ssh/key.pem -v ${USER}@${HOST_NAME} "cd ${CICD_DIR} && sh ${EXPORT_DB_SHELL}.sh"
- ssh -i ~/.ssh/key.pem -v ${USER}@${HOST_NAME} "cd ${CICD_DIR} && sh ${LOAD_DATA_SHELL}.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}
- echo sed \"s/\\\"updated\\\":[ ]*\\\"[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\\"/\\\"updated\\\":\\\"${RESUME_DATE}\\\"/g\" > ./update_time.sh
- 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
install_dependencies:
stage: .pre
script:
- npm install
generate:
stage: build
script:
- cd static/
- touch .nojekyll
- rm -rfv ./data-sample
- cd ../
- npm run generate
artifacts:
expire_in: 1 week
paths:
- dist/
resume:
stage: deploy
script:
- scp -i ~/.ssh/key.pem -rv ./dist/* ${USER}@${HOST_NAME}:${DEPLOY_LOCAL}/
pages:
stage: deploy
script:
- mkdir -vp ./public
- mv ./dist/* ./public/ -v
artifacts:
expire_in: 1 week
paths:
- public
only:
- master
git:
stage: deploy
script:
- 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}
- git pull origin master --verbose
- rm -rfv ./*
- cp -rv ../dist/* ./
- git add .
- CURRENT_TIME=`date +%FT%T%:z`
- COMMIT_MESSAGE_HEAD="[GitLab CI/CD] ${CURRENT_TIME}"
- COMMIT_MESSAGE_BODY="[GitLab CI/CD] ${CURRENT_TIME}, ${CI_PROJECT_TITLE}. ${CI_PIPELINE_IID} (global ID ${CI_PIPELINE_ID}), triggered by ${CI_PIPELINE_SOURCE} (${COMMENT}) at ${CI_PIPELINE_CREATED_AT} / ${CI_JOB_STARTED_AT}, 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_DESCRIPTION} (${CI_RUNNER_SHORT_TOKEN}, ${CI_RUNNER_VERSION} (${CI_RUNNER_REVISION}))), by ${GITLAB_USER_NAME}"
- echo ${COMMIT_MESSAGE_HEAD}
- echo ${COMMIT_MESSAGE_BODY}
- git commit -m "${COMMIT_MESSAGE_HEAD}" -m "${COMMIT_MESSAGE_BODY}"
- git push --set-upstream origin master --verbose