Skip to content

Commit

Permalink
Merge pull request #98 from 0xPolygon/djpolygon/deb_packages
Browse files Browse the repository at this point in the history
Adding initial for packages
  • Loading branch information
djpolygon authored Jul 12, 2024
2 parents 72ae676 + c2bbe1b commit 7833b6e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
126 changes: 126 additions & 0 deletions .github/workflows/deb_packager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: deb_packager

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: make clean
run: make clean

- name: build for amd64/x86
run: make build

- name: Making directory structure
run: mkdir -p packaging/deb/cdk-data-availability/usr/bin/
- name: Copying necessary binary file
run: cp -rp dist/cdk-data-availability packaging/deb/cdk-data-availability/usr/bin/
- name: create directory structure for systemd
run: mkdir -p packaging/deb/cdk-data-availability/lib/systemd/system
- name: copy the service file
run: cp -rp packaging/package_scripts/systemd/cdk-data-availability.service packaging/deb/cdk-data-availability/lib/systemd/system/


# Control file creation
- name: create control file
run: |
echo "Package: cdk-data-availability" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Version: ${{ env.VERSION }}" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Section: base" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Priority: optional" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Architecture: amd64" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Maintainer: [email protected]" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Description: cdk-data-availability binary package" >> packaging/deb/cdk-data-availability/DEBIAN/control
- name: Creating package for binary for cdk-data-availability ${{ env.ARCH }}
run: cp -rp packaging/deb/cdk-data-availability packaging/deb/cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}
env:
ARCH: amd64

- name: Running package build
run: dpkg-deb --build --root-owner-group packaging/deb/cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}
env:
ARCH: amd64

### Arm64 setup
- name: prepping environment for arm64 build
run: make clean

- name: removing amd64 control file
run: rm -rf packaging/deb/cdk-data-availability/DEBIAN/control

- name: Adding requirements for cross compile
run: sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu

- name: build for arm64
run: GOARCH=arm64 GOOS=linux CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ CGO_ENABLED=1 go build -o dist/cdk-data-availability ./cmd/main.go

- name: copying necessary files
run: cp -rp dist/cdk-data-availability packaging/deb/cdk-data-availability/usr/bin/

- name: create control file
run: |
echo "Package: cdk-data-availability" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Version: ${{ env.VERSION }}" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Section: base" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Priority: optional" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Architecture: arm64" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Maintainer: [email protected]" >> packaging/deb/cdk-data-availability/DEBIAN/control
echo "Description: cdk-data-availability binary package" >> packaging/deb/cdk-data-availability/DEBIAN/control
- name: Creating package for binary for cdk-data-availability ${{ env.ARCH }}
run: cp -rp packaging/deb/cdk-data-availability packaging/deb/cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}
env:
ARCH: arm64

- name: Running package build
run: dpkg-deb --build --root-owner-group packaging/deb/cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}
env:
ARCH: arm64

- name: create checksum for the amd64 package for cdk-data-availability
run: cd packaging/deb/ && sha256sum cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}.deb > cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}.deb.checksum
env:
ARCH: amd64

- name: create checksum for the arm64 package for cdk-data-availability
run: cd packaging/deb/ && sha256sum cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}.deb > cdk-data-availability-${{ env.GIT_TAG }}-${{ env.ARCH }}.deb.checksum
env:
ARCH: arm64

- name: Release cdk-data-availability Packages
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.GIT_TAG }}
prerelease: true
files: |
packaging/deb/cdk-data-availability**.deb
packaging/deb/cdk-data-availability**.deb.checksum
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ ifndef CHECK_DOCKER
$(error "Docker is not installed. Please install Docker and retry.")
endif

clean:
env GO111MODULE=on go clean -cache
rm -fr build/_workspace/pkg/ $(GOBIN)/*


# Targets that require the checks
generate: check-go
build: check-go
Expand Down
12 changes: 12 additions & 0 deletions packaging/deb/cdk-data-availability/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -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 cdk-data-availability
if [ -d "/opt/cdk-data-availability" ]
then
echo "Directory /opt/cdk-data-availability exists."
else
sudo mkdir -p /opt/cdk-data-availability
sudo chown -R cdk-data-availability /opt/cdk-data-availability
fi
sudo systemctl daemon-reload
8 changes: 8 additions & 0 deletions packaging/deb/cdk-data-availability/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
###############
# Remove cdk-data-availability installs
##############
sudo rm -rf /lib/systemd/system/cdk-data-availability.service
sudo deluser cdk-data-availability
sudo systemctl daemon-reload
16 changes: 16 additions & 0 deletions packaging/package_scripts/systemd/cdk-data-availability.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=cdk-data-availability-service
StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/cdk-data-availability
Type=simple
KillSignal=SIGINT
User=cdk-data-availability
TimeoutStopSec=120

[Install]
WantedBy=multi-user.target

0 comments on commit 7833b6e

Please sign in to comment.