# stages: # - build # - test # - deploy # services: # - docker:stable-dind # build-latest: # image: docker:stable # stage: build # only: # - main # script: # - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY # - docker pull $CI_REGISTRY_IMAGE:latest || true # - docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE . # - docker tag $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:latest # - docker push $CI_REGISTRY_IMAGE:latest image: docker:stable stages: - build - push before_script: - echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY Build: stage: build script: - 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 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 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