.gitlab-ci.yml 9.76 KB
Newer Older
1
stages:
2 3 4 5 6 7
  - review_webpack
  - review_docker
  - review_deploy
  - release_build
  - release_sentry
  - release_deploy
8

9
review:webpack:
10
  stage: review_webpack
echel0n's avatar
echel0n committed
11
  image:
12 13 14
    name: nikolaik/python-nodejs:python3.7-nodejs10-alpine
  variables:
    NODE_ENV: "development"
echel0n's avatar
echel0n committed
15
  script:
16
    - apk add --no-cache git gcc libffi-dev python3-dev musl-dev openssl-dev
17 18
    - npm install -qs
    - npm run build
echel0n's avatar
echel0n committed
19
  only:
20 21 22 23 24
    - merge_requests
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - sickrage/core/webserver/static/
echel0n's avatar
echel0n committed
25

26
review:docker:
27 28
  stage: review_docker
  dependencies:
29
    - review:webpack
30 31 32 33 34 35 36 37 38 39
  image:
    name: docker:latest
    entrypoint: ["/bin/sh", "-c"]
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://localhost:2375
    DOCKER_TLS_CERTDIR: ""
  services:
    - docker:dind
  script:
40
    - docker login -u "${CI_REGISTRY_USER}" -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
41 42 43 44 45 46
    - docker build --network host -t "${CI_REGISTRY_IMAGE}:latest" .
    - docker tag "${CI_REGISTRY_IMAGE}:latest" "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"
    - test ! -z "${CI_COMMIT_TAG}" && docker push "${CI_REGISTRY_IMAGE}:latest"
    - docker push "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"
  only:
    - merge_requests
47 48
  cache:
    key: ${CI_COMMIT_REF_SLUG}
49

50
review:deploy:
51
  stage: review_deploy
52
  dependencies:
53
    - review:docker
54 55 56 57
  image:
    name: lachlanevenson/k8s-kubectl:latest
    entrypoint: ["/bin/sh", "-c"]
  script:
58
    - kubectl create secret docker-registry gitlab-registry --namespace ${KUBE_NAMESPACE} --docker-server=${CI_REGISTRY} --docker-username=${CI_REGISTRY_USER} --docker-password=${CI_JOB_TOKEN} --docker-email=$GITLAB_USER_EMAIL --dry-run -o json | kubectl apply --namespace ${KUBE_NAMESPACE} -f -
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    - sed -i "s~__CI_REGISTRY_IMAGE__~${CI_REGISTRY_IMAGE}~" manifests/deployment.yaml
    - sed -i "s/__VERSION__/${CI_COMMIT_REF_NAME}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
    - sed -i "s/__CI_COMMIT_REF_SLUG__/${CI_COMMIT_REF_SLUG}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
    - sed -i "s/__CI_ENVIRONMENT_SLUG__/${CI_ENVIRONMENT_SLUG}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
    - sed -i "s/__KUBE_NAMESPACE__/${KUBE_NAMESPACE}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
    - |
      if kubectl apply -f manifests/deployment.yaml | grep -q unchanged; then
          echo "=> Patching deployment to force image update."
          kubectl patch -f manifests/deployment.yaml -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"ci-last-updated\":\"$(date +'%s')\"}}}}}"
      else
          echo "=> Deployment apply has changed the object, no need to force image update."
      fi
    - kubectl apply -f manifests/service.yaml || true
    - kubectl apply -f manifests/ingress.yaml
    - kubectl rollout status -f manifests/deployment.yaml
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://review.sickrage.ca/$CI_COMMIT_REF_SLUG
77
    on_stop: review:stop
78 79 80
  only:
    - merge_requests

81
review:stop:
82
  stage: review_deploy
83 84 85 86
  image:
    name: lachlanevenson/k8s-kubectl:latest
    entrypoint: ["/bin/sh", "-c"]
  script:
87 88 89
#    - wget -O /usr/bin/reg https://github.com/genuinetools/reg/releases/download/v0.13.0/reg-linux-amd64
#    - chmod +x /usr/bin/reg
#    - reg -r ${CI_REGISTRY} -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} rm ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
echel0n's avatar
echel0n committed
90 91
    - kubectl delete ing -l ref=${CI_ENVIRONMENT_SLUG}
    - kubectl delete all -l ref=${CI_ENVIRONMENT_SLUG}
