Skip to content

Commit

Permalink
add snapcraft recipe (#52)
Browse files Browse the repository at this point in the history
* add snapcraft recipe

* add snap ci workflows

* Update CHANGELOG.md

* Update snapcraft.yaml

* remove setup.py

* should stay as unreleased until the actual package is bumped

* no need to bump as cos-alerter did not change

* put back setup.py

* use packages instead of package-dir

* ignore snaps

* comment explaining setup.py

---------

Co-authored-by: Dylan Stephano-Shachter <dylan.stephano-shachter@canonical.com>
  • Loading branch information
simskij and dstathis authored Aug 28, 2023
1 parent a3c5efb commit a26342b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/promote-snap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Promote Snap

on:
workflow_dispatch:
inputs:
promotion:
type: choice
description: Channel to promote from
options:
- edge -> beta
- beta -> candidate
- candidate -> stable

env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}

jobs:
promote:
name: Promote Snap
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo snap install --classic --channel edge snapcraft
- name: Set target channel
env:
PROMOTE_FROM: ${{ github.event.inputs.promotion }}
run: |
if [ "${PROMOTE_FROM}" == "edge -> beta" ]; then
echo "promote-from=edge" >> ${GITHUB_ENV}
echo "promote-to=beta" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "beta -> candidate" ]; then
echo "promote-from=beta" >> ${GITHUB_ENV}
echo "promote-to=candidate" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "candidate -> stable" ]; then
echo "promote-from=candidate" >> ${GITHUB_ENV}
echo "promote-to=stable" >> ${GITHUB_ENV}
fi
- name: Fetch Revision
run: |
SNAP_RELEASES=$(curl -s -H "Snap-Device-Series: 16" "http://api.snapcraft.io/v2/snaps/info/cos-alerter?fields=revision")
REVISION=$(echo $SNAP_RELEASES | jq '."channel-map"[] | select(.channel.risk=="${{ env.promote-from }}").revision')
echo "revision=$REVISION" >> ${GITHUB_ENV}
- name: Promote Snap
run: |
snapcraft release cos-alerter ${{ env.revision }} ${{ env.promote-to }}
35 changes: 35 additions & 0 deletions .github/workflows/release-snap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release Snap

on:
push:
branches:
- main
paths:
- snap/**


env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup LXD
uses: canonical/setup-lxd@v0.1.1
with:
channel: latest/stable

- name: Install dependencies
run: |
sudo snap install --classic --channel edge snapcraft
- name: Build Snap
run: snapcraft pack --output cos-alerter.snap

- name: Upload and Publish Snap
run: snapcraft upload --release edge cos-alerter.snap

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ cos-alerter.yaml
dist
venv
*.egg-info
*.snap
**/__pycache__
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Added usage instructions to the readme (#51).
- Added snapcraft build recipes and automation. (#52)

## [0.4.0] - 2023-05-31

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Homepage = "https://github.com/canonical/cos-alerter"
[project.scripts]
cos-alerter = "cos_alerter.daemon:main"

[tool.setuptools]
packages = ["cos_alerter"]

[tool.black]
line-length = 99

Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is needed for some reason to make snapcraft work.
# https://github.com/snapcore/snapcraft/issues/4300

from setuptools import setup

setup()
39 changes: 39 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: cos-alerter
version: '0.4.0'
summary: A watchdog alerting on alertmanager notification failures.
license: Apache-2.0
contact: simon.aronsson@canonical.com
issues: https://github.com/canonical/cos-alerter/issues
source-code: https://github.com/canonical/cos-alerter/
website: https://charmhub.io/topics/canonical-observability-stack/
description: |
COS Alerter is a watchdog used to alert on alertmanager notification failures.
By leveraging an always-firing alert rule routed specifically to cos-alerter, you'll
be alerted if the pings stop happening - meaning your alertmanager is likely malfunctioning.
base: core22
grade: stable
confinement: strict
compression: lzo

plugs:
etc-cos-alerter:
interface: system-files
read:
- /etc/cos-alerter.yaml

parts:
cos-alerter:
plugin: python
source: .

apps:
daemon:
command: bin/cos-alerter --config /etc/cos-alerter.yaml
install-mode: disable
restart-condition: on-failure
daemon: simple
plugs:
- network
- network-bind
- etc-cos-alerter

0 comments on commit a26342b

Please sign in to comment.