4e52da09dcc5dd7ba7d3457d83a216ef46216300
[metze/samba-autobuild/.git] / bootstrap / .gitlab-ci.yml
1 services:
2   - docker:dind
3
4 .build_image_template:
5   image: docker:latest
6   stage: images
7   tags:
8     - docker
9     - gce
10   variables:
11     SAMBA_CI_IS_BROKEN_IMAGE: "no"
12   before_script:
13     # Ensure we are generating correct the container
14     - uname -a
15     - cat /etc/os-release
16     - echo "SAMBA_CI_CONTAINER_REGISTRY[${SAMBA_CI_CONTAINER_REGISTRY}]"
17     - echo "SAMBA_CI_CONTAINER_TAG[${SAMBA_CI_CONTAINER_TAG}]"
18     - echo "SAMBA_CI_IS_BROKEN_IMAGE[${SAMBA_CI_IS_BROKEN_IMAGE}]"
19     - echo "SAMBA_CI_REBUILD_IMAGES[${SAMBA_CI_REBUILD_IMAGES}]"
20     - echo "SAMBA_CI_REBUILD_BROKEN_IMAGES[${SAMBA_CI_REBUILD_BROKEN_IMAGES}]"
21     - echo "GITLAB_USER_LOGIN[${GITLAB_USER_LOGIN}]"
22     - echo "${SAMBA_CI_CONTAINER_TAG}" > /tmp/sha1sum-tag.txt
23     - diff -u bootstrap/sha1sum.txt /tmp/sha1sum-tag.txt
24   script: |
25     set -xueo pipefail
26     ci_image_name=samba-ci-${CI_JOB_NAME}
27     docker build -t ${ci_image_name} --build-arg SHA1SUM=${SAMBA_CI_CONTAINER_TAG} bootstrap/generated-dists/${CI_JOB_NAME}
28     ci_image_path="${SAMBA_CI_CONTAINER_REGISTRY}/${ci_image_name}"
29     timestamp=$(date +%Y%m%d%H%M%S)
30     docker_hash=$(docker image inspect --format='{{index .Id}}' ${ci_image_name} | cut -d : -f 2 | cut -c 1-9)
31     timestamp_tag=${SAMBA_CI_CONTAINER_TAG}-${timestamp}-${GITLAB_USER_LOGIN}-${docker_hash}
32     samba_repo_root=/home/samba/samba
33     # Ensure we are generating the correct container that we expect to be in
34     echo "${SAMBA_CI_CONTAINER_TAG}" > /tmp/sha1sum-tag.txt
35     diff -u bootstrap/sha1sum.txt /tmp/sha1sum-tag.txt
36     docker run --volume $(pwd):${samba_repo_root} --workdir ${samba_repo_root} ${ci_image_name} \
37         /bin/bash -c "echo \"${SAMBA_CI_CONTAINER_TAG}\" > /tmp/sha1sum-tag.txt; diff -u bootstrap/sha1sum.txt /tmp/sha1sum-tag.txt"
38     docker run --volume $(pwd):${samba_repo_root} --workdir ${samba_repo_root} ${ci_image_name} \
39         diff -u bootstrap/sha1sum.txt /sha1sum.txt
40     docker run --volume $(pwd):${samba_repo_root} --workdir ${samba_repo_root} ${ci_image_name} \
41         bootstrap/template.py --sha1sum > /tmp/sha1sum-template.txt
42     diff -u bootstrap/sha1sum.txt /tmp/sha1sum-template.txt
43     # run smoke test with samba-o3
44     docker run --volume $(pwd):${samba_repo_root} --workdir ${samba_repo_root} ${ci_image_name} \
45         /bin/bash -c "sudo chown -R samba:samba ./** && export PKG_CONFIG_PATH=/usr/lib64/compat-gnutls34/pkgconfig:/usr/lib64/compat-nettle32/pkgconfig && script/autobuild.py samba-o3 --verbose --nocleanup --keeplogs --tail --testbase /tmp/samba-testbase"
46     docker tag ${ci_image_name} ${ci_image_path}:${SAMBA_CI_CONTAINER_TAG}
47     docker tag ${ci_image_name} ${ci_image_path}:${timestamp_tag}
48     # We build all images, but only upload is it's not marked as broken
49     test x"${SAMBA_CI_IS_BROKEN_IMAGE}" = x"yes" || { \
50         docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY; \
51         docker push ${ci_image_path}:${SAMBA_CI_CONTAINER_TAG}; \
52         docker push ${ci_image_path}:${timestamp_tag}; \
53     }
54     echo "Success for ${ci_image_path}:${timestamp_tag}"
55     test x"${SAMBA_CI_IS_BROKEN_IMAGE}" = x"no" || { \
56          echo "The image ${CI_JOB_NAME} is marked as broken and should have failed!"; \
57          echo "Replace .build_image_template_force_broken with .build_image_template!"; \
58          echo "Add a .samba-o3-template section at the end of the main .gitlab-ci.yml!"; \
59          /bin/false; \
60     }
61   only:
62     variables:
63       #
64       # You need a custom pipeline which passes
65       # SAMBA_CI_REBUILD_IMAGES="yes".
66       #
67       # https://gitlab.com/samba-team/devel/samba/pipelines/new
68       #
69       - $SAMBA_CI_REBUILD_IMAGES == "yes"
70
71 .build_image_template_force_broken:
72   extends: .build_image_template
73   variables:
74     SAMBA_CI_IS_BROKEN_IMAGE: "yes"
75   only:
76     variables:
77       #
78       # You need a custom pipeline which passes
79       # SAMBA_CI_REBUILD_BROKEN_IMAGES="yes"
80       # in order to build broken images for debugging
81       #
82       # https://gitlab.com/samba-team/devel/samba/pipelines/new
83       #
84       - $SAMBA_CI_REBUILD_BROKEN_IMAGES == "yes"
85
86 ubuntu1804:
87   extends: .build_image_template
88
89 debian10:
90   extends: .build_image_template
91
92 fedora31:
93   extends: .build_image_template
94
95 fedora30:
96   extends: .build_image_template
97
98 fedora29:
99   extends: .build_image_template
100
101 centos8:
102   extends: .build_image_template
103
104 centos7:
105   extends: .build_image_template
106   variables:
107     # Shallow copies are not supported by git on CentOS7
108     GIT_DEPTH: ""
109     # We install a compat-gnutls34 package for GnuTLS >= 3.4.7
110     PKG_CONFIG_PATH: /usr/lib64/compat-gnutls34/pkgconfig:/usr/lib64/compat-nettle32/pkgconfig
111
112 opensuse150:
113   extends: .build_image_template
114
115 opensuse151:
116   extends: .build_image_template