Debian Codegraph @

dist/rpm/caddy.spec

raw
1 %global debug_package %{nil}
2
3 Name: caddy
4 Version: 2.11.3
5 Release: 1%{?dist}
6 Summary: Web server with automatic HTTPS
7 License: Apache-2.0
8 URL: https://caddyserver.com
9
10 # In order to build Caddy with version information, we need to import it as a
11 # go module. To do that, we are going to forgo the traditional source tarball
12 # and instead use just this file from upstream. This method requires that we
13 # allow networking in the build environment.
14 Source0: https://raw.githubusercontent.com/caddyserver/caddy/v%{version}/cmd/caddy/main.go
15 # Use official resources for config, unit file, and welcome page.
16 # https://github.com/caddyserver/dist
17 Source10: https://raw.githubusercontent.com/caddyserver/dist/master/config/Caddyfile
18 Source20: https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service
19 Source21: https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy-api.service
20 Source22: https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.sysusers
21 Source30: https://raw.githubusercontent.com/caddyserver/dist/master/welcome/index.html
22 # Since we are not using a traditional source tarball, we need to explicitly
23 # pull in the license file.
24 Source90: https://raw.githubusercontent.com/caddyserver/caddy/v%{version}/LICENSE
25
26 BuildRequires: git-core
27 BuildRequires: systemd-rpm-macros
28 %{?systemd_requires}
29
30 # https://github.com/caddyserver/caddy/commit/05acc5131ed5c80acbd28ed8d907b166cd15b72c
31 BuildRequires: golang >= 1.25
32
33 Provides: webserver
34
35
36 %description
37 Caddy is an extensible server platform that uses TLS by default.
38
39
40 %prep
41 %setup -q -c -T
42 # Copy main.go and LICENSE into the build directory.
43 cp %{S:0} %{S:90} .
44
45
46 %build
47 # https://pagure.io/go-rpm-macros/c/1cc7f5d9026175bb6cb1b8c889355d0c4fc0e40a
48 %undefine _auto_set_build_flags
49
50 # Fedora diverges from upstream Go by disabling the proxy server. Some of
51 # Caddy's dependencies reference commits that are no longer upstream, but are
52 # cached in the proxy. As long as we are downloading dependencies during the
53 # build, reset the behavior to prefer the proxy. This also avoid having a
54 # build requirement on bzr.
55 # https://fedoraproject.org/wiki/Changes/golang1.13#Detailed_Description
56 export GOPROXY='https://proxy.golang.org,direct'
57
58 # As of 2023-08-03, golang 1.21 in Fedora Rawhide requires this environment
59 # variable to be set for the build to work correctly.
60 # https://github.com/golang/go/issues/60145#issuecomment-1547921152
61 export GOSUMDB='sum.golang.org'
62 export BUILDTAGS='%{!?suse_version:rpm_crashtraceback }nobadger'
63
64 go mod init caddy
65 echo "require github.com/caddyserver/caddy/v2 v%{version}" >> go.mod
66 go mod tidy
67 go build \
68 -buildmode pie \
69 -compiler gc \
70 -tags="${BUILDTAGS}" \
71 -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n')%{?__global_ldflags: -extldflags '%__global_ldflags'}" \
72 -a -v -x
73
74
75 %install
76 # command
77 install -D -p -m 0755 caddy %{buildroot}%{_bindir}/caddy
78
79 # man pages
80 ./caddy manpage --directory %{buildroot}%{_mandir}/man8
81
82 # config
83 install -D -p -m 0644 %{S:10} %{buildroot}%{_sysconfdir}/caddy/Caddyfile
84
85 # systemd units
86 install -D -p -m 0644 %{S:20} %{buildroot}%{_unitdir}/caddy.service
87 install -D -p -m 0644 %{S:21} %{buildroot}%{_unitdir}/caddy-api.service
88
89 # sysusers
90 install -D -p -m 0644 %{S:22} %{buildroot}%{_sysusersdir}/caddy.conf
91
92 # data directory
93 install -d -m 0750 %{buildroot}%{_sharedstatedir}/caddy
94
95 # welcome page
96 install -D -p -m 0644 %{S:30} %{buildroot}%{_datadir}/caddy/index.html
97
98 # shell completions
99 install -d -m 0755 %{buildroot}%{_datadir}/bash-completion/completions
100 ./caddy completion bash > %{buildroot}%{_datadir}/bash-completion/completions/caddy
101 install -d -m 0755 %{buildroot}%{_datadir}/zsh/site-functions
102 ./caddy completion zsh > %{buildroot}%{_datadir}/zsh/site-functions/_caddy
103 install -d -m 0755 %{buildroot}%{_datadir}/fish/vendor_completions.d
104 ./caddy completion fish > %{buildroot}%{_datadir}/fish/vendor_completions.d/caddy.fish
105
106
107 %pre
108 %sysusers_create_compat %{S:22}
109
110
111 %post
112 %systemd_post caddy.service
113
114 if [ -x /usr/sbin/getsebool ]; then
115 # connect to ACME endpoint to request certificates
116 setsebool -P httpd_can_network_connect on
117 fi
118 if [ -x /usr/sbin/semanage -a -x /usr/sbin/restorecon ]; then
119 # file contexts
120 semanage fcontext --add --type httpd_exec_t '%{_bindir}/caddy' 2> /dev/null || :
121 semanage fcontext --add --type httpd_sys_content_t '%{_datadir}/caddy(/.*)?' 2> /dev/null || :
122 semanage fcontext --add --type httpd_config_t '%{_sysconfdir}/caddy(/.*)?' 2> /dev/null || :
123 semanage fcontext --add --type httpd_var_lib_t '%{_sharedstatedir}/caddy(/.*)?' 2> /dev/null || :
124 restorecon -r %{_bindir}/caddy %{_datadir}/caddy %{_sysconfdir}/caddy %{_sharedstatedir}/caddy || :
125 fi
126 if [ -x /usr/sbin/semanage ]; then
127 # QUIC
128 semanage port --add --type http_port_t --proto udp 80 2> /dev/null || :
129 semanage port --add --type http_port_t --proto udp 443 2> /dev/null || :
130 # admin endpoint
131 semanage port --add --type http_port_t --proto tcp 2019 2> /dev/null || :
132 fi
133
134
135 %preun
136 %systemd_preun caddy.service
137
138
139 %postun
140 %systemd_postun_with_restart caddy.service
141
142 if [ $1 -eq 0 ]; then
143 if [ -x /usr/sbin/getsebool ]; then
144 # connect to ACME endpoint to request certificates
145 setsebool -P httpd_can_network_connect off
146 fi
147 if [ -x /usr/sbin/semanage ]; then
148 # file contexts
149 semanage fcontext --delete --type httpd_exec_t '%{_bindir}/caddy' 2> /dev/null || :
150 semanage fcontext --delete --type httpd_sys_content_t '%{_datadir}/caddy(/.*)?' 2> /dev/null || :
151 semanage fcontext --delete --type httpd_config_t '%{_sysconfdir}/caddy(/.*)?' 2> /dev/null || :
152 semanage fcontext --delete --type httpd_var_lib_t '%{_sharedstatedir}/caddy(/.*)?' 2> /dev/null || :
153 # QUIC
154 semanage port --delete --type http_port_t --proto udp 80 2> /dev/null || :
155 semanage port --delete --type http_port_t --proto udp 443 2> /dev/null || :
156 # admin endpoint
157 semanage port --delete --type http_port_t --proto tcp 2019 2> /dev/null || :
158 fi
159 fi
160
161
162 %files
163 %license LICENSE
164 %{_bindir}/caddy
165 %{_mandir}/man8/caddy*.8*
166 %{_datadir}/caddy
167 %{_unitdir}/caddy.service
168 %{_unitdir}/caddy-api.service
169 %{_sysusersdir}/caddy.conf
170 %dir %{_sysconfdir}/caddy
171 %config(noreplace) %{_sysconfdir}/caddy/Caddyfile
172 %attr(0750,caddy,caddy) %dir %{_sharedstatedir}/caddy
173 %{_datadir}/bash-completion/completions/caddy
174 %{_datadir}/zsh/site-functions/_caddy
175 %{_datadir}/fish/vendor_completions.d/caddy.fish