-
Notifications
You must be signed in to change notification settings - Fork 57
/
.gitlab-ci.yml
143 lines (137 loc) · 4.31 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
default:
tags:
- k8s-aws-tools
interruptible: true
stages:
- build
- deploy
- release
variables:
MKDOCS_IMAGE_VERSION: "0.3.8"
MKDOCS_IMAGE_URL: "registry.gitlab.com/kxdev/documentation/framework/mkdocs-build"
KUBERNETES_MEMORY_REQUEST: "512Mi"
KUBERNETES_MEMORY_LIMIT: "1024Mi"
BACKUP_DRAFT_DIR: "/home/seedy/qbackup/q_draft"
BACKUP_LIVE_DIR: "/home/seedy/qbackup/q_live"
DRAFT_DIR: "/var/www/draft"
LIVE_DIR: "/var/www"
build-job:
image: "$MKDOCS_IMAGE_URL:$MKDOCS_IMAGE_VERSION"
stage: build
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: never
- when: always
before_script:
- apt-get install -y zip wget
script:
- echo "######## build-job"
- ./local.sh build
artifacts:
name: "local"
paths:
- local.zip
expire_in: 3 days
.setup-ssh:
image:
name: "$MKDOCS_IMAGE_URL:$MKDOCS_IMAGE_VERSION"
entrypoint: [""]
before_script:
- |
# Write key into container
mkdir -p ~/.ssh
chmod 700 ~/.ssh
eval $(ssh-agent -s)
echo $SEEDY_B64_KEY | base64 -d | tr -d '\r' > ~/.ssh/id_rsa
chmod 0600 ~/.ssh/id_rsa
- |
# ssh-add
echo 'echo -n $(echo $SEEDY_B64_PASS | base64 -d)' > ~/.ssh-pass
chmod +x ~/.ssh-pass
SSH_ASKPASS=~/.ssh-pass ssh-add ~/.ssh/id_rsa
- |
# known_hosts
ssh-keyscan -t rsa -H code.kx.com >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
cat ~/.ssh/known_hosts
deploy-draft-job:
stage: deploy
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: never
- when: on_success
dependencies:
- build-job
when: on_success
extends: .setup-ssh
variables:
DISPLAY: "1"
GIT_STRATEGY: none
UNZIP_DIR: "/tmp/seedy/unzip"
script:
- echo "######## Available files in runner"
- ls -al
- |
ssh [email protected] << EOF
echo "######## Removing dir used to unzip i.e. ${UNZIP_DIR}"
rm -rf ${UNZIP_DIR}
mkdir -p ${UNZIP_DIR}
EOF
- scp local.zip [email protected]:${UNZIP_DIR}/
- |
ssh [email protected] << EOF
if [ ! -d ${DRAFT_DIR} ]; then mkdir -p ${DRAFT_DIR}; fi
echo "######## Current contents of ${DRAFT_DIR}"
ls -l ${DRAFT_DIR}
echo "######## Unzip new site to ${UNZIP_DIR}/local"
cd ${UNZIP_DIR}
unzip local.zip
echo "######## Backing up ${DRAFT_DIR}/q (previous draft site) to ${BACKUP_DRAFT_DIR}"
rm -rf ${BACKUP_DRAFT_DIR}
mkdir -p ${BACKUP_DRAFT_DIR}
cd ${DRAFT_DIR}
if [ -d q ]; then mv q ${BACKUP_DRAFT_DIR};echo "######## Old draft site backed up to ${BACKUP_DRAFT_DIR}"; fi
echo "######## Contents of backup dir ${BACKUP_DRAFT_DIR}"
ls -l ${BACKUP_DRAFT_DIR}
echo "######## Moving new draft site from ${UNZIP_DIR}/local to ${DRAFT_DIR}/q"
mv ${UNZIP_DIR}/local ${DRAFT_DIR}/q
echo "######## Contents of draft dir ${DRAFT_DIR}"
ls -l ${DRAFT_DIR}
echo "######## Contents of draft q dir ${DRAFT_DIR}/q"
ls -l ${DRAFT_DIR}/q
EOF
release_job:
image: "$MKDOCS_IMAGE_URL:$MKDOCS_IMAGE_VERSION"
stage: release
interruptible: false
rules:
- if: $CI_COMMIT_TAG
extends: .setup-ssh
variables:
DISPLAY: "1"
GIT_STRATEGY: none
script:
- echo "######## release_job"
- |
ssh [email protected] << EOF
if [ ! -d ${LIVE_DIR} ]; then mkdir -p ${LIVE_DIR}; fi
echo "######## Current contents of ${LIVE_DIR}"
ls -l ${LIVE_DIR}
echo "######## Backing up ${LIVE_DIR}/q (previous live site) to ${BACKUP_LIVE_DIR}"
rm -rf ${BACKUP_LIVE_DIR}
mkdir -p ${BACKUP_LIVE_DIR}
cd ${LIVE_DIR}
if [ -d q ]; then mv q ${BACKUP_LIVE_DIR};echo "######## Old live site backed up to ${BACKUP_LIVE_DIR}"; fi
echo "######## Contents of backup dir ${BACKUP_LIVE_DIR}"
ls -l ${BACKUP_LIVE_DIR}
echo "######## Copy new site from ${DRAFT_DIR}/q to ${LIVE_DIR}/q"
cp -r ${DRAFT_DIR}/q ${LIVE_DIR}/q
echo "######## Contents of live dir ${LIVE_DIR}"
ls -l ${LIVE_DIR}
echo "######## Contents of live dir ${LIVE_DIR}/q"
ls -l ${LIVE_DIR}/q
EOF