specify services and image outside of the jobs

This commit is contained in:
Patrick Jentsch 2019-06-04 12:10:12 +02:00
parent 2d65189d96
commit e0e77d1164

View File

@ -1,3 +1,8 @@
image: docker:latest
services:
- docker:dind
stages:
- build
- push
@ -6,41 +11,32 @@ before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
Build:
image: docker:latest
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build --pull -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
services:
- docker:dind
stage: build
tags:
- docker
Push latest:
image: docker:latest
only:
- master
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
services:
- docker:dind
stage: push
tags:
- docker
Push tag:
image: docker:latest
only:
- tags
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
services:
- docker:dind
stage: push
tags:
- docker