From dcf80c2558289d85034076320100a902b7f71c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 20 Oct 2018 21:57:18 +0200 Subject: [PATCH 1/2] snap: add snap packaging support via snapcraft Hooks needs to be installed in $SNAP_USER_DATA/hooks --- .gitignore | 4 ++++ snap/scripts/run.sh | 27 +++++++++++++++++++++++++++ snap/snapcraft.yaml | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100755 snap/scripts/run.sh create mode 100644 snap/snapcraft.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f24811 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +parts +prime +stage +snap/.snapcraft diff --git a/snap/scripts/run.sh b/snap/scripts/run.sh new file mode 100755 index 0000000..4f6ee35 --- /dev/null +++ b/snap/scripts/run.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +if [ ! -f "$SNAP_USER_COMMON/config.json" ]; then + cp "$SNAP/config.json.sample" "$SNAP_USER_COMMON/config.json" +fi + +if [ ! -L "$SNAP_USER_COMMON/webhooks.py" ]; then + ln -sf "$SNAP/webhooks.py" "$SNAP_USER_COMMON" +fi + +if [ "X$SNAP_ARCH" = "Xamd64" ]; then + ARCH="x86_64-linux-gnu" +elif [ "X$SNAP_ARCH" = "Xarmhf" ]; then + ARCH="arm-linux-gnueabihf" +elif [ "X$SNAP_ARCH" = "Xarm64" ]; then + ARCH="aarch64-linux-gnu" +else + ARCH="$SNAP_ARCH-linux-gnu" +fi + +export PATH=$SNAP/usr/bin:$PATH +export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH:$SNAP/usr/lib:$LD_LIBRARY_PATH + +cd "$SNAP_USER_COMMON" +mkdir -p hooks + +exec env $SNAP/usr/bin/python3 ./webhooks.py $@ diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..8fcc7f7 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,34 @@ +name: python-github-webhooks +version: git +summary: Simple Python WSGI application to handle Github webhooks +description: | + Simple Python WSGI application to handle Github webhooks + +grade: stable +confinement: strict + +parts: + python-github-webhooks: + plugin: python + requirements: requirements.txt + source: . + override-build: | + snapcraftctl build + install -m 755 webhooks.py $SNAPCRAFT_PART_INSTALL + install -m 644 config.json.sample $SNAPCRAFT_PART_INSTALL + ln -s python3 $SNAPCRAFT_PART_INSTALL/usr/bin/python || true + stage-packages: + - git + + runner: + plugin: dump + source: snap/scripts + organize: + webhooks: bin/run.sh + +apps: + python-github-webhooks: + command: ./run.sh + plugs: + - network + - network-bind From 7c2a20016f36bddc743081d408c7c4128cf84dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 20 Oct 2018 21:58:03 +0200 Subject: [PATCH 2/2] snap: make it a daemon Hooks moved to $SNAP_COMMON/hooks --- snap/scripts/run.sh | 10 +++++----- snap/snapcraft.yaml | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/snap/scripts/run.sh b/snap/scripts/run.sh index 4f6ee35..91766e3 100755 --- a/snap/scripts/run.sh +++ b/snap/scripts/run.sh @@ -1,11 +1,11 @@ #!/bin/sh -if [ ! -f "$SNAP_USER_COMMON/config.json" ]; then - cp "$SNAP/config.json.sample" "$SNAP_USER_COMMON/config.json" +if [ ! -f "$SNAP_COMMON/config.json" ]; then + cp "$SNAP/config.json.sample" "$SNAP_COMMON/config.json" fi -if [ ! -L "$SNAP_USER_COMMON/webhooks.py" ]; then - ln -sf "$SNAP/webhooks.py" "$SNAP_USER_COMMON" +if [ ! -L "$SNAP_COMMON/webhooks.py" ]; then + ln -sf "$SNAP/webhooks.py" "$SNAP_COMMON" fi if [ "X$SNAP_ARCH" = "Xamd64" ]; then @@ -21,7 +21,7 @@ fi export PATH=$SNAP/usr/bin:$PATH export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH:$SNAP/usr/lib:$LD_LIBRARY_PATH -cd "$SNAP_USER_COMMON" +cd "$SNAP_COMMON" mkdir -p hooks exec env $SNAP/usr/bin/python3 ./webhooks.py $@ diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 8fcc7f7..e6f7b4b 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -29,6 +29,7 @@ parts: apps: python-github-webhooks: command: ./run.sh + daemon: simple plugs: - network - network-bind