-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.gitlab-ci.yml
33 lines (31 loc) · 1.28 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
image: alpine
variables:
WORK_DIR: ${CI_PROJECT_NAME}
BRANCH: ${CI_COMMIT_REF_NAME}
REPO: https://gitlab.com/Tecnonucleous/open-telegram-bot-nodejs.git
SERVER_IP: $SERVER_IP
SERVER_PORT: $SERVER_PORT
SSH_USERNAME: $SSH_USERNAME
DEPLOY_KEY : $DEPLOY_KEY
FILE_CONFIG_BOT : $FILE_CONFIG_BOT
CP_FILE_CONFIG_BOT : $CP_FILE_CONFIG_BOT
BOT_INDEX : $BOT_INDEX
stages:
- deploy
deploy:
stage: deploy
# Within before_script what we are doing is creating and adding ssh key, also we are disabling command line to ask for password. 'StrictHostKeyChecking no'
before_script:
#Add necessary packages
- apk add --update openssh bash openssl gettext
#Run ssh agent
- eval $(ssh-agent -s)
# Create ~/.ssh directory
- mkdir -p ~/.ssh
# Add deploy key to ssh directory
# Add deploy key to ssh directory
- echo "$DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- ssh -o StrictHostKeyChecking=no "$SSH_USERNAME"@"$SERVER_IP" -p "$SERVER_PORT" "cd ${WORK_DIR}; pm2 stop openbot; rm -rf open-telegram-bot-nodejs; git init; git clone -b ${BRANCH} ${REPO}; cp ${FILE_CONFIG_BOT} ${CP_FILE_CONFIG_BOT}; cd ${BOT_INDEX}; npm install; pm2 restart openbot"