-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
82 lines (71 loc) · 2.67 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
# DOCKER and DOCKER-COMPOSE FLOW
# image: docker:20
# NON-DOCKER FLOW
image: node:16-alpine
# DOCKER FLOW ##############
# services:
# - docker:20-dind
############################
before_script:
# - apk-add update -qq
- apk add -qq git
- apk add -qq openssh
# Setup SSH deploy keys
## Copy the key and give it the right permissions
##
- mkdir -p ~/.ssh
- mv "$STOKA_SSH_PRIVATE_KEY" ~/.ssh/id_rsa
- chmod 400 ~/.ssh/id_rsa
##
## Use ssh-keyscan to scan the keys of your private server. Replace gitlab.com
## with your own domain name. You can copy and repeat that command if you have
## more than one server to connect to.
##
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 400 ~/.ssh/known_hosts
##
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || ( apk add install openssh-client git -y )'
##
## Run ssh-agent (inside the build environment)
##
- eval $(ssh-agent -s)
##
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
##
- ssh-add ~/.ssh/id_rsa
##
## You can optionally disable host key checking. Be aware that by adding that
## you are suspectible to man-in-the-middle attacks.
## WARNING: Use this only with the Docker executor, if you use it with shell
## you will overwrite your user's SSH config.
##
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\tForwardAgent yes\n\n" > ~/.ssh/config'
- echo ~/.ssh/config
deploy_production:
type: deploy
environment:
name: production
url: stoka.example.com
script:
- apk add rsync
- git clone -b develop git@gitlab.com:Pramus/stoka-backend.git
- cd stoka-backend/
# DOCKER FLOW WITHOUT COMPOSE
# - docker build . -t stoka
# - docker save stoka | gzip > stoka.tar.gz
# - rsync -a stoka.tar.gz stoka@stoka.andrzejewski.it:~/stoka-backend/stoka.tar.gz
# NON-DOCKER FLOW
- npm i
- npm run build
- ssh stoka@stoka.andrzejewski.it "git config --global user.email "stoka@stoka.com" && git config --global user.name "Stoka" && cd /var/www/stoka-backend/ && git checkout -f develop && git fetch origin && git reset --hard origin/develop && exit"
- rsync -avzh node_modules/ stoka@stoka.andrzejewski.it:/var/www/stoka-backend/node_modules
- rsync -avzh dist/ stoka@stoka.andrzejewski.it:/var/www/stoka-backend/dist
- ssh stoka@stoka.andrzejewski.it "pm2 restart stoka-service"
only:
- develop