92 93 94 95 96 97 98 99 100
  variables:
    GIT_STRATEGY: none
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  only:
    - merge_requests

101
release:build:master:
102 103 104 105 106 107
  stage: release_build
  image:
    name: nikolaik/python-nodejs:python3.7-nodejs10-alpine
  variables:
    NODE_ENV: "development"
  script:
108
    - apk add --no-cache git gcc libffi-dev python3-dev musl-dev openssl-dev
109 110
    - git config --global user.email $(git --no-pager show -s --format='%ae' HEAD)
    - git config --global user.name $(git --no-pager show -s --format='%an' HEAD)
111 112 113
    - npm install -qs
    - pip install bumpversion
    - pip install -r requirements-dev.txt
114
    - bumpversion --allow-dirty release package.json sickrage/version.txt
115
    - git checkout -b release-$(cat sickrage/version.txt)
116
    - npm run build
echel0n's avatar
echel0n committed
117 118 119 120
#    - python setup.py extract_messages
#    - crowdin-cli-py upload sources
#    - crowdin-cli-py download
#    - python setup.py compile_catalog
121 122
    - git add --all
    - git commit -m "[TASK] Releasing v$(cat sickrage/version.txt)"
123 124 125 126
    - git fetch . release-$(cat sickrage/version.txt):master
    - git fetch . release-$(cat sickrage/version.txt):develop
    - git tag -a $(cat sickrage/version.txt) -m "Release v$(cat sickrage/version.txt) master"
    - git push https://$GIT_ACCESS_USER:[email protected]$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:master --follow-tags
127 128 129 130
    - git checkout develop
    - bumpversion --allow-dirty patch package.json sickrage/version.txt
    - git add --all
    - git commit -m "[TASK] Bump develop branch to v$(cat sickrage/version.txt)"
131 132 133
#    - git tag -a $(cat sickrage/version.txt) -m "Pre-Release v$(cat sickrage/version.txt) develop"
    - git push https://$GIT_ACCESS_USER:[email protected]$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:develop --follow-tags
  when: manual
134
  only:
135
    - develop
136 137 138 139 140 141 142
  except:
    refs:
      - tags
      - triggers
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[TASK\] Releasing/

143
release:build:develop:
144 145 146 147 148 149
  stage: release_build
  image:
    name: nikolaik/python-nodejs:python3.7-nodejs10-alpine
  variables:
    NODE_ENV: "development"
  script:
150
    - apk add --no-cache git gcc libffi-dev python3-dev musl-dev openssl-dev
151 152 153
    - npm install -qs
    - pip install bumpversion
    - pip install -r requirements-dev.txt
154
    - bumpversion --allow-dirty dev package.json sickrage/version.txt
155
    - npm run build
156 157 158 159
    #    - python setup.py extract_messages
    #    - crowdin-cli-py upload sources
    #    - crowdin-cli-py download
    #    - python setup.py compile_catalog
160 161 162 163 164 165 166 167 168 169 170 171 172 173
    - git config --global user.email $(git --no-pager show -s --format='%ae' HEAD)
    - git config --global user.name $(git --no-pager show -s --format='%an' HEAD)
    - git add --all
    - git tag -a $(cat sickrage/version.txt) -m "Pre-release v$(cat sickrage/version.txt)"
    - git commit -m "[TASK] Pre-Releasing v$(cat sickrage/version.txt)"
    - git push https://$GIT_ACCESS_USER:[email protected]$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:$CI_COMMIT_REF_NAME --follow-tags
  only:
    - develop
  except:
    refs:
      - tags
      - triggers
    variables:
      - $CI_COMMIT_MESSAGE =~ /\[TASK\] Pre-Releasing/
174
      - $CI_COMMIT_MESSAGE =~ /\[TASK\] Bump/
175

176
release:sentry:master:
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
  stage: release_sentry
  image:
    name: getsentry/sentry-cli
    entrypoint: [""]
  script:
    - export SENTRY_URL=$SENTRY_URL
    - export SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
    - export SENTRY_ORG=$SENTRY_ORG
    - export SENTRY_PROJECT=$SENTRY_PROJECT
    - sentry-cli releases new --project $SENTRY_PROJECT $(cat sickrage/version.txt)
    - sentry-cli releases set-commits --auto $(cat sickrage/version.txt)
    - sentry-cli releases finalize $(cat sickrage/version.txt)
    - sentry-cli releases deploys $(cat sickrage/version.txt) new -e master
  only:
    - /^[0-9.]+$/
  except:
    - branches
    - triggers

