From 945e2a6dd75ffc0ae71a8480cf192283f3dbeb16 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Tue, 25 Jun 2024 16:50:10 -0500 Subject: [PATCH] Adding initial for deb packages --- .github/workflows/deb_packager.yml | 84 ++++++++++++++++++++++ packaging/deb/zkevm-bridge/DEBIAN/postinst | 12 ++++ packaging/deb/zkevm-bridge/DEBIAN/postrm | 8 +++ packaging/systemd/zkevm-bridge.service | 16 +++++ 4 files changed, 120 insertions(+) create mode 100644 .github/workflows/deb_packager.yml create mode 100755 packaging/deb/zkevm-bridge/DEBIAN/postinst create mode 100755 packaging/deb/zkevm-bridge/DEBIAN/postrm create mode 100644 packaging/systemd/zkevm-bridge.service diff --git a/.github/workflows/deb_packager.yml b/.github/workflows/deb_packager.yml new file mode 100644 index 00000000..5897ee6f --- /dev/null +++ b/.github/workflows/deb_packager.yml @@ -0,0 +1,84 @@ +name: deb_packager +# test + +on: + push: + branches: + - 'main' + paths: + - '**' + tags: + - 'v*.*.*' + - 'v*.*.*-*' + +jobs: + build: + permissions: + id-token: write + contents: write + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: 1.22.x + # Variables + - name: Adding TAG to ENV + run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV + - name: adding version + run: | + NUMERIC_VERSION=$( echo ${{ env.GIT_TAG }} | sed 's/[^0-9.]//g' ) + echo "VERSION=$NUMERIC_VERSION" >> $GITHUB_ENV + + - name: build the binary + run: make build + + - name: making directory structure + run: mkdir -p packaging/deb/zkevm-bridge/usr/bin/ + - name: copying necessary binary for amd64 + run: cp -rp dist/zkevm-bridge packaging/deb/zkevm-bridge/usr/bin/zkevm-bridge + - name: create directory for service file + run: mkdir -p packaging/deb/zkevm-bridge/lib/systemd/system + - name: copy the service file + run: cp -rp packaging/systemd/zkevm-bridge.service packaging/deb/zkevm-bridge/lib/systemd/system/ + + + # Control file creation + - name: create control file + run: | + echo "Package: zkevm-bridge" >> packaging/deb/zkevm-bridge/DEBIAN/control + echo "Version: ${{ env.VERSION }}" >> packaging/deb/zkevm-bridge/DEBIAN/control + echo "Section: base" >> packaging/deb/zkevm-bridge/DEBIAN/control + echo "Priority: optional" >> packaging/deb/zkevm-bridge/DEBIAN/control + echo "Architecture: amd64" >> packaging/deb/zkevm-bridge/DEBIAN/control + echo "Maintainer: devops@polygon.technology" >> packaging/deb/zkevm-bridge/DEBIAN/control + echo "Description: zkevm-bridge binary package" >> packaging/deb/zkevm-bridge/DEBIAN/control + + - name: Creating package for binary for zkevm-bridge ${{ env.ARCH }} + run: cp -rp packaging/deb/zkevm-bridge packaging/deb/zkevm-bridge-${{ env.GIT_TAG }}-${{ env.ARCH }} + env: + ARCH: amd64 + + - name: Running package build + run: dpkg-deb --build --root-owner-group packaging/deb/zkevm-bridge-${{ env.GIT_TAG }}-${{ env.ARCH }} + env: + ARCH: amd64 + + - name: create checksum for the amd64 package + run: cd packaging/deb/ && sha256sum zkevm-bridge-${{ env.GIT_TAG }}-${{ env.ARCH }}.deb > zkevm-bridge-${{ env.GIT_TAG }}-${{ env.ARCH }}.deb.checksum + env: + ARCH: amd64 + + + - name: Release zkevm-bridge Packages + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.GIT_TAG }} + prerelease: true + files: | + packaging/deb/zkevm-bridge**.deb + packaging/deb/zkevm-bridge**.deb.checksum \ No newline at end of file diff --git a/packaging/deb/zkevm-bridge/DEBIAN/postinst b/packaging/deb/zkevm-bridge/DEBIAN/postinst new file mode 100755 index 00000000..5bc5bafe --- /dev/null +++ b/packaging/deb/zkevm-bridge/DEBIAN/postinst @@ -0,0 +1,12 @@ +#!/bin/bash +# This is a postinstallation script so the service can be configured and started when requested +# +sudo adduser --disabled-password --disabled-login --shell /usr/sbin/nologin --quiet --system --no-create-home --home /nonexistent zkevm-bridge +if [ -d "/opt/zkevm-bridge" ] +then + echo "Directory /opt/zkevm-bridge exists." +else + sudo mkdir -p /opt/zkevm-bridge + sudo chown -R zkevm-bridge /opt/zkevm-bridge +fi +sudo systemctl daemon-reload \ No newline at end of file diff --git a/packaging/deb/zkevm-bridge/DEBIAN/postrm b/packaging/deb/zkevm-bridge/DEBIAN/postrm new file mode 100755 index 00000000..054e4bd2 --- /dev/null +++ b/packaging/deb/zkevm-bridge/DEBIAN/postrm @@ -0,0 +1,8 @@ +#!/bin/bash +# +############### +# Remove zkevm-bridge installs +############## +sudo rm -rf /lib/systemd/system/zkevm-bridge.service +sudo deluser zkevm-bridge +sudo systemctl daemon-reload \ No newline at end of file diff --git a/packaging/systemd/zkevm-bridge.service b/packaging/systemd/zkevm-bridge.service new file mode 100644 index 00000000..6585b744 --- /dev/null +++ b/packaging/systemd/zkevm-bridge.service @@ -0,0 +1,16 @@ +[Unit] + Description=zkevm-bridge + StartLimitIntervalSec=500 + StartLimitBurst=5 + +[Service] + Restart=on-failure + RestartSec=5s + ExecStart=/usr/bin/zkevm-bridge + Type=simple + KillSignal=SIGINT + User=zkevm-bridge + TimeoutStopSec=120 + +[Install] + WantedBy=multi-user.target \ No newline at end of file