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