centos-ci.yml 6.73 KB
Newer Older
1 2
#
# THIS FILE IS GENERATED, DO NOT EDIT
3
#
4 5 6

################################################################################
#
7
# Centos checks
8 9 10
#
################################################################################

11 12 13 14 15 16 17 18 19
include:
  - local: '/templates/centos.yml'


stages:
  - centos_container_build
  - centos_check


20 21 22 23 24 25
#
# Common variable definitions
#
.ci-commons-centos:
  variables:
    FDO_DISTRIBUTION_PACKAGES: 'wget curl'
26
    FDO_DISTRIBUTION_EXEC: 'sh test/script.sh'
27
    FDO_DISTRIBUTION_VERSION: '7'
28
    FDO_EXPIRES_AFTER: '1h'
29

Jonas Ådahl's avatar
Jonas Ådahl committed
30 31 32 33 34 35 36 37 38 39
.ci-commons-centos@x86_64:
  extends: .ci-commons-centos
  variables:
    FDO_DISTRIBUTION_TAG: fdo-ci-x86_64-$CI_PIPELINE_ID

.ci-commons-centos@aarch64:
  extends: .ci-commons-centos
  variables:
    FDO_DISTRIBUTION_TAG: fdo-ci-aarch64-$CI_PIPELINE_ID

40 41 42
#
# A few templates to avoid writing the image and stage in each job
#
Jonas Ådahl's avatar
Jonas Ådahl committed
43
.centos:ci@container-build@x86_64:
44
  extends:
Jonas Ådahl's avatar
Jonas Ådahl committed
45 46
    - .fdo.container-build@centos@x86_64
    - .ci-commons-centos@x86_64
47
  image: $CI_REGISTRY_IMAGE/x86_64/buildah:2020-12-16.4
48 49 50 51 52 53
  stage: centos_container_build


#
# generic centos checks
#
Jonas Ådahl's avatar
Jonas Ådahl committed
54
.centos@check@x86_64:
55
  extends:
56
    - .fdo.distribution-image@centos
Jonas Ådahl's avatar
Jonas Ådahl committed
57
    - .ci-commons-centos@x86_64
58 59
  stage: centos_check
  script:
60 61 62 63
      # run both curl and wget because one of those two is installed and one is
      # in the base image, but it depends on the distro which one
    - curl --insecure https://gitlab.freedesktop.org
    - wget --no-check-certificate https://gitlab.freedesktop.org
64 65 66
      # make sure our test script has been run
    - if [[ -e /test_file ]] ;
      then
67
        echo $FDO_DISTRIBUTION_EXEC properly run ;
68 69 70 71 72 73 74 75
      else
        exit 1 ;
      fi


#
# straight centos build and test
#
Jonas Ådahl's avatar
Jonas Ådahl committed
76 77
centos:7@container-build@x86_64:
  extends: .centos:ci@container-build@x86_64
78 79


Jonas Ådahl's avatar
Jonas Ådahl committed
80 81
centos:7@check@x86_64:
  extends: .centos@check@x86_64
82
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
83
    - centos:7@container-build@x86_64
84

85 86 87
# Test FDO_BASE_IMAGE. We don't need to do much here, if our
# FDO_DISTRIBUTION_EXEC script can run curl+wget this means we're running on
# the desired base image. That's good enough.
Jonas Ådahl's avatar
Jonas Ådahl committed
88 89
centos:7@base-image@x86_64:
  extends: centos:7@container-build@x86_64
90 91 92
  stage: centos_check
  variables:
    # We need to duplicate FDO_DISTRIBUTION_TAG here, gitlab doesn't allow nested expansion
Jonas Ådahl's avatar
Jonas Ådahl committed
93
    FDO_BASE_IMAGE: registry.freedesktop.org/$CI_PROJECT_PATH/centos/7:fdo-ci-x86_64-$CI_PIPELINE_ID
94 95 96
    FDO_DISTRIBUTION_PACKAGES: ''
    FDO_DISTRIBUTION_EXEC: 'test/test-wget-curl.sh'
    FDO_FORCE_REBUILD: 1
Jonas Ådahl's avatar
Jonas Ådahl committed
97
    FDO_DISTRIBUTION_TAG: fdo-ci-baseimage-x86_64-$CI_PIPELINE_ID
98
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
99
    - centos:7@container-build@x86_64
100

101 102 103
#
# /cache centos check (in build stage)
#
104 105
# Also ensures setting FDO_FORCE_REBUILD will do the correct job
#
Jonas Ådahl's avatar
Jonas Ådahl committed
106 107
centos@cache-container-build@x86_64:
  extends: .centos:ci@container-build@x86_64
