neiam
/cartosnap_ex
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Update .gitlab-ci.yml file
0985ae3 · Gabriel Morell · 2022-06-22 05:26
Files changed
modified
.gitlab-ci.yml
+24
−10
@@ -1,12 +1,26 @@
| 1 | −image: | |
| 2 | − name: gcr.io/kaniko-project/executor:debug | |
| 3 | − entrypoint: [ "" ] | |
| 4 | −build-master: | |
| 5 | − retry: 2 | |
| 1 | +docker-build: | |
| 2 | + # Use the official docker image. | |
| 3 | + image: docker:latest | |
| 6 | 4 | stage: build |
| 5 | + services: | |
| 6 | + - docker:dind | |
| 7 | + before_script: | |
| 8 | + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY | |
| 9 | + # Default branch leaves tag empty (= latest tag) | |
| 10 | + # All other branches are tagged with the escaped branch name (commit ref slug) | |
| 7 | 11 | script: |
| 8 | − - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json | |
| 9 | − - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE --registry-mirror e0.registry.gng.io | |
| 10 | − | |
| 11 | − only: | |
| 12 | − - master | |
| 12 | + - | | |
| 13 | + if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then | |
| 14 | + tag="" | |
| 15 | + echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'" | |
| 16 | + else | |
| 17 | + tag=":$CI_COMMIT_REF_SLUG" | |
| 18 | + echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" | |
| 19 | + fi | |
| 20 | +- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" . | |
| 21 | + - docker push "$CI_REGISTRY_IMAGE${tag}" | |
| 22 | + # Run this job in a branch where a Dockerfile exists | |
| 23 | + rules: | |
| 24 | + - if: $CI_COMMIT_BRANCH | |
| 25 | + exists: | |
| 26 | + - Dockerfile |
Parents: c9d7c0d