forked from nginx/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.packaging
184 lines (158 loc) · 9.75 KB
/
Makefile.packaging
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/make -f
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Variable Definitions #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
PACKAGES_DIR := ./build/packages
GITHUB_PACKAGES_DIR := ./build/github/packages
GPG_PUBLIC_KEY := .key
DEB_DISTROS?=ubuntu-jammy-22.04 ubuntu-focal-20.04 ubuntu-bionic-18.04 debian-bullseye-11 debian-buster-10
DEB_ARCHS?=arm64 amd64
RPM_DISTROS?=centos-7-x86_64 oraclelinux-7-x86_64 oraclelinux-8-x86_64 oraclelinux-9-x86_64 suse-12-x86_64 suse-15-x86_64
RPM_ARCH=x86_64
REDHAT_VERSIONS?=redhatenterprise-7 redhatenterprise-8 redhatenterprise-9
REDHAT_ARCHS?=aarch64 x86_64
ROCKY_VERSIONS?=rocky-8 rocky-9
ROCKY_ARCHS?=aarch64 x86_64
FREEBSD_DISTROS?="FreeBSD:12:amd64" "FreeBSD:13:amd64"
APK_VERSIONS?=3.13 3.14 3.15 3.16 3.17
APK_ARCHS?=aarch64 x86_64
ALMA_VERSIONS?=almalinux-8 almalinux-9
ALMA_ARCHS?=aarch64 x86_64
AMAZON_VERSIONS?=amazon-2
AMAZON_ARCHS?=aarch64 x86_64
UPLOAD_URL := "https://up-ap.nginx.com/"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Release Packaging #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
clean-packages:
rm -rf $(PACKAGES_DIR)
rm -rf $(GITHUB_PACKAGES_DIR)
$(PACKAGES_DIR):
@mkdir -p $(PACKAGES_DIR)/deb && mkdir -p $(PACKAGES_DIR)/rpm && mkdir -p $(PACKAGES_DIR)/apk && mkdir -p $(PACKAGES_DIR)/txz
$(GITHUB_PACKAGES_DIR):
@mkdir -p $(GITHUB_PACKAGES_DIR)
package: gpg-key $(PACKAGES_DIR) $(GITHUB_PACKAGES_DIR) ## Create final packages for all supported distros
# Create deb packages
@for arch in $(DEB_ARCHS); do \
GOWORK=off CGO_ENABLED=0 GOARCH=$${arch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for distro in $(DEB_DISTROS); do \
deb_codename=`echo $$distro | cut -d- -f 2`; \
VERSION=$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager deb --target ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb; \
cp ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')~$${deb_codename}_$${arch}.deb; \
done; \
rm -rf ./build/nginx-agent; \
done; \
# Create rpm packages
@GOWORK=off CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent
@for distro in $(RPM_DISTROS); do \
rpm_distro=`echo $$distro | cut -d- -f 1`; \
rpm_major=`echo $$distro | cut -d- -f 2`; \
rpm_codename='na'; \
if [ "$$rpm_distro" = "centos" ] || [ "$$rpm_distro" = "redhatenterprise" ]; then rpm_codename="el$$rpm_major"; \
elif [ "$$rpm_distro" = "oraclelinux" ]; then rpm_codename="oraclelinux$$rpm_major"; \
elif [ "$$rpm_distro" = "amazon" ] && [ "$$rpm_major" = "2" ]; then rpm_codename="amzn$$rpm_major"; \
elif [ "$$rpm_distro" = "suse" ]; then rpm_codename="sles$$rpm_major"; \
fi; \
if [ "$$rpm_codename" != "na" ]; then \
VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=amd64 nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.${RPM_ARCH}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$(RPM_ARCH).rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.${RPM_ARCH}.rpm; \
fi; \
done; \
rm -rf ./build/nginx-agent
# Create redhat rpm packages
@for arch in $(REDHAT_ARCHS); do \
goarch=amd64; \
if [ "$$arch" = "aarch64" ]; then goarch="arm64"; fi; \
GOWORK=off CGO_ENABLED=0 GOARCH=$${goarch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for distro in $(REDHAT_VERSIONS); do \
rpm_distro=`echo $$distro | cut -d- -f 1`; \
rpm_major=`echo $$distro | cut -d- -f 2`; \
rpm_codename="el$$rpm_major"; \
VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
done; \
rm -rf ./build/nginx-agent; \
done; \
# Create almalinux rpm packages
@for arch in $(ALMA_ARCHS); do \
goarch=amd64; \
if [ "$$arch" = "aarch64" ]; then goarch="arm64"; fi; \
GOWORK=off CGO_ENABLED=0 GOARCH=$${goarch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for distro in $(ALMA_VERSIONS); do \
rpm_distro=`echo $$distro | cut -d- -f 1`; \
rpm_major=`echo $$distro | cut -d- -f 2`; \
rpm_codename="almalinux$$rpm_major"; \
VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
done; \
rm -rf ./build/nginx-agent; \
done; \
# Create rocky rpm packages
@for arch in $(ROCKY_ARCHS); do \
goarch=amd64; \
if [ "$$arch" = "aarch64" ]; then goarch="arm64"; fi; \
GOWORK=off CGO_ENABLED=0 GOARCH=$${goarch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for distro in $(ROCKY_VERSIONS); do \
rpm_distro=`echo $$distro | cut -d- -f 1`; \
rpm_major=`echo $$distro | cut -d- -f 2`; \
rpm_codename='na'; \
if [ "$$rpm_distro" = "rocky" ]; then rpm_codename="rocky$$rpm_major"; fi; \
if [ "$$rpm_codename" != "na" ]; then \
VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
fi; \
done; \
rm -rf ./build/nginx-agent; \
done; \
@for arch in $(AMAZON_ARCHS); do \
goarch=amd64; \
if [ "$$arch" = "aarch64" ]; then goarch="arm64"; fi; \
GOWORK=off CGO_ENABLED=0 GOARCH=$${goarch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for distro in $(AMAZON_VERSIONS); do \
rpm_distro=`echo $$distro | cut -d- -f 1`; \
rpm_major=`echo $$distro | cut -d- -f 2`; \
rpm_codename="amazon$$rpm_major"; \
VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').$${rpm_codename}.ngx.$${arch}.rpm; \
done; \
rm -rf ./build/nginx-agent; \
done; \
# Create apk packages
@for arch in $(APK_ARCHS); do \
goarch=amd64; \
if [ "$$arch" = "aarch64" ]; then goarch="arm64"; fi; \
GOWORK=off CGO_ENABLED=0 GOARCH=$${goarch} GOOS=linux go build -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for version in $(APK_VERSIONS); do \
if [ ! -d "$(PACKAGES_DIR)/apk/v$${version}/$${arch}" ]; then mkdir -p $(PACKAGES_DIR)/apk/v$${version}/$${arch}; fi; \
VERSION=$(shell echo ${VERSION} | tr -d 'v') ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager apk --target $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').apk; \
cp $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v').apk ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-$(shell echo ${VERSION} | tr -d 'v')-v$${version}-$${arch}.apk; \
done; \
rm -rf ./build/nginx-agent; \
done; \
# Create txz packages
rm -rf ./build/nginx-agent
@GOWORK=off CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags=${LDFLAGS} -o ./build/nginx-agent
docker run -v ${PWD}:/nginx-agent/ build-signed-packager:1.0.0
echo "DEB packages:"; \
find $(PACKAGES_DIR)/deb ;\
echo "RPM packages:"; \
find $(PACKAGES_DIR)/rpm ;\
echo "APK packages:"; \
find $(PACKAGES_DIR)/apk ;\
echo "TXZ packages:"; \
find $(PACKAGES_DIR)/txz ;\
echo "Github packages:"; \
find $(GITHUB_PACKAGES_DIR) ;\
cd $(PACKAGES_DIR) && tar -czvf "./${PACKAGE_PREFIX}.tar.gz" * && cd ../..;
gpg-key: ## Generate GPG public key
$$(gpg --import $(NFPM_SIGNING_KEY_FILE)); \
keyid=$$(gpg --list-keys NGINX | egrep -A1 "^pub" | egrep -v "^pub" | tr -d '[:space:]'); \
expiry=1y; \
$$(gpg --quick-set-expire $$keyid $$expiry '*'); \
# we need to convert the private gpg key to rsa pem format for pkg signing \
$$(gpg --export-secret-key $$keyid | openpgp2ssh $$keyid > .key.rsa); \
$$(gpg --output $(GPG_PUBLIC_KEY) --armor --export)
release: ## Publish tarball to the UPLOAD_URL
echo "Publishing nginx-agent packages to ${UPLOAD_URL}"; \
curl -XPOST -F "file=@$(PACKAGES_DIR)/${PACKAGE_PREFIX}.tar.gz" -H "Token: ${TOKEN}" ${UPLOAD_URL}; \
curl -XPOST -F "file=@$(GPG_PUBLIC_KEY)" -H "Token: ${TOKEN}" ${UPLOAD_URL}; \