-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
70 lines (63 loc) · 1.64 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
stages:
- verify
- build
- test
- publish
# YAML anchor for login command which will be used in multiple places
.docker_login: &docker_login |
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
.crane_auth: &crane_auth |
crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
lint:
stage: verify
image: registry.gitlab.com/pipeline-components/hadolint:latest
script:
- hadolint -t warning ./Dockerfile
except:
- tags
build:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- *docker_login # Use the defined YAML anchor
- /kaniko/executor
--context $CI_PROJECT_DIR
--dockerfile $CI_PROJECT_DIR/Dockerfile
--destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
--snapshotMode=redo
--use-new-run
timeout: 2h
test:
stage: test
image:
name: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
entrypoint: [""]
script:
- echo "OK"
except:
- tags
publish:
stage: publish
image:
name: gcr.io/go-containerregistry/crane:debug
entrypoint: [""]
before_script:
- *crane_auth # Use the defined YAML anchor
script:
- crane tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME $CI_COMMIT_REF_NAME
except:
- main
publish_latest:
stage: publish
image:
name: gcr.io/go-containerregistry/crane:debug
entrypoint: [""]
before_script:
- *crane_auth # Use the defined YAML anchor
script:
- crane tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME latest
only:
- main