Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[archlinux] adjust pkgbuild + add files #11

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions archlinux/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
:80

# Set this path to your site's directory.
root * /usr/share/caddy

# Enable the static file server.
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://github.com/caddyserver/caddy/wiki/v2:-Documentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# https://github.com/caddyserver/caddy/wiki/v2:-Documentation
# https://caddyserver.com/docs/caddyfile

PS. I forget if we talked about this already, but do we need a copy of the Caddyfile? I think this exact same Caddyfile is already in this repo. I'd like to avoid making copies of it, so we only have to update one file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I only fetch the caddy welcome page from this repository. This is why I ship a dedicated caddy file. I would actually prefer if we could use just one source in the PKGBUILD (we could achieve this via moving the welcome page and a default caddy file to the standard caddy repo under github.com/caddyserver/caddy )

Copy link
Member

@mholt mholt Feb 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't want to mix distribution resources with the actual code itself, though. Can you just fetch both the Caddyfile and the welcome page from this repo instead? (If you're already fetching one, why not another?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's tedious, if we get the hardening options in this repository as well, I will end up with four sources instead of one. It's considered bad practice to fetch from so many sources in Arch Linux. Not sure how other maintainers would react.

I don't think this files are 'distribution' specific. I would actually consider them es necessary to build caddy and run it from source. At least it's the first time that I see somebody having a separate distribution repository. I will think about it.

Copy link
Member

@mholt mholt Feb 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is each file considered a different source? Why is it bad practice? If the installation needs it, why not get it?

I don't think this files are 'distribution' specific. I would actually consider them es necessary to build caddy and run it from source.

They definitely are distribution-specific, i.e. not needed to compile or run. They're absolutely non-essential, and I'd rather people write their own configs, tbh. I really don't want extra resources cluttering up the main repository.

I learned from making Papa Parse that distribution can quickly double or triple the size of the actual repository. Distributing a program is a totally different (and way too difficult, IMO) task than just writing the program and compiling it, so it's in a different repo.

46 changes: 38 additions & 8 deletions archlinux/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
# Maintainer : Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=caddy
pkgver=2.0.0beta10
_pkgver=2.0.0-beta10
pkgver=2.0.0beta13
Copy link
Member

@mholt mholt Feb 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno if it matters, but we had to make the tag v2.0.0-beta.13 in order to make Go modules happy...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Then I can just use pkgver in the PKGBUILD and don't need to track this twice. Thanks a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sorry. Looks like I misunderstood you here :'D. It doesn't matter for us here, because I just pull your code by commit (for checking your signature on this commit). I am not sure if pacman (the Arch Linux package manager can handle versions like v2.0.0-beta.13... we can try, but I can't promise. Or is it okay to leave it as v2.0.0-beta13?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's okay. I wasn't sure if the version had to be the same as in the Caddy repo.

_gitcommit='6614d1c495f3266037d36b4c2f4f70fcc73acad1'
_distcommit='9e93bfd85c97d71ab842a4a4b555d358295c914e'
pkgrel=1
pkgdesc="Powerful, enterprise-ready, open source web server with automatic HTTPS written in Go"
arch=('x86_64')
url="https://github.com/caddyserver/caddy"
license=('Apache')
makedepends=('go-pie' 'git')
depends=('glibc')
source=("${pkgname}-${pkgver}::git+https://github.com/caddyserver/caddy#tag=v${_pkgver}?signed")
sha512sums=('SKIP')
validpgpkeys=('29D0817A67156E4F25DC24782A349DD577D586A5')
makedepends=('go-pie' 'git')
backup=('etc/caddy/Caddyfile')
source=("git+https://github.com/caddyserver/caddy#commit=${_gitcommit}?signed"
"caddy-${_distcommit}-index.html::https://raw.githubusercontent.com/caddyserver/dist/${_distcommit}/welcome/index.html"
'caddy.service'
'caddy.tmpfiles'
'Caddyfile')
sha512sums=('SKIP'
'7836722155509009cbd8eaf605e2d09a2aefd58a90e5973156ec6363aa5ba2ed6ec30a57d2ee9b4e6e4910d02243ffbed92c366b1eb2076d0da71c2d4f930175'
'b1ff442e9972af44ea0560e3a5b8359ec94ce2f692e85c5413ba1b0963cb53159338b578f4cac4f8c445c818de5ef8f5b8a67af2ec6cb7303c475b81028c2e24'
'd4a2a415a0fa75fae7aa932030d1dc33f30e964fc425aefbb4c695239ea9de9e025fe2097a6c4af35f95cf908e72db6a60615e24f1e4ad1c7d93a04793bfefb0'
'245b7de1e6e66642bd35e3e09b04c64323892676f671cdede6e31fabfe1b4c50692686ae14327152c8dcc4306880413450e5ab69f920e20460e01b56a52daf7d')
validpgpkeys=(
'29D0817A67156E4F25DC24782A349DD577D586A5' # Matthew Holt <mholt@users.noreply.github.com>
)

pkgver() {
cd ${pkgname}
git describe --tags --match 'v*' | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
sed 's|/var/www/html|/srv/http|g' -i "${srcdir}/caddy-${_distcommit}-index.html"
}

build() {
cd "${pkgname}-${pkgver}/cmd/caddy/"
cd "${pkgname}/cmd/caddy/"
go build -trimpath -ldflags "-extldflags ${LDFLAGS}" -o caddy
}

check() {
cd "${pkgname}"
go test ./...
}

package() {
cd "${pkgname}-${pkgver}"
cd "${pkgname}"
install -Dm755 "cmd/caddy/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
install -Dm 644 "${srcdir}/caddy.service" -t "${pkgdir}/usr/lib/systemd/system"
install -Dm 644 "${srcdir}/caddy.tmpfiles" "${pkgdir}/usr/lib/tmpfiles.d/caddy.conf"
install -Dm 644 "${srcdir}/Caddyfile" "${pkgdir}/etc/caddy/Caddyfile"
install -Dm 644 "${srcdir}/caddy-${_distcommit}-index.html" "${pkgdir}/usr/share/caddy/index.html"
install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
31 changes: 31 additions & 0 deletions archlinux/caddy.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[Unit]
Description=Caddy Web Server
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=http
Group=http
ExecStart=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile --resume --environ
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512

# Hardening options
PrivateTmp=true
ProtectSystem=strict
PrivateDevices=true
ProtectHome=true
ReadWritePaths=/var/lib/caddy /var/log/caddy
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
LockPersonality=true


[Install]
WantedBy=multi-user.target
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this file is also already in our repo: https://github.com/caddyserver/dist/blob/4d5728e7a4452d31030336c8e3ad9a006e58af18/init/caddy.service -- but this one is quite different. Is this one that we should use universally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the hardened service file. It has more hardening options. I have no problems with it so far, but other distribution maintainers were afraid it could have bad side effects. We should maybe have a discussion around this in the dist slack channel before shipping it universally.

2 changes: 2 additions & 0 deletions archlinux/caddy.tmpfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d /var/lib/caddy 0750 http http
d /var/log/caddy 0750 http http