196
release:sentry:develop:
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
  stage: release_sentry
  image:
    name: getsentry/sentry-cli
    entrypoint: [""]
  script:
    - export SENTRY_URL=$SENTRY_URL
    - export SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
    - export SENTRY_ORG=$SENTRY_ORG
    - export SENTRY_PROJECT=$SENTRY_PROJECT
    - sentry-cli releases new --project $SENTRY_PROJECT $(cat sickrage/version.txt)
    - sentry-cli releases set-commits --auto $(cat sickrage/version.txt)
    - sentry-cli releases finalize $(cat sickrage/version.txt)
    - sentry-cli releases deploys $(cat sickrage/version.txt) new -e develop
  only:
    - /^[0-9.]+dev[0-9]+$/
  except:
    - branches
    - triggers

deploy:pypi:
  stage: release_deploy
218 219
  image: python:3.7-alpine3.9
  script:
220
    - apk add --no-cache py-pip gcc libffi-dev python3-dev musl-dev openssl-dev
221 222 223 224
    - pip install -U twine
    - python setup.py sdist bdist_wheel
    - twine upload dist/*
  only:
echel0n's avatar
echel0n committed
225
    - /^[0-9.]+$/
echel0n's avatar
echel0n committed
226
    - /^[0-9.]+dev[0-9]+$/
echel0n's avatar
echel0n committed
227 228 229
  except:
    - branches
    - triggers
230

231 232
deploy:docker:master:
  stage: release_deploy
echel0n's avatar
echel0n committed
233
  variables:
234
    UPSTREAM_BRANCH: master
echel0n's avatar
echel0n committed
235 236 237 238 239
    UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA
  trigger:
    project: sickrage/sickrage-docker
    branch: master
  only:
240
    - /^[0-9.]+$/
echel0n's avatar
echel0n committed
241 242 243 244
  except:
    - branches
    - triggers

245 246
deploy:docker:develop:
  stage: release_deploy
247
  variables:
248
    UPSTREAM_BRANCH: develop
echel0n's avatar
echel0n committed
249
    UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA
250 251 252
  trigger:
    project: sickrage/sickrage-docker
    branch: master
echel0n's avatar
echel0n committed
253
  only:
echel0n's avatar
echel0n committed
254
    - /^[0-9.]+dev[0-9]+$/
255
  except:
echel0n's avatar
echel0n committed
256 257
    - branches
    - triggers
258

259
deploy:synology:master:
260
  stage: release_deploy
261 262 263 264 265 266 267 268
  variables:
    UPSTREAM_BRANCH: master
    UPSTREAM_COMMIT_SHA: $CI_COMMIT_SHA
  trigger:
    project: sickrage/sickrage-synology
    branch: master
  only:
    - /^[0-9.]+$/
269 270 271 272
  except:
    - branches
    - triggers

273
deploy:readynas:master:
274
  stage: release_deploy
275 276 277 278 279 280 281 282 283 284 285 286 287 288
  variables:
    UPSTREAM_COMMIT_TAG: $CI_COMMIT_TAG
    UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
    UPSTREAM_COMMIT_TAG_MESSAGE: $CI_COMMIT_TAG_MESSAGE
    UPSTREAM_PROJECT_ID: $CI_PROJECT_ID
  trigger:
    project: sickrage/sickrage-readynas
    branch: master
  only:
    - /^[0-9.]+$/
  except:
    - branches
    - triggers

289
deploy:qnap:master:
290
  stage: release_deploy
291 292 293 294 295 296 297 298 299 300
  variables:
    UPSTREAM_COMMIT_TAG: $CI_COMMIT_TAG
    UPSTREAM_PROJECT_NAME: $CI_PROJECT_NAME
    UPSTREAM_COMMIT_TAG_MESSAGE: $CI_COMMIT_TAG_MESSAGE
    UPSTREAM_PROJECT_ID: $CI_PROJECT_ID
  trigger:
    project: sickrage/sickrage-qnap
    branch: master
  only:
    - /^[0-9.]+$/
301 302
  except:
    - branches
303
    - triggers