This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
.gitlab-ci.yml
127 lines (119 loc) · 4.05 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
image: node:8-alpine
variables:
WEBDEV_FTP_HOST: 'webdev1-ssh.sinergise.com'
S3_BUCKET_NAME: 'water.blue-dot-observatory.com'
stages:
- test
- deploy
before_script:
# write version, branch & commit id to src/VERSION.js:
- 'echo "export const VERSION_INFO = { tag: ''$CI_COMMIT_TAG'', branch: ''$CI_COMMIT_REF_NAME'', commit: ''$CI_COMMIT_SHA'' }" > ./src/VERSION.js'
### TEST: ###
install_packages_and_run_lint:
stage: test
when: manual
script:
- apk add --update git
- yarn config set cache-folder .yarn
- yarn install
- npm run lint
artifacts:
expire_in: 2 days
paths:
# we will need the installed packages in next step, so cache might not be enough - we need to create an artifact:
- ./node_modules
### DEPLOY: ###
deploy_testing:
stage: deploy
when: manual
variables:
REACT_APP_BASENAME: '/tmp/wo/$CI_COMMIT_REF_SLUG'
except:
- master
- develop
- tags
script:
- CI=true yarn build
- mv ./build ./build_testing
- export TARGET_DIR="/sentinel/tmp/wo/$CI_COMMIT_REF_SLUG/"
- apk add --update ncftp
- echo "rm -r $TARGET_DIR; mkdir $TARGET_DIR" | ncftp -u $WEBDEV_FTP_USERNAME -p $WEBDEV_FTP_PASSWORD $WEBDEV_FTP_HOST
- ncftpput -u $WEBDEV_FTP_USERNAME -p $WEBDEV_FTP_PASSWORD -R $WEBDEV_FTP_HOST $TARGET_DIR ./build_testing/*
- 'echo "Testing URL: https://webdev.sentinel-hub.com/tmp/wo/$CI_COMMIT_REF_SLUG/"'
dependencies:
- install_packages_and_run_lint
artifacts:
expire_in: 1 hour
paths:
- ./build_testing
deploy_staging:
stage: deploy
when: manual
variables:
REACT_APP_BASENAME: '/water-observatory'
only:
- develop
script:
- CI=true yarn build
- mv ./build ./build_staging
- export TARGET_DIR="/sentinel/water-observatory/"
- apk add --update ncftp
- echo "rm -r $TARGET_DIR; mkdir $TARGET_DIR" | ncftp -u $WEBDEV_FTP_USERNAME -p $WEBDEV_FTP_PASSWORD $WEBDEV_FTP_HOST
- ncftpput -u $WEBDEV_FTP_USERNAME -p $WEBDEV_FTP_PASSWORD -R $WEBDEV_FTP_HOST $TARGET_DIR ./build_staging/*
- 'echo "Staging URL: https://webdev.sentinel-hub.com/water-observatory/"'
dependencies:
- install_packages_and_run_lint
artifacts:
expire_in: 1 hour
paths:
- ./build_staging
deploy_production:
stage: deploy
when: manual
variables:
PUBLIC_URL: '/'
only:
- tags
script:
- CI=true yarn build
- mv ./build ./build_prod
- apk add --update python python-dev py-pip
- pip install awscli
# deploy sometimes fails if you don't sync clocks in docker container:
- hwclock -s
- aws s3 sync ./build_prod s3://$S3_BUCKET_NAME/ --acl public-read
- INVALIDATION_OUTPUT=$(aws cloudfront create-invalidation --distribution-id $AWS_CLOUDFRONT_DISTRIBUTION --paths "/*")
- 'echo "INVALIDATION OUTPUT: $INVALIDATION_OUTPUT"'
- INVALIDATION_ID=$(echo "$INVALIDATION_OUTPUT" | python -c "import sys, json; print json.load(sys.stdin)['Invalidation']['Id']")
- aws cloudfront wait invalidation-completed --distribution-id $AWS_CLOUDFRONT_DISTRIBUTION --id "$INVALIDATION_ID"
dependencies:
- install_packages_and_run_lint
artifacts:
expire_in: 100 years
paths:
- ./build_prod
publish_github:
stage: test
# when: manual
variables:
GITHUB_REPO: '/tmp/githubrepo'
GITHUB_BRANCH: 'github'
# only:
# - master
script:
- apk add --no-cache --update openssh git
- git config --global user.email "[email protected]"
- git config --global user.name "Sinergise"
- mkdir -p ~/.ssh
- echo "$GITHUB_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- ssh-keyscan github.com >> ~/.ssh/known_hosts
- chmod 400 ~/.ssh/*
- cat ~/.ssh/id_rsa
- cat ~/.ssh/known_hosts
# - export REPO_DIR="`pwd`"
- git clone "$CI_PROJECT_DIR" "$GITHUB_REPO"
- cd /tmp/githubrepo/
- git remote add ghorigin [email protected]:sentinel-hub/water-observatory-frontend.git
- git checkout "$GITHUB_BRANCH" || (git checkout --orphan "$GITHUB_BRANCH" && git commit -m "Initial commit" && git checkout "$GITHUB_BRANCH")
# push to github:
- git push -u ghorigin "$GITHUB_BRANCH"