-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
94 lines (83 loc) · 2.56 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
stages:
- test
- deploy
include:
- project: 'lvckyworld-docker/gitlab-ci-rezept'
file:
- '/deployment/.rsync.yml'
- component: git.lvckyworld.dev/pipeline-components/node-package-manager/npm-install@~latest
inputs:
stage: test
build:nextjs:
extends: .npm install
script:
- npm install
- npm run build
artifacts:
paths:
- .next
expire_in: 1 week
only:
- master
- merge_requests
- /^(deploy-dev-)\d{8}.\d{4}$/
- /^(deploy-prod-)\d{8}.\d{4}$/
deploy:staging:
extends: .deploy-rsync
environment:
name: 'staging'
url: https://iven:[email protected]
variables:
SERVER: 'theta.lvckyworld.dev'
SERVER_PORT: 22
SERVER_USERNAME: 'deployer'
SERVER_PATH: '/home/deployer/schlenther.dev/schlenther.dev-staging'
MNTDIR: '/mnt/schlenther.dev/schlenther.dev-staging'
RSYNC_OPTIONS: '--delete'
before_script:
- ls -la ${FOLDER_TO_SYNC}
# remove docker .env default file
- rm .env
# copy .env file from GitLab CI-Settings
- cp ${STAGING_ENV} ./.env
# remove docker-compose.yml default file
- rm docker-compose.yml
# replace docker-compose.yml with docker-compose.staging.yml
- cp docker-compose.staging.yml docker-compose.yml
script:
# deploy using rsync jobs script
- !reference [.deploy-rsync, script]
- |
runssh() {
echo "$@" | ssh -p $SERVER_PORT $SERVER_USERNAME@$SERVER "(cd $SERVER_PATH || true && export CURRENTDIR=${CURRENTDIR} &&
export SERVER_PATH=${SERVER_PATH} && export CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA} && bash -s)"
}
# list the files on the server
- echo "FILES FROM SERVER"
- runssh ls -lva
# stop, remove, rebuild and start docker
- runssh docker compose down
- runssh docker compose up typescript -d --build --remove-orphans
only:
- /^(deploy-dev-)\d{8}.\d{4}$/
deploy:production:
stage: deploy
extends: deploy:staging
environment:
name: 'production'
url: https://schlenther.dev
variables:
SERVER_PATH: '/home/deployer/schlenther.dev/schlenther.dev-production'
MNTDIR: '/mnt/schlenther.dev/schlenther.dev-production'
before_script:
- ls -la ${FOLDER_TO_SYNC}
# remove docker .env default file
- rm .env
# copy .env file from GitLab CI-Settings
- cp ${PRODUCTION_ENV} ./.env
# remove docker-compose.yml default file
- rm docker-compose.yml
# replace docker-compose.yml with docker-compose.production.yml
- mv docker-compose.production.yml docker-compose.yml
only:
- /^(deploy-prod-)\d{8}.\d{4}$/