.gitlab-ci.yml 2.24 KB
Newer Older
1

2
3
variables:

4
5
6
7
8
9
10
11
12
13
  ### 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
  ###
  ### You shouldn't change the following variables
  NAMESPACE: openshift
14
15
  OPENSHIFT_SERVER: https://openshift-dev.cern.ch

16

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

### '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
Pablo Panero's avatar
Pablo Panero committed
28

29
30
31
32
build_dev_version:
  stage: build
  except:
    - tags
Pablo Panero's avatar
Pablo Panero committed
33
    - master
34
  environment: dev
35
36
  tags:
    - docker-image-build
Pablo Panero's avatar
Pablo Panero committed
37
  script: 'echo "Building Dev/QA Docker image..."'
38
39
40
41
42
43
44
45

### 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
46
  script: 'echo "Building Docker image..."'
47
48
  variables:
    TO: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
49

Pablo Panero's avatar
Pablo Panero committed
50
### If a new tag is pushed it needs to be referenced into the ImageStream
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
tag_image_dev: &tag_image
  stage: tag_image
  only:
  - tags
  environment: staging
  image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
  script:
    - oc tag --source=docker ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} ${RESOURCE}:${CI_COMMIT_TAG} --token=${TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE}
  variables:
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_DEV}

### Import image into OpenShift. Import $CI_COMMIT_TAG if present or 'latest' if not.
import_image_dev:
  stage: import_image
  environment: staging
  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:
Pablo Panero's avatar
Pablo Panero committed
70
    TOKEN: ${SERVICE_ACCOUNT_TOKEN_DEV}