Use own ruby image for production CI
[leap_se.git] / .gitlab-ci.yml
1 ---
2
3 variables:
4   OPENSHIFT_SERVER: hexacab.org:8443
5   OPENSHIFT_DOMAIN: apps.hexacab.org
6   PROJECT_NAME: leapse
7   # Configure this variable in Secure Variables:
8   # OPENSHIFT_TOKEN: my.openshift.token
9
10 stages:
11   - review
12   - production
13   - cleanup
14
15 .deploy: &deploy
16   image: ayufan/openshift-cli
17   before_script:
18     - oc login "${OPENSHIFT_SERVER}" --token="${OPENSHIFT_TOKEN}"
19     - oc project "${PROJECT_NAME}-${CI_PROJECT_ID}" 2> /dev/null || oc new-project "${PROJECT_NAME}-${CI_PROJECT_ID}"
20   script:
21     - "oc get services ${APP} 2> /dev/null || oc new-app ${CI_REPOSITORY_URL}#${CI_COMMIT_REF_NAME} --name=${APP} --strategy=docker && sleep 3 && oc logs -f bc/${APP}"
22     - "oc status -v"
23     - "oc expose dc ${APP} --port=8080 && oc expose service ${APP} --port=8080 --hostname=${PROJECT_NAME}-${CI_ENVIRONMENT_SLUG}.${OPENSHIFT_DOMAIN}"
24
25 review:
26   <<: *deploy
27   stage: review
28   variables:
29     APP: review-$CI_COMMIT_REF_NAME
30     APP_HOST: $PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
31   environment:
32     name: review/$CI_COMMIT_REF_NAME
33     url: http://$PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$OPENSHIFT_DOMAIN
34     on_stop: stop-review
35   only:
36     - branches
37   except:
38     - master
39
40 stop-review:
41   <<: *deploy
42   stage: cleanup
43   script:
44     - oc delete all -l "app=$APP"
45   when: manual
46   variables:
47     APP: review-$CI_COMMIT_REF_NAME
48     GIT_STRATEGY: none
49   environment:
50     name: review/$CI_COMMIT_REF_NAME
51     action: stop
52   only:
53     - branches
54   except:
55     - master
56
57 production:
58   image: 0xacab.org:4567/leap/docker/ruby:stretch_amd64
59   stage: production
60   environment:
61     name: production
62   only:
63     - master
64   before_script:
65     # install ssh-agent
66     - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
67     # run ssh-agent
68     - eval $(ssh-agent -s)
69     # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
70     # see https://gitlab.com/gitlab-org/gitlab-ee/issues/2940 for fixing
71     # broken line endings
72     - ssh-add <(echo "$SSH_PRIVATE_KEY" | sed 's/\r$//')
73   script:
74     - apt-get update
75     - apt-get install -y --no-install-recommends capistrano
76     - cap deploy