This commit is contained in:
sbriat 2023-04-04 11:59:05 +02:00
parent 49e7027987
commit 0778f64416
1 changed files with 37 additions and 4 deletions

View File

@ -3,6 +3,7 @@ image: docker:20.10.22
stages: stages:
- test - test
- build - build
- push
############## ##############
# TEST STAGE # # TEST STAGE #
@ -37,10 +38,42 @@ build:
services: services:
- docker:dind - docker:dind
before_script: before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
script: script:
- docker build --pull -t "$CI_REGISTRY_IMAGE" . # fetches the latest image (not failing if image is not found)
- docker push "$CI_REGISTRY_IMAGE" - docker pull $CI_REGISTRY_IMAGE:latest || true
- >
docker build
--pull
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
.
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
##############
# PUSH STAGE #
##############
push latest:
stage: push
variables:
GIT_STRATEGY: none
before_script:
- echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
only: only:
- main - main
when: manual 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
push tag:
stage: push
variables:
GIT_STRATEGY: none
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