.gitlab-ci.yml 4.04 KB
Newer Older
1

2
3
variables:

4
5
6
7
8
9
10
  ### Disable cache in Docker builds, as this has occasionally resulted in images not containing what was
  ### expected multiple MRs where being built/retried.
  NO_CACHE: 'true'
  ### Replace RESOURCE with the name of the image you want to build and publish in OpenShift
  ### Important! In order for this template to work, the name of the gitlab repo must match
  ### also the variable name
  RESOURCE: cern-search-rest-api
11
  ### OpenShift namespace and server values
12
13
  NAMESPACE_DEV: test-cern-search-master
  OPENSHIFT_SERVER_DEV: https://openshift-dev.cern.ch
14
15
  NAMESPACE_PROD: cern-search-master
  OPENSHIFT_SERVER_PROD: https://openshift.cern.ch
16

17

18
19
20
21
### By default, there are 6 stages that we may use:
### Feel free to adapt this to your specific case.
stages:
  - build
22
23
24
  - tag_image
  - import_image # This stage is only used when the built image is stored in the GitLab Registry
  - deploy
25
26
27
28

### 'Build' stage
### Build the image and store it in the registry. It is important that this step
### doesn't override the image the applications are running, as we haven't tested the image yet
29
########## DEV ##########
30
31
32
33
build_dev_version:
  stage: build
  except:
    - tags
Pablo Panero's avatar
Pablo Panero committed
34
    - master
35
  environment: staging
36
37
  tags:
    - docker-image-build
Pablo Panero's avatar
Pablo Panero committed
38
  script: 'echo "Building Dev/QA Docker image..."'
39

40
41
42
43
44
45
46
47
48
49
########## PROD ##########
build_prod_version:
  stage: build
  only:
    - master
  environment: master
  tags:
    - docker-image-build
  script: 'echo "Building Prod Docker image..."'

50
########## ALL ##########
51
52
53
54
55
56
57
### When building tags, use the git tag as the docker tag of the image
build_tagged_version:
  stage: build
  only:
    - tags
  tags:
    - docker-image-build
58
  script: 'echo "Building Docker image..."'
59
60
  variables:
    TO: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
61

62
########## DEV ##########
Pablo Panero's avatar
Pablo Panero committed
63
### If a new tag is pushed it needs to be referenced into the ImageStream
64
tag_image_dev: &tag_image_openshift
65
66
67
68
69
70
  stage: tag_image
  only:
  - tags
  environment: staging
  image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
  script:
71
    - oc tag --source=docker ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} ${RESOURCE}:${CI_COMMIT_TAG} --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE}
72
73
  variables:
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_DEV}
74
    NAMESPACE: ${NAMESPACE_DEV}
75
76
77
78
79
80
81
82
    OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_DEV}

########## PROD ##########
### If a new tag is pushed it needs to be referenced into the ImageStream
tag_image_prod:
  <<: *tag_image_openshift
  variables:
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_PROD}
83
    NAMESPACE: ${NAMESPACE_PROD}
84
    OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_PROD}
85

86
########## DEV ##########
87
### Import image into OpenShift. Import $CI_COMMIT_TAG if present or 'latest' if not.
88
import_image_dev:
89
90
  stage: import_image
  environment: staging
91
92
93
94
95
96
97
98
99
100
101
  image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
  script:
    - oc import-image ${RESOURCE}:${CI_COMMIT_TAG:-latest} --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE}
  variables:
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_DEV}
    OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_DEV}
    NAMESPACE: ${NAMESPACE_DEV}

########## PROD ##########
### Import image into OpenShift. Import $CI_COMMIT_TAG if present or 'latest' if not.
import_image_prod:
102
103
104
105
106
107
108
  stage: import_image
  environment: master
  only:
  - tags
  image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
  script:
    - oc import-image ${RESOURCE}:${CI_COMMIT_TAG:-latest} --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE}
109
110
111
  variables:
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_PROD}
    OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_PROD}
112
    NAMESPACE: ${NAMESPACE_PROD}
113
114
115
116
117
118
119
120

########## PROD ##########
deploy_production:
  stage: deploy
  environment: production
  only:
  - tags
  when: manual
121
122
  image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
  script:
123
    - oc --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE} tag ${RESOURCE}:${CI_COMMIT_TAG} ${RESOURCE}:stable
124
  variables:
125
126
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_PROD}
    OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_PROD}
127
    NAMESPACE: ${NAMESPACE_PROD}
128
    GIT_STRATEGY: none