-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
151 lines (137 loc) · 3.98 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
#image: node:latest
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
#services:
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
#test_async:
# script:
# - npm install
# - npm test
stages:
- setup
- build
- test
- deploy
variables:
BUILD_TARGET: dist
BUILD_LABEL_TMPFILE: build.txt
before_script:
- if [ -f ${BUILD_LABEL_TMPFILE} ]; then export BUILD_LABEL=`cat ${BUILD_LABEL_TMPFILE}`; fi
init:
stage: setup
tags:
#- kunden-web
- node
#- php
before_script:
- export BUILD_LABEL=$(TZ=Europe/Berlin date +%Y%m%d-%H%M)
script:
# save timestamp to file
- echo $BUILD_LABEL > ${BUILD_LABEL_TMPFILE}
- echo -e "\n\n\n\e[96mCreated new build label \e[107;30;1m $BUILD_LABEL \e[0m\n\n\n"
# other init commands
- whoami
- pwd
artifacts:
paths:
- ${BUILD_LABEL_TMPFILE}
app-build:
stage: build
tags:
#- kunden-web
- node
#- php
dependencies:
- init
variables:
BUILD_INFO_FILE: dist/build.txt
script:
# check if a build environment exists and copy it or install a new one if it doesn't
- if [ -d /build-env_DOES_NOT_EXIT_USE_INSTALL_FOR_NOW/node_modules ] && [ -f /build-env/package-lock.json ];
then echo -e "\e[96mFOUND EXISTING BUILD ENVIRONMENT" && mv /build-env/* ./;
else echo -e "\e[93mNO EXISTING BUILD ENVIRONMENT - RUNNING INSTALL" && npm install;
fi
# list used packages
- npm ls || true
# run node build
- npm run build
# create build info file
- echo -e "LABEL=`cat ${BUILD_LABEL_TMPFILE}`" > ${BUILD_INFO_FILE}
- echo -e "TAG=${CI_COMMIT_TAG}" >> ${BUILD_INFO_FILE}
- echo -e "COMMIT=${CI_COMMIT_SHA}" >> ${BUILD_INFO_FILE}
- echo -e "PIPELINE=${CI_PIPELINE_ID}" >> ${BUILD_INFO_FILE}
# print debug-info
- cat ${BUILD_INFO_FILE}
- ls -la ${BUILD_TARGET}
artifacts:
paths:
- ${BUILD_TARGET}
- node_modules
- bin
- gui
- lib
- test
- .coveralls.yml
app-tests:
stage: test
tags:
#- kunden-web
- node
#- php
dependencies:
- app-build
variables:
BUILD_TEST_COVERAGE_FILE: dist/coverage.xml
script:
# check if a build environment exists and copy it or install a new one if it doesn't
#- php -v
- node -v
- npm test
artifacts:
paths:
- ${BUILD_TARGET}
deploy-package:
stage: deploy
tags:
- npm
dependencies:
- app-build
- app-tests
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ssh-add <(echo "$SSH_STAGING_PRIVATE_KEY")
- apt-get install rsync
script:
- ssh -p22 [email protected] "mkdir -p /_tmp"
- rsync -rav -e ssh --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded /${BUILD_TARGET}/ [email protected]:/_tmp
- ssh -p22 [email protected] "mv /${BUILD_TARGET} /${BUILD_TARGET}_save && mv /_tmp /${BUILD_TARGET}"
- ssh -p22 [email protected] "rm -rf /${BUILD_TARGET}_save"
only:
refs:
- tags
when: manual
deploy-demo:
stage: deploy
tags:
- ftp
dependencies:
- app-build
- app-tests
script:
- 'which lftp || ( apt-get update -qq && apt-get install -y -qq lftp )'
- lftp -c "set ftp:ssl-allow no; open -u $FTP_USERNAME,$FTP_PASSWORD $FTP_HOST; mirror -Rev ${BUILD_TARGET}/ ./$FTP_PATH/${BUILD_TARGET} --parallel=10 --exclude-glob .git* --exclude .git/"
only:
refs:
- master
#when: manual