.gitlab-ci.yml 4.99 KB
Newer Older
1
2
3
stages:
  - check
  - build
4
  - clean_up
Clemens Lange's avatar
Clemens Lange committed
5

6
7
8
# Triggered when the latest commit contains changes to cms/cvmfs/standalone
# Triggers the pipeline for every folder containing changes
check_changes_pipeline:
9
  stage: check
10
11
  rules:
    - changes: [cc7-cms/*, cc7-cvmfs/*, slc6-cms/*, slc6-cvmfs/*, slc5-cms/*, standalone/*]
12
      if: $CI_PIPELINE_SOURCE == 'push' # Trigger if push (for test on branches)
13
  tags:
14
      - docker # tags docker since those runners have git installed (needed by check.sh)
15
  script:
16
    - echo "Pipeline source - $CI_PIPELINE_SOURCE"
17
18
    - ./check.sh

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Test template for all images
# Tagged $DATE-$CI_COMMIT_SHORT_SHA
# Pushed to gitlab registry under name test
.test_all_template: &test_all
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - export DATE=$(date +"%Y-%m-%d")
    - if [[ $IMAGE_NAME == "standalone" ]]; then REPO_NAME=standalone; else REPO_NAME=$IMAGE_NAME; fi
    - echo "Pipeline source - $CI_PIPELINE_SOURCE"
    - echo "Building test image - $IMAGE_NAME"
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}, \"$DOCKER_REGISTRY\":{\"auth\":\"${DOCKER_AUTH}\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/$REPO_NAME --dockerfile $CI_PROJECT_DIR/$REPO_NAME/Dockerfile --destination $CI_REGISTRY_IMAGE/test:$IMAGE_NAME-$DATE-$CI_COMMIT_SHORT_SHA --build-arg=BUILD_DATE="$DATE" --build-arg=VERSION="$DATE" --build-arg=VCS_URL="$CI_REPOSITORY_URL" --build-arg=VCS_REF="$CI_COMMIT_SHORT_SHA"

# Build template for cms/cvmfs images
# Tagged $DATE-$CI_COMMIT_SHORT_SHA and latest
# Pushed to gitlab registry and Docker Hub (only latest) 
37
.build_cms_cvmfs_template: &build_cms_cvmfs
38
39
40
41
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
42
    - export DATE=$(date +"%Y-%m-%d")
43
44
    - echo "Pipeline source - $CI_PIPELINE_SOURCE"
    - echo "Building image - $IMAGE_NAME"
45
    - export DOCKER_AUTH="$(echo -n $DOCKER_USER:$DOCKER_PASS | base64)" # https://github.com/GoogleContainerTools/kaniko#pushing-to-docker-hub
46
47
48
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}, \"$DOCKER_REGISTRY\":{\"auth\":\"${DOCKER_AUTH}\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/$IMAGE_NAME --dockerfile $CI_PROJECT_DIR/$IMAGE_NAME/Dockerfile --destination $CI_REGISTRY_IMAGE/$IMAGE_NAME:$DATE-$CI_COMMIT_SHORT_SHA --destination $CI_REGISTRY_IMAGE/$IMAGE_NAME:latest --destination  $DOCKER_GROUP/$IMAGE_NAME:latest --build-arg=BUILD_DATE="$DATE" --build-arg=VERSION="$DATE" --build-arg=VCS_URL="$CI_REPOSITORY_URL" --build-arg=VCS_REF="$CI_COMMIT_SHORT_SHA"

49
50
51
# Build template for standalone images
# Tagged $DATE-$CI_COMMIT_SHORT_SHA
# Pushed to gitlab registry
52
53
54
55
56
57
.build_standalone_template: &build_standalone
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - export DATE=$(date +"%Y-%m-%d")
58
    - export IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]') # IMAGE_NAME is given in lowercase to please docker image naming rules
59
60
    - echo "Pipeline source - $CI_PIPELINE_SOURCE"
    - echo "Building image - $IMAGE_NAME"
61
    - printf "Release - $RELEASE\nScram Arch - $SCRAM_ARCH\nBase image - $BASE_IMAGE\n"
62
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
63
    - /kaniko/executor --context $CI_PROJECT_DIR/$REPO_NAME --dockerfile $CI_PROJECT_DIR/$REPO_NAME/Dockerfile --destination $CI_REGISTRY_IMAGE/$IMAGE_NAME:$DATE-$CI_COMMIT_SHORT_SHA --build-arg=BUILD_DATE="$DATE" --build-arg=VERSION="$DATE" --build-arg=VCS_URL="$CI_REPOSITORY_URL" --build-arg=VCS_REF="$CI_COMMIT_SHORT_SHA" --build-arg BASEIMAGE="$BASE_IMAGE" --build-arg SCRAM_ARCH="$SCRAM_ARCH" --build-arg CMSSW_VERSION="$RELEASE"
64
65
66
67
    - echo "export IMAGE_PATH=$CI_REGISTRY_IMAGE/$IMAGE_NAME:$DATE-$CI_COMMIT_SHORT_SHA" > standalone_image_path.env
  artifacts:
    paths:
      - standalone_image_path.env # Pass image path to clean_up job
68

69
70
71
72
73
74
75
76
77
78
test_all_pipeline:
  <<: *test_all
  stage: build
  only:
    variables:
      - $IMAGE_NAME
      - $TEST
  except:
    refs:
      - master
79
80
  tags:
    - docker-privileged
Clemens Lange's avatar
Clemens Lange committed
81
82

build_cms_cvmfs_pipeline:
83
  <<: *build_cms_cvmfs
Clemens Lange's avatar
Clemens Lange committed
84
85
86
87
  stage: build
  only:
    variables:
      - $IMAGE_NAME
88
89
    refs:
      - master
90
  variables:
91
92
    DOCKER_GROUP: cmscloud
    DOCKER_REGISTRY: https://index.docker.io/v1/
93
94
  tags:
    - docker-privileged
95
96

build_standalone_pipeline:
97
  <<: *build_standalone
98
99
100
101
  stage: build
  only:
    variables:
      - $RELEASE && $SCRAM_ARCH && $OS
102
103
    refs:
      - master
104
105
106
  tags:
    - docker-privileged-xl
  variables:
107
    IMAGE_NAME: $RELEASE-$SCRAM_ARCH
108
    REPO_NAME: standalone
109
110
    BASE_IMAGE: "$CI_REGISTRY_IMAGE/$OS-cms:latest"
  # Necessary variables to be passed to Dockerfile for building a standalone image is CMSSW_VERSION=$RELEASE,
111
  # SCRAM_ARCH=$SCRAM_ARCH and BASEIMAGE="gitlab-registry.cern.ch/cms-cloud/cmssw-docker/$OS-cms:latest"