-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
143 lines (119 loc) · 5.71 KB
/
Makefile
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
SHELL=/bin/bash
GitBranch=$(shell git rev-parse --abbrev-ref HEAD)
GitCommit=$(shell git rev-parse --short HEAD)
Date=$(shell date '+%Y%m%d%H%M%S')
BuildTime=$(shell date '+%Y-%m-%d %T%z')
Registry="registry.erda.cloud/erda-actions"
RegistryForPush="registry.erda.cloud/erda-actions"
DevelopRegistry="registry.cn-hangzhou.aliyuncs.com/dice"
ARCH ?= $(shell go env GOARCH)
PLATFORMS ?= linux/arm64,linux/amd64
.ONESHELL:
echo \
custom-script java-agent \
email mysql-assert app-create app-run git-checkout assert jsonparse redis-cli mysql-cli git-push release dice dice-deploy dice-deploy-addon dice-deploy-service \
dice-deploy-domain dice-deploy-release dice-deploy-redeploy dice-deploy-rollback buildpack buildpack-aliyun java java-build js js-build manual-review js-deploy \
dockerfile docker-push php gitbook js-script sonar integration-test unit-test api-test java-lint testplan java-dependency-check golang java-unit android ios \
mobile-template lib-publish mobile-publish java-deploy extract-repo-version release-fetch dingtalk-robot-msg oss-upload delete-nodes ess-info loop api-register \
api-publish publish-api-asset mysqldump archive-release erda-get-addon-info erda-get-service-addr erda-mysql-migration push-extensions archive-extensions \
testscene-run testplan-run contrast-security erda-create-custom-addon project-artifacts project-package semgrep js-pack:
@set -eo pipefail
@echo start make action: $@
version="$${VERSION}"
if [[ "$${version}" == "" ]]; then
if [[ "`ls -l actions/$@ | wc -l | tr -d ' '`" != "2" ]]; then
echo Multi version [$$(echo `ls actions/$@` | sed 's/ /, /g')] detected, which version you want to make? \
specify by env: VERSION=1.0
exit 1
fi
version=`ls actions/$@`
echo Auto select the only version: $${version}
fi
@echo use version: $${version}
@dockerfile="actions/$@/$${version}/Dockerfile"
@echo expected Dockerfile: $${dockerfile}
if [[ ! -f $${dockerfile} ]]; then echo "expected Dockerfile not exist, stop." && exit 1; fi
@builder="$(shell docker buildx ls | grep erda-actions | awk '{print $1}' | head -n 1)"
if [[ "$${builder}" == "" ]]; then docker buildx create --name erda-actions; fi
docker buildx use erda-actions
image="$(Registry)/$@-action:$${version}-$(Date)-${GitCommit}"
imageForPush="$(RegistryForPush)/$@-action:$${version}-$(Date)-${GitCommit}"
@echo image=$${image}
dockerbuild="docker buildx build --push . --platform=$(PLATFORMS) -f $${dockerfile} -t $${imageForPush} \
--label 'branch=$(GitBranch)' --label 'commit=$(GitCommit)' --label 'build-time=$(BuildTime)'"
# --pull
if [[ $@ == "java-dependency-check" ]]; then dockerbuild="$${dockerbuild} --pull"; fi
# --no-cache
if [[ $@ == "buildpack" || $@ == "java" || $@ == "java-build" || $@ == "java-agent" ]]; then
dockerbuild="$${dockerbuild} --no-cache"
fi
if [[ $@ == "golang" ]]; then dockerbuild="$${dockerbuild} --build-arg GO_VERSION=${GO_VERSION}"; fi
@echo $${dockerbuild}
eval "$${dockerbuild}"
echo "action meta: $@($${version})=$${image}"
# auto replace dice.yml image
if [[ "${AUTO_GIT_COMMIT}" == "true" ]]; then
diceyml="actions/$@/$${version}/dice.yml"
yq eval ".jobs.[].image = \"$${image}\"" -i $${diceyml}
git add .
@git commit -m "Auto update image for action: $@, version: $${version}"
fi
.ONESHELL:
sonarqube:
@set -eo pipefail
@echo start make $@
version="$${VERSION}"
sonarDir="actions/sonar/1.0"
if [[ "$${version}" == "" ]]; then
if [[ "`ls -l "$${sonarDir}/$@" | wc -l | tr -d ' '`" != "2" ]]; then
echo Multi version [$$(echo `ls $${sonarDir}/$@` | sed 's/ /, /g')] detected, which version you want to make? \
specify by env: VERSION=1.0
exit 1
fi
version=`ls $${sonarDir}/$@`
echo Auto select the only version: $${version}
fi
@echo use version: $${version}
cd actions/sonar/1.0/sonarqube/$${version}
docker build . -t registry.cn-hangzhou.aliyuncs.com/dice-third-party/sonar:$${version} -f Dockerfile
all-arch:
echo "build all arch for $(action)"
version="$${VERSION}"
if [[ "$${version}" == "" ]]; then
if [[ "`ls -l actions/$@ | wc -l | tr -d ' '`" != "2" ]]; then
echo Multi version [$$(echo `ls actions/$(action)` | sed 's/ /, /g')] detected, which version you want to make? \
specify by env: VERSION=1.0
exit 1
fi
version=`ls actions/$(action)`
echo Auto select the only version: $${version}
fi
@echo use version: $${version}
@dockerfile="actions/$(action)/$${version}/Dockerfile"
@echo expected Dockerfile: $${dockerfile}
if [[ ! -f $${dockerfile} ]]; then echo "expected Dockerfile not exist, stop." && exit 1; fi
arches=(amd64 arm64)
for arch in $${arches[@]}; do
if [[ "$(DEVELOP_MODE)" == 'true' ]]; then
echo "DEVELOP_MODE == true"
image="$(DevelopRegistry)/$$arch/$(action)-action:$${version}-$(Date)-${GitCommit}"
imageForPush=$${image}
else
image="$(Registry)/$$arch/$(action)-action:$${version}-$(Date)-${GitCommit}"
imageForPush="$(RegistryForPush)/$$arch/$(action)-action:$${version}-$(Date)-${GitCommit}"
fi
@echo image=$${image}
dockerbuild="DOCKER_BUILDKIT=1 docker build . --platform "linux/$$arch" --build-arg ARCH=$$arch -f $${dockerfile} -t $${imageForPush} \
--label 'branch=$(GitBranch)' --label 'commit=$(GitCommit)' --label 'build-time=$(BuildTime)'"
# --pull
if [[ $(action) == "java-dependency-check" ]]; then dockerbuild="$${dockerbuild} --pull"; fi
# --no-cache
if [[ $(action) == "buildpack" || $(action) == "java" || $(action) == "java-build" || $(action) == "java-agent" ]]; then
dockerbuild="$${dockerbuild} --no-cache"
fi
if [[ $@ == "golang" ]]; then dockerbuild="$${dockerbuild} --build-arg GO_VERSION=${GO_VERSION}"; fi
@echo $${dockerbuild}
eval "$${dockerbuild}"
docker push $${imageForPush}
echo "action meta: $(action)($${version})-$$arch=$${image}"
done