@@ -1,7 +1,9 @@
stages:
- build
- test
+ - containers
include:
- 'automation/gitlab-ci/build.yaml'
- 'automation/gitlab-ci/test.yaml'
+ - 'automation/gitlab-ci/containers.yaml'
@@ -16,9 +16,9 @@ help:
include yocto/yocto.inc
%: %.dockerfile ## Builds containers
- $(DOCKER_CMD) build --pull -t $(REGISTRY)/$(@D):$(@F) -f $< $(<D)
+ $(DOCKER_CMD) build --pull -t $(REGISTRY)/$(@D):$(@F)$(BUILD_CONTAINER_SUFFIX) -f $< $(<D)
@if [ ! -z $${PUSH+x} ]; then \
- $(DOCKER_CMD) push $(REGISTRY)/$(@D):$(@F); \
+ $(DOCKER_CMD) push $(REGISTRY)/$(@D):$(@F)$(BUILD_CONTAINER_SUFFIX); \
fi
.PHONY: all clean
new file mode 100644
@@ -0,0 +1,25 @@
+.container-build-tmpl:
+ stage: containers
+ image: docker:stable
+ tags:
+ - container-builder
+ rules:
+ - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "staging"
+ changes:
+ - automation/build/${BUILD_CONTAINER}.dockerfile
+ services:
+ - docker:dind
+ before_script:
+ - apk add make
+ - docker info
+ - docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
+ script:
+ - make -C automation/build ${BUILD_CONTAINER} PUSH=1 BUILD_CONTAINER_SUFFIX=-test
+ after_script:
+ - docker logout
+
+debian-unstable-container:
+ extends:
+ - .container-build-tmpl
+ variables:
+ BUILD_CONTAINER: debian/unstable
Only run this on the staging branch, whenever the dockerfile changes. Allow to set a suffix when building containers, to be able to test it before changing the one in production. Using "rules" instead of "only" as this allow to use variables in the "changes" rules. Also, "rules" is the preferred keyword as "only/except" isn't being actively developed in GitLab. Use $CI_PIPELINE_SOURCE==push to evaluate "rules:changes" only on push. In most other cases, "rules:changes" evaluate to true so checking CI_PIPELINE_SOURCE is important. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> --- .gitlab-ci.yml | 2 ++ automation/build/Makefile | 4 ++-- automation/gitlab-ci/containers.yaml | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 automation/gitlab-ci/containers.yaml