forked from ricealexander/glade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
75 lines (71 loc) · 2.09 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
variables:
TARGET_SERVER_IP_PROD: "64.5.130.181"
TARGET_SERVER_PATH_PROD: "/var/www/pages.whro.org/public"
# The key values should be variable names from `Settings -> CI/CD -> Variables`, probably in the Group section
# E.G. SSH_PRIVATE_KEY_PROD: $SSH_PRIVATE_KEY_130_28
SSH_PRIVATE_KEY_PROD: $SSH_PRIVATE_KEY_130_181
stages:
- build
- release
- deploy
release:
stage: release
# Avoid unnecessary artifact downloads:
# https://docs.gitlab.com/ee/ci/yaml/#dependencies
dependencies: []
rules:
- if: $CI_COMMIT_TAG # Run this job when a tag is created manually
script:
- echo "Creating a release."
release:
tag_name: $CI_COMMIT_TAG
name: '$CI_COMMIT_TAG'
description: '$CI_COMMIT_TAG_MESSAGE'
build:
image: node:lts-alpine
stage: build
script:
- apk add --no-cache --virtual .gyp python3 make g++
- npm install
- npm run build
cache:
paths:
- node_modules/
artifacts:
paths:
- dist/
expire_in: 1 hour
rules:
# Production deploys happen when a Tag is created
- if: $CI_COMMIT_TAG
when: manual
- when: never
tags:
- docker
allow_failure: false
deploy:
stage: deploy
script:
- echo "Deploy to server"
- echo "Branch slug is '$CI_COMMIT_REF_SLUG'"
- echo "Commit branch is '$CI_COMMIT_BRANCH'"
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $TARGET_SERVER_IP >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- scp dist/glade.js git@$TARGET_SERVER_IP:$TARGET_SERVER_PATH/glade/
rules:
# Production deploys happen when a Tag is created
- if: $CI_COMMIT_TAG
when: manual
variables:
SSH_PRIVATE_KEY: "${SSH_PRIVATE_KEY_PROD}"
TARGET_SERVER_IP: "${TARGET_SERVER_IP_PROD}"
TARGET_SERVER_PATH: "${TARGET_SERVER_PATH_PROD}"
- when: never
tags:
- shell