diff --git a/.github/workflows/promote-snap.yaml b/.github/workflows/promote-snap.yaml new file mode 100644 index 0000000..e47d12a --- /dev/null +++ b/.github/workflows/promote-snap.yaml @@ -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 }} diff --git a/.github/workflows/release-snap.yaml b/.github/workflows/release-snap.yaml new file mode 100644 index 0000000..bc3477e --- /dev/null +++ b/.github/workflows/release-snap.yaml @@ -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 + diff --git a/.gitignore b/.gitignore index 7ab736a..b6308c9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ cos-alerter.yaml dist venv *.egg-info +*.snap **/__pycache__ diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b9d16..b332c10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 49cde02..e85702a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..17a3fcc --- /dev/null +++ b/setup.py @@ -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() diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..065954b --- /dev/null +++ b/snap/snapcraft.yaml @@ -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