-
Notifications
You must be signed in to change notification settings - Fork 3
/
codefresh.yml
100 lines (91 loc) · 2.88 KB
/
codefresh.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
version: "1.0"
stages:
- clone
- prepare
- build
- release
steps:
main_clone:
title: 'Cloning main repository...'
stage: clone
type: git-clone
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
revision: ${{CF_BRANCH}}
git: ${{GIT_CONTEXT}}
prepare_env_vars:
title: 'Preparing environment variables...'
stage: prepare
image: codefreshio/ci-helpers
working_directory: ${{main_clone}}
commands:
- cf_export DOCKER_VERSION=20.10.13
- cf_export SERVICE_VERSION=$(yq r service.yaml version)
- cf_export IMAGE_NAME=codefresh/dind
validate_version:
title: 'Validating the service version...'
stage: prepare
image: codefreshio/ci-helpers
fail_fast: false
commands:
- |
err() { echo -e "\e[31m$@\e[0m" ; return 1 ; }
ok() { echo -e "\e[32m$@\e[0m" ; return 0 ; }
current_version=${SERVICE_VERSION}
last_version=$(git describe --abbrev=0 --tags)
echo "Current version is $current_version, last version - $last_version"
semver-cli greater $current_version $last_version && ok "Version check ok" || err "Please the update the version in the service.yaml file"
build_image:
title: "Building the image..."
stage: build
type: build
working_directory: ${{main_clone}}
build_arguments:
- DOCKER_VERSION=${{DOCKER_VERSION}}
dockerfile: ./Dockerfile
image_name: ${{IMAGE_NAME}}
tag: ${{CF_BRANCH_TAG_NORMALIZED}}
approve_existing_version_update:
type: pending-approval
stage: release
title: "Are you sure you want to update already existing image version?"
description: |
"Used for reverting changes without raising the service version"
when:
branch:
only: [master]
steps:
- name: validate_version
on:
- failure
release:
type: parallel
stage: release
steps:
add_git_tag:
title: "Adding Git tag..."
stage: release
image: codefreshio/ci-helpers
commands:
- source /get-token/get-gh-token.sh
- |
curl --fail -X POST -d '{"ref": "refs/tags/${{SERVICE_VERSION}}","sha": "${{CF_REVISION}}"}' -H "Content-Type: application/json" -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}/git/refs
when:
branch:
only: [master]
steps:
- name: validate_version
on:
- success
push_image_prod:
type: push
title: "Pushing the image to the public registry..."
stage: release
image_name: '${{IMAGE_NAME}}'
registry: "${{REGISTRY_INTEGRATION}}"
candidate: "${{build_image}}"
tags:
- "${{DOCKER_VERSION}}-v${{SERVICE_VERSION}}"
- "latest"
when:
branch:
only: [master]