Skip to content

Commit

Permalink
add script and config for packaging deb
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Sep 12, 2020
1 parent 59954f9 commit 03cc768
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 2.1

jobs:
build:
docker:
- image: circleci/ruby:2.7
working_directory: ~/deb
steps:
- checkout
- aws-cli/install
- run:
name: Download and import signing key
command: |
aws s3 cp s3://offen-secrets/signing-key.asc /tmp
gpg --import /tmp/signing-key.asc
- run:
name: Install fpm and dpkg-sig
command: |
gem install --no-document fpm
sudo apt-get install dpkg-sig
- run:
name: Package deb
command: ./package
- run:
name: Upload to S3
command: |
aws s3 cp *.deb s3://offen/deb/
workflows:
version: 2
build:
jobs:
- build:
context: AWS
filters:
branches:
only:
- master
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
*.deb
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# deb

Packaging Offen as a Debian package

This repo holds a script and some configuration files to package Offen as a Debian package. It can be run as:

```
./package
```

where the version to package is defined as `OFFEN_VERSION` in the `version` file.

---

The packaging script is licensed under the Mozilla Public License 2.0. Offen itself and the scripts and files included in the package are licensed under the Apache 2.0 License.
43 changes: 43 additions & 0 deletions offen.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2020 - Offen Authors <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# This file holds system-wide configuration values for Offen
# Refer to https://docs.offen.dev/running-offen/configuring-the-application/
# for further instructions.

# You likely want to populate the following values or set them as
# environment variables.

# Use `offen secret -quiet` to generate a secret
#
# OFFEN_SECRET="<RANDOM_BASE64_ENCODED_SECRET>"

# If you expose Offen directly to the internet without running behind a
# reverse proxy, define a comma separated list of domains to acquire a
# SSL certificate for using Let's Encrypt
#
# OFFEN_SERVER_AUTOTLS="offen.example.com,other.example.com"

# If you run Offen behind a reverse proxy, you can set a port
# here (default is 3000):
#
# OFFEN_SERVER_PORT="9876"

# This is the SMTP configuration used for sending transactional email. If
# not configured, Offen tries to use local sendmail.
#
# OFFEN_SMTP_HOST="exampleserver.com"
# OFFEN_SMTP_PASSWORD="password"
# OFFEN_SMTP_USER="[email protected]"
# OFFEN_SMTP_SENDER="[email protected]"

# If you want use a database other than the default SQLite file, configure the
# following for MySQL:
#
# OFFEN_DATABASE_DIALECT="mysql"
# OFFEN_DATABASE_CONNECTIONSTRING="user:pass@tcp(localhost:3306)/offen?parseTime=true"
#
# or use Postgres like this:
#
# OFFEN_DATABASE_DIALECT="postgres"
# OFFEN_DATABASE_CONNECTIONSTRING="postgres://user:pass@localhost:5432/offen"
12 changes: 12 additions & 0 deletions offen.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2020 - Offen Authors <[email protected]>
# SPDX-License-Identifier: Apache-2.0

[Unit]
Description=Offen Web Analytics

[Service]
ExecStart=/usr/local/bin/offen
Restart=always

[Install]
WantedBy=multi-user.target
58 changes: 58 additions & 0 deletions package
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Copyright 2020 - Offen Authors <[email protected]>
# SPDX-License-Identifier: MPL-2.0

set -eo pipefail

check_deps () {
deps=("curl" "fpm" "gpg" "dpkg" "dpkg-sig")
for dep in $deps; do
if [ -z $(which $dep) ]; then
echo "This script requires $dep to be installed, cannot continue"
exit 1
fi
done
}

download () {
rm -rf bin && mkdir bin
curl -sSL https://get.offen.dev/$1 | tar -xvz -C bin
curl https://keybase.io/hioffen/pgp_keys.asc | gpg --import
gpg --verify bin/offen-linux-amd64.asc bin/offen-linux-amd64
}

package () {
stripped_version=$(echo $1 | cut -c 2-)
rm -f *.deb

artifact="offen_${stripped_version}_amd64.deb"

fpm \
--maintainer "Offen Authors <[email protected]>" \
--url "https://www.offen.dev" \
--license "Apache-2.0" \
--vendor "Offen" \
--description "Offen is an open alternative to common web analytics tools. Gain insights while your users have full access to their data." \
--post-install "post_install.sh" \
--deb-systemd "offen.service" \
-p "offen_${stripped_version}_amd64.deb" \
-s dir -t deb -n offen -v $stripped_version \
bin/offen-linux-amd64=/usr/local/bin/offen \
offen.env=/etc/offen/

dpkg-sig --sign builder $artifact
echo "Successfully packaged and signed $artifact"
}

check_deps

source ./version
if [ -z "$OFFEN_VERSION" ]; then
echo "Expected OFFEN_VERSION to be set, got none."
exit 1
fi

echo "Packaging Offen at version $OFFEN_VERSION ..."
download $OFFEN_VERSION
package $OFFEN_VERSION
7 changes: 7 additions & 0 deletions post_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Copyright 2020 - Offen Authors <[email protected]>
# SPDX-License-Identifier: Apache-2.0

mkdir -p /var/opt/offen
mkdir -p /var/www/.cache
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OFFEN_VERSION="v0.1.5"

0 comments on commit 03cc768

Please sign in to comment.