-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
136 lines (129 loc) · 4.41 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
# Private repo are located on Gitlab CI
# This script exist here for archive and starter
image: misterio92/ci-php-node:2.0
variables:
STAGING_REMOTE_DESTINATION_DIR: ./www/wp-content
PRODUCTION_REMOTE_DESTINATION_DIR: ./www/wp-content
STAGE_URL: https://wpdevstack.ecrannoir.be
PRODUCTION_URL: https://wpdevstack.ecrannoir.be
THEME_DIR: wpdevstack
THEME_CHILD_DIR: wpdevstack-child
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm/
- node_modules/
stages:
- build
- test
- deploy
build_job:
stage: build
only:
- main
- master
- staging
- production
before_script:
- source .env
- apt-get update
- apt-get install zip unzip -y
- npm install --prefix ./$THEME_DIR
- npm install --prefix ./$THEME_CHILD_DIR
script:
- echo "Here we are on build step"
- npm run production --prefix ./$THEME_DIR
- npm run production --prefix ./$THEME_CHILD_DIR
artifacts:
paths:
- ./$THEME_DIR/assets/
- ./$THEME_DIR/languages/
- ./$THEME_DIR/vendor/
- ./$THEME_CHILD_DIR/assets/
- ./$THEME_CHILD_DIR/languages/
- ./$THEME_CHILD_DIR/vendor/
environment:
name: stage
url: $STAGE_URL
ftp_deploy:
stage: deploy
only:
refs:
- staging
# - master
variables:
- $CI_SYNC_TYPE == "FTP"
before_script:
- source .env
- apt-get update
- apt-get install lftp
script:
- echo "Here we are on Deploy step by ftp"
- rm -rf $THEME_NAME/src/ $THEME_NAME/package.json $THEME_NAME/package-lock.json $THEME_NAME/webpack.config.js $THEME_NAME/.stylelintrc.json
- lftp --version
- lftp -e "open $FTP_ADDRESS; user $FTP_LOGIN $FTP_PASSWORD; mirror --reverse --verbose --delete $THEME_NAME $STAGING_REMOTE_DESTINATION_DIR/themes; bye"
# - lftp -e "open $FTP_ADDRESS; user $FTP_LOGIN $FTP_PASSWORD; mirror --reverse --verbose --delete plugins/ $STAGING_REMOTE_DESTINATION_DIR/plugins; bye"
environment:
name: stage
url: $STAGE_URL
staging_rsync_deploy:
stage: deploy
only:
refs:
- main
- master
- staging
- production
before_script:
- source .env
- "which ssh-agent || ( apk --no-cache add rsync openssh-client )"
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- echo "CI Deploy with rsync"
- echo "$STAGING_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- ssh -p22 $STAGING_SSH_USER@$STAGING_SSH_HOST "ls -al"
- find ./$THEME_NAME -type d -exec chmod 755 {} \;
- find ./$THEME_NAME -type f -exec chmod 644 {} \;
- find ./$THEME_CHILD_DIR -type d -exec chmod 755 {} \;
- find ./$THEME_CHILD_DIR -type f -exec chmod 644 {} \;
- chmod 755 $THEME_NAME
- chmod 755 $THEME_CHILD_DIR
- ls -al $THEME_NAME
- ls -al $THEME_CHILD_DIR
- rsync -azPqv --delete --exclude-from='.rsyncignore' $THEME_NAME $STAGING_SSH_USER@$STAGING_SSH_HOST:$STAGING_REMOTE_DESTINATION_DIR/themes
- rsync -azPqv --delete --exclude-from='.rsyncignore' $THEME_CHILD_DIR $STAGING_SSH_USER@$STAGING_SSH_HOST:$STAGING_REMOTE_DESTINATION_DIR/themes
environment:
name: stage
url: $STAGE_URL
production_rsync_deploy:
stage: deploy
only:
refs:
- main
- production
# - master
before_script:
- source .env
- "which ssh-agent || ( apk --no-cache add rsync openssh-client )"
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- echo "CI Deploy Staging with rsync"
- echo "$PRODUCTION_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- ssh -p22 $PRODUCTION_SSH_USER@$PRODUCTION_SSH_HOST "ls -al"
- find ./$THEME_NAME -type d -exec chmod 755 {} \;
- find ./$THEME_NAME -type f -exec chmod 644 {} \;
- find ./$THEME_CHILD_DIR -type d -exec chmod 755 {} \;
- find ./$THEME_CHILD_DIR -type f -exec chmod 644 {} \;
- chmod 755 $THEME_NAME
- chmod 755 $THEME_CHILD_DIR
- ls -al $THEME_NAME
- ls -al $THEME_CHILD_DIR
- rsync -azPqv --delete --exclude-from='.rsyncignore' $THEME_NAME $PRODUCTION_SSH_USER@$PRODUCTION_SSH_HOST:$PRODUCTION_REMOTE_DESTINATION_DIR/themes
- rsync -azPqv --delete --exclude-from='.rsyncignore' $THEME_CHILD_DIR $PRODUCTION_SSH_USER@$PRODUCTION_SSH_HOST:$PRODUCTION_REMOTE_DESTINATION_DIR/themes
environment:
name: production
url: $PRODUCTION_URL