Tom/.gitlab-ci.yml

66 lines
1.7 KiB
YAML
Raw Normal View History

2021-07-28 00:01:17 +02:00
###############################################################
# Setting I use for cleaning up image tags #
# - Running cleanup every day #
# - Keeping 1 tag per image name matching : (?:v.+|dev) #
# - Removing tags older than 7 days matching the default : .* #
###############################################################
2021-07-27 23:22:54 +02:00
image: docker:stable
2021-07-27 23:20:53 +02:00
2021-07-27 22:51:52 +02:00
stages:
- build
2021-07-27 23:20:53 +02:00
- push
2021-07-27 22:51:52 +02:00
2021-07-27 23:24:22 +02:00
services:
- docker:dind
2021-07-27 23:20:53 +02:00
before_script:
2021-07-27 23:24:22 +02:00
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
2021-07-27 22:51:52 +02:00
2021-07-27 23:20:53 +02:00
Build:
2021-07-27 22:41:23 +02:00
stage: build
2021-07-27 22:24:30 +02:00
script:
2021-07-27 23:20:53 +02:00
- docker pull $CI_REGISTRY_IMAGE:latest || true
- >
docker build
--pull
--build-arg VCS_REF=$CI_COMMIT_SHA
--build-arg VCS_URL=$CI_PROJECT_URL
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
.
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
2021-07-27 22:59:04 +02:00
2021-07-27 23:20:53 +02:00
Push latest:
variables:
GIT_STRATEGY: none
stage: push
only:
- main
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
2021-07-27 22:59:04 +02:00
2021-07-27 23:35:37 +02:00
# Push dev:
# variables:
# GIT_STRATEGY: none
# stage: push
# only:
# - dev
# script:
# - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
# - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:dev
# - docker push $CI_REGISTRY_IMAGE:dev
2021-07-27 23:20:53 +02:00
Push tag:
variables:
GIT_STRATEGY: none
stage: push
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