-
Notifications
You must be signed in to change notification settings - Fork 74
/
Makefile.packaging
201 lines (175 loc) · 10.7 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/make -f
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Variable Definitions #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
PACKAGES_DIR := ./build/packages
GITHUB_PACKAGES_DIR := ./build/github/packages
AZURE_PACKAGES_DIR := ./build/azure/packages
GPG_PUBLIC_KEY := .key
DEB_DISTROS?=ubuntu-noble-24.04 ubuntu-jammy-22.04 ubuntu-focal-20.04 debian-bookworm-12 debian-bullseye-11
DEB_ARCHS?=arm64 amd64
RPM_DISTROS?=oraclelinux-8-x86_64 oraclelinux-9-x86_64 suse-12-x86_64 suse-15-x86_64
RPM_ARCH=x86_64
REDHAT_VERSIONS?=redhatenterprise-8 redhatenterprise-9
REDHAT_ARCHS?=aarch64 x86_64
ROCKY_VERSIONS?=rocky-8 rocky-9
ROCKY_ARCHS?=aarch64 x86_64
FREEBSD_DISTROS?="FreeBSD:13:amd64" "FreeBSD:14:amd64"
APK_VERSIONS?=3.17 3.18 3.19 3.20
APK_ARCHS?=aarch64 x86_64
ALMA_VERSIONS?=almalinux-8 almalinux-9
ALMA_ARCHS?=aarch64 x86_64
AMAZON_VERSIONS?=amazon-2 amazon-2023
AMAZON_ARCHS?=aarch64 x86_64
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Release Packaging #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
clean-packages:
rm -rf $(PACKAGES_DIR)
rm -rf $(GITHUB_PACKAGES_DIR)
rm -rf $(AZURE_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)
$(AZURE_PACKAGES_DIR):
@mkdir -p $(AZURE_PACKAGES_DIR)
package: gpg-key $(PACKAGES_DIR) $(GITHUB_PACKAGES_DIR) $(AZURE_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 -pgo=auto -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for distro in $(DEB_DISTROS); do \
deb_codename=`echo $$distro | cut -d- -f 2`; \
VERSION=${VERSION}~$${deb_codename} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager deb --target ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_${VERSION}~$${deb_codename}_$${arch}.deb; \
cp ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_${VERSION}~$${deb_codename}_$${arch}.deb ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}~$${deb_codename}_$${arch}.deb; \
cp ${PACKAGES_DIR}/deb/${PACKAGE_PREFIX}_${VERSION}~$${deb_codename}_$${arch}.deb ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}~$${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 -pgo=auto -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" = "suse" ]; then rpm_codename="sles$$rpm_major"; \
fi; \
if [ "$$rpm_codename" != "na" ]; then \
VERSION=${VERSION} ARCH=amd64 nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.${RPM_ARCH}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$(RPM_ARCH).rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.${RPM_ARCH}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$(RPM_ARCH).rpm ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${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 -pgo=auto -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=${VERSION} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${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 -pgo=auto -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=${VERSION} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${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 -pgo=auto -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=${VERSION} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${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 -pgo=auto -ldflags=${LDFLAGS} -o ./build/nginx-agent; \
for version in $(AMAZON_VERSIONS); do \
rpm_major=`echo $$version | cut -d- -f 2`; \
rpm_codename="amzn$$rpm_major";\
VERSION=${VERSION} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager rpm --target $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm; \
cp $(PACKAGES_DIR)/rpm/${PACKAGE_PREFIX}-${VERSION}.$${rpm_codename}.ngx.$${arch}.rpm ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}.$${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 -pgo=auto -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=${VERSION} ARCH=$${arch} nfpm pkg --config .nfpm.yaml --packager apk --target $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-${VERSION}.apk; \
cp $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-${VERSION}.apk ${GITHUB_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}-v$${version}-$${arch}.apk; \
cp $(PACKAGES_DIR)/apk/v$${version}/$${arch}/${PACKAGE_PREFIX}-${VERSION}.apk ${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}-${VERSION}-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 -pgo=auto -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 ../.. && cp "${PACKAGES_DIR}/${PACKAGE_PREFIX}.tar.gz" "${AZURE_PACKAGES_DIR}/${PACKAGE_PREFIX}.tar.gz"; \
echo "Azure packages:"; \
find $(AZURE_PACKAGES_DIR) ;
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:]'); \
if [ -z "$$keyid" ]; then echo "Error: GPG key not found."; exit 1; fi; \
# Check if the key is expired \
# Look for the 'e' (expired) flag in the 'pub' or 'uid' lines \
if gpg --list-keys --with-colons "$$keyid" | grep -E '^pub:e:|^uid:e:'; then \
echo "Error: GPG key has expired."; \
exit 1; \
fi; \
expiry=1y; \
$$(gpg --quick-set-expire $$keyid $$expiry '*'); \
# 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 $$keyid)
release: ## Publish tarball to the UPLOAD_URL
echo "Publishing nginx-agent packages to ${UPLOAD_URL}"; \
curl -XPOST --fail -F "file=@$(PACKAGES_DIR)/${PACKAGE_PREFIX}.tar.gz" -H "Token: ${TOKEN}" ${UPLOAD_URL}; \
curl -XPOST --fail -F "file=@$(GPG_PUBLIC_KEY)" -H "Token: ${TOKEN}" ${UPLOAD_URL}; \