CI: only build the images that changed
[platform/upstream/gstreamer.git] / .gitlab-ci.yml
1 stages:
2   - "test"
3   - "build runtime"
4   - "build base"
5   - "manifest"
6   - "build"
7
8 test manifest:
9   variables:
10     GIT_STRATEGY: fetch
11   image: "fedora"
12   stage: "test"
13   before_script:
14     - dnf install -y python3-pytest python3-pytest-cov python3-requests
15   script:
16     - pytest-3 --junitxml=junit.xml --cov=build_manifest gitlab/build_manifest.py
17   only:
18     changes:
19       - "gitlab/build_manifest.py"
20   coverage: '/TOTAL.*\s+(\d+%)$/'
21   artifacts:
22     reports:
23       junit:
24         - "junit.xml"
25   only:
26     changes:
27       - gitlab/build_manifest.py
28
29 .base:
30   image: "docker:stable"
31   services:
32     - docker:dind
33   variables:
34     # When using dind, it's wise to use the overlayfs driver for
35     # improved performance.
36     DOCKER_DRIVER: "overlay2"
37     GIT_STRATEGY: fetch
38   script:
39     - export IMAGE="${CI_REGISTRY_IMAGE}/${ARCH}/${TAG}"
40     - export REF="${IMAGE}:${CI_COMMIT_SHA}"
41     - export LATEST="${IMAGE}:latest"
42
43     - docker build --pull -f ${DOCKERFILE} -t ${REF} ${CONTEXT_DIR}
44     - docker image tag ${REF} ${LATEST}
45
46     # If we are in a fork, push the image to the reigstry regardless the branch
47     - |
48       if [ "$CI_PROJECT_NAMESPACE" != "gstreamer" ]; then
49         docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
50         docker push ${REF}
51         docker push ${LATEST}
52       fi
53
54     # Push the images to the upstream registry
55     - |
56       if [ "$CI_COMMIT_REF_NAME" = "master" -a "$CI_PROJECT_NAMESPACE" = "gstreamer" ]; then
57         docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
58         docker push ${REF}
59         docker push ${LATEST}
60       fi
61
62 alpine amd64 manifest builder docker:
63   stage: "build runtime"
64   variables:
65     ARCH: "amd64"
66     TAG: "alpine-manifest-build"
67     CONTEXT_DIR: "docker/runtime-images/"
68     DOCKERFILE: "docker/runtime-images/Dockerfile-manifest-builder"
69   extends: .base
70   only:
71     changes:
72       - 'docker/runtime-images/Dockerfile-manifest-builder'
73       - 'gitlab/build_manifest.py'
74
75 fedora amd64 run docker:
76   stage: "build runtime"
77   variables:
78     ARCH: "amd64"
79     TAG: "fedora-runtime"
80     CONTEXT_DIR: "docker/runtime-images/"
81     DOCKERFILE: "docker/runtime-images/Dockerfile-fedora"
82   extends: .base
83   only:
84     changes:
85       - 'docker/runtime-images/Dockerfile-fedora'
86
87 fedora amd64 build docker:
88   stage: "build base"
89   variables:
90     ARCH: "amd64"
91     TAG: "fedora-build"
92     CONTEXT_DIR: "docker/build-base-images/"
93     DOCKERFILE: "docker/build-base-images/Dockerfile-fedora"
94   extends: .base
95   only:
96     changes:
97       - 'docker/build-base-images/Dockerfile-fedora'
98
99 include: "gitlab/ci_template.yml"
100
101 # Test the build job against the latest build image tag and the local manifest
102 build fedora x86_64 local:
103   extends: '.build'
104   image: "${CI_REGISTRY_IMAGE}/amd64/fedora-build:latest"
105   dependencies:
106     - 'manifest'