Skip to content

Commit

Permalink
Merge pull request #42 from sacherjj/debian_package
Browse files Browse the repository at this point in the history
Initial debian package
  • Loading branch information
sacherjj authored Jul 14, 2023
2 parents fe1240b + 1e37716 commit 534ee15
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/publish-casper-db-utils-deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: publish-casper-db-utils-deb

on:
push:
tags:
- "v*.*.*"

jobs:
publish-deb:
strategy:
matrix:
include:
- os: ubuntu-20.04
code_name: focal

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal

- name: Install deps
run: |
echo "deb http://repo.aptly.info/ squeeze main" | sudo tee -a /etc/apt/sources.list.d/aptly.list
wget -qO - https://www.aptly.info/pubkey.txt | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y awscli aptly=1.2.0
aptly config show
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.APTLY_GPG_KEY }}
passphrase: ${{ secrets.APTLY_GPG_PASS }}

- name: Install cargo deb
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-deb

- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --release

- name: Cargo deb
uses: actions-rs/cargo@v1
with:
command: deb

- name: Upload binaries to repo
env:
AWS_SECRET_ACCESS_KEY: ${{ secrets.APTLY_SECRET_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.APTLY_ACCESS_KEY }}
PLUGIN_REPO_NAME: ${{ secrets.APTLY_REPO }}
PLUGIN_REGION: ${{ secrets.APTLY_REGION }}
PLUGIN_GPG_KEY: ${{ secrets.APTLY_GPG_KEY }}
PLUGIN_GPG_PASS: ${{ secrets.APTLY_GPG_PASS }}
PLUGIN_ACL: 'public-read'
PLUGIN_PREFIX: 'releases'
PLUGIN_DEB_PATH: './target/debian'
PLUGIN_OS_CODENAME: ${{ matrix.code_name }}
run: ./ci/publish_deb_to_repo.sh

- name: Invalidate cloudfront
uses: chetan/invalidate-cloudfront-action@v1
env:
DISTRIBUTION: ${{ secrets.APTLY_DIST_ID }}
PATHS: "/*"
AWS_REGION: ${{ secrets.APTLY_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.APTLY_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.APTLY_SECRET_KEY }}

62 changes: 62 additions & 0 deletions ci/publish_deb_to_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
set -e

# DEFAULTS
PLUGIN_OS_CODENAME="${PLUGIN_OS_CODENAME:-bionic}"

# Verify all variables are present
if [[ -z $PLUGIN_GPG_KEY || -z $PLUGIN_GPG_PASS || -z $PLUGIN_REGION \
|| -z $PLUGIN_REPO_NAME || -z $PLUGIN_ACL || -z $PLUGIN_PREFIX \
|| -z $AWS_SECRET_ACCESS_KEY || -z $AWS_ACCESS_KEY_ID \
|| -z $PLUGIN_DEB_PATH || -z $PLUGIN_OS_CODENAME ]]; then
echo "ERROR: Environment Variable Missing!"
exit 1
fi

# Verify if its the first time publishing. Will need to know later.
# Probably an easier way to do this check :)
EXISTS=$(aws s3 ls s3://"$PLUGIN_REPO_NAME"/releases/dists/ --region "$PLUGIN_REGION" | grep "$PLUGIN_OS_CODENAME") || EXISTS_RET="false"

# Sanity Check for later
if [ "$EXISTS_RET" = "false" ]; then
echo "First time uploading repo!"
else
echo "Repo Exists! Defaulting to publish update..."
fi

### APTLY SECTION

# Move old config file to use in jq query
mv ~/.aptly.conf ~/.aptly.conf.orig

# Inject ENV Variables and save as .aptly.conf
jq --arg region "$PLUGIN_REGION" --arg bucket "$PLUGIN_REPO_NAME" --arg acl "$PLUGIN_ACL" --arg prefix "$PLUGIN_PREFIX" '.S3PublishEndpoints[$bucket] = {"region":$region, "bucket":$bucket, "acl": $acl, "prefix": $prefix}' ~/.aptly.conf.orig > ~/.aptly.conf

# If aptly repo DOESNT exist locally already
if [ ! "$(aptly repo list | grep $PLUGIN_OS_CODENAME)" ]; then
aptly repo create -distribution="$PLUGIN_OS_CODENAME" -component=main "release-$PLUGIN_OS_CODENAME"
fi

# If aptly mirror DOESNT exist locally already
if [ ! "$(aptly mirror list | grep $PLUGIN_OS_CODENAME)" ] && [ ! "$EXISTS_RET" = "false" ] ; then
aptly mirror create -ignore-signatures "local-repo-$PLUGIN_OS_CODENAME" https://"${PLUGIN_REPO_NAME}"/"${PLUGIN_PREFIX}"/ "${PLUGIN_OS_CODENAME}" main
fi

# When it's not the first time uploading.
if [ ! "$EXISTS_RET" = "false" ]; then
aptly mirror update -ignore-signatures "local-repo-$PLUGIN_OS_CODENAME"
# Found an article that said using 'Name' will select all packages for us
aptly repo import "local-repo-$PLUGIN_OS_CODENAME" "release-$PLUGIN_OS_CODENAME" Name
fi

# Add .debs to the local repo
aptly repo add -force-replace "release-$PLUGIN_OS_CODENAME" "$PLUGIN_DEB_PATH"/*.deb

# Publish to S3
if [ ! "$(aptly publish list | grep $PLUGIN_REPO_NAME | grep $PLUGIN_OS_CODENAME)" ]; then
# If the repo is new
aptly publish repo -batch -force-overwrite -passphrase="$PLUGIN_GPG_PASS" "release-$PLUGIN_OS_CODENAME" s3:"${PLUGIN_REPO_NAME}":
else
# If the repo exists
aptly publish update -batch -force-overwrite -passphrase="$PLUGIN_GPG_PASS" "$PLUGIN_OS_CODENAME" s3:"${PLUGIN_REPO_NAME}":
fi

0 comments on commit 534ee15

Please sign in to comment.