108 109 110 111 112 113 114 115 116 117 118 119 120
  before_script:
      # The template normally symlinks the /cache
      # folder, but we want a fresh new one for the
      # tests.
    - mkdir runner_cache_$CI_PIPELINE_ID
    - uname -a | tee runner_cache_$CI_PIPELINE_ID/foo-$CI_PIPELINE_ID

  artifacts:
    paths:
      - runner_cache_$CI_PIPELINE_ID/*
    expire_in: 1 week

  variables:
Jonas Ådahl's avatar
Jonas Ådahl committed
121
    FDO_DISTRIBUTION_TAG: fdo-ci-cache-x86_64-$CI_PIPELINE_ID
122 123
    FDO_DISTRIBUTION_EXEC: 'bash test/test_cache.sh $CI_PIPELINE_ID'
    FDO_CACHE_DIR: $CI_PROJECT_DIR/runner_cache_$CI_PIPELINE_ID
124
    FDO_FORCE_REBUILD: 1
125 126 127 128

#
# /cache centos check (in check stage)
#
Jonas Ådahl's avatar
Jonas Ådahl committed
129
centos@cache-check@x86_64:
130 131 132
  stage: centos_check
  image: alpine:latest
  script:
Jonas Ådahl's avatar
Jonas Ådahl committed
133
    # in the previous stage (centos@cache-container-build@x86_64),
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    # test/test_cache.sh checked for the existance of `/cache/foo-$CI_PIPELINE_ID`
    # and if it found it, it wrote `/cache/bar-$CI_PIPELINE_ID`.
    #
    # So if we have in the artifacts `bar-$CI_PIPELINE_ID`, that means
    # 2 things:
    # - /cache was properly mounted while building the container
    # - the $FDO_CACHE_DIR has been properly written from within the
    #   building container, meaning the /cache folder has been successfully
    #   updated.
    - if [ -e $CI_PROJECT_DIR/runner_cache_$CI_PIPELINE_ID/bar-$CI_PIPELINE_ID ] ;
      then
        echo Successfully read/wrote the cache folder, all good ;
      else
        echo FAILURE while retrieving the previous artifacts ;
        exit 1 ;
      fi
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
151
    - job: centos@cache-container-build@x86_64
152 153 154
      artifacts: true


155 156 157
#
# make sure we do not rebuild the image if the tag exists (during the check)
#
Jonas Ådahl's avatar
Jonas Ådahl committed
158 159
do not rebuild centos:7@container-build@x86_64:
  extends: .centos:ci@container-build@x86_64
160 161
  stage: centos_check
  variables:
162 163
    FDO_UPSTREAM_REPO: $CI_PROJECT_PATH
    FDO_DISTRIBUTION_PACKAGES: 'this-package-should-not-exist'
164
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
165
    - centos:7@container-build@x86_64
166 167


168 169 170
#
# check if the labels were correctly applied
#
Jonas Ådahl's avatar
Jonas Ådahl committed
171
check labels centos@x86_64:7:
172
  extends:
Jonas Ådahl's avatar
Jonas Ådahl committed
173
    - centos:7@check@x86_64
174
  image: $CI_REGISTRY_IMAGE/x86_64/buildah:2020-12-16.4
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  script:
    # FDO_DISTRIBUTION_IMAGE still has indirections
    - DISTRO_IMAGE=$(eval echo ${FDO_DISTRIBUTION_IMAGE})

    # retrieve the infos from the registry (once)
    - JSON_IMAGE=$(skopeo inspect docker://$DISTRO_IMAGE)

    # parse all the labels we care about
    - IMAGE_PIPELINE_ID=$(echo $JSON_IMAGE | jq -r '.Labels["fdo.pipeline_id"]')
    - IMAGE_JOB_ID=$(echo $JSON_IMAGE | jq -r '.Labels["fdo.job_id"]')
    - IMAGE_PROJECT=$(echo $JSON_IMAGE | jq -r '.Labels["fdo.project"]')
    - IMAGE_COMMIT=$(echo $JSON_IMAGE | jq -r '.Labels["fdo.commit"]')

    # some debug information
    - echo $JSON_IMAGE
    - echo $IMAGE_PIPELINE_ID $CI_PIPELINE_ID
    - echo $IMAGE_JOB_ID
    - echo $IMAGE_PROJECT $CI_PROJECT_PATH
    - echo $IMAGE_COMMIT $CI_COMMIT_SHA

    # ensure the labels are correct (we are on the same pipeline)
    - '[[ x"$IMAGE_PIPELINE_ID" == x"$CI_PIPELINE_ID" ]]'
    - '[[ x"$IMAGE_JOB_ID" != x"" ]]' # we don't know the job ID, but it must be set
    - '[[ x"$IMAGE_PROJECT" == x"$CI_PROJECT_PATH" ]]'
    - '[[ x"$IMAGE_COMMIT" == x"$CI_COMMIT_SHA" ]]'
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
201
    - centos:7@container-build@x86_64
202 203


204 205 206
#
# make sure we do not rebuild the image if the tag exists in the upstream
# repository (during the check)
207
# special case where FDO_REPO_SUFFIX == ci_templates_test_upstream
208
#
Jonas Ådahl's avatar
Jonas Ådahl committed
209 210
pull upstream centos:7@container-build@x86_64:
  extends: .centos:ci@container-build@x86_64
211 212
  stage: centos_check
  variables:
213
    FDO_UPSTREAM_REPO: $CI_PROJECT_PATH
214
    FDO_REPO_SUFFIX: centos/ci_templates_test_upstream
215
    FDO_DISTRIBUTION_PACKAGES: 'this-package-should-not-exist'
216
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
217
    - centos:7@container-build@x86_64
218 219 220 221 222

#
# Try our centos scripts with other versions and check
#

Jonas Ådahl's avatar
Jonas Ådahl committed
223 224
centos:8@container-build@x86_64:
  extends: .centos:ci@container-build@x86_64
225
  variables:
226
    FDO_DISTRIBUTION_VERSION: '8'
227

Jonas Ådahl's avatar
Jonas Ådahl committed
228 229
centos:8@check@x86_64:
  extends: .centos@check@x86_64
230 231
  variables:
    FDO_DISTRIBUTION_VERSION: '8'
232
  needs:
Jonas Ådahl's avatar
Jonas Ådahl committed
233
    - centos:8@container-build@x86_64