Skip to content

Commit 534ee15

Browse files
authored
Merge pull request #42 from sacherjj/debian_package
Initial debian package
2 parents fe1240b + 1e37716 commit 534ee15

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
name: publish-casper-db-utils-deb
3+
4+
on:
5+
push:
6+
tags:
7+
- "v*.*.*"
8+
9+
jobs:
10+
publish-deb:
11+
strategy:
12+
matrix:
13+
include:
14+
- os: ubuntu-20.04
15+
code_name: focal
16+
17+
runs-on: ${{ matrix.os }}
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: actions-rs/toolchain@v1
22+
with:
23+
toolchain: stable
24+
profile: minimal
25+
26+
- name: Install deps
27+
run: |
28+
echo "deb http://repo.aptly.info/ squeeze main" | sudo tee -a /etc/apt/sources.list.d/aptly.list
29+
wget -qO - https://www.aptly.info/pubkey.txt | sudo apt-key add -
30+
sudo apt-get update
31+
sudo apt-get install -y awscli aptly=1.2.0
32+
aptly config show
33+
34+
- name: Import GPG key
35+
uses: crazy-max/ghaction-import-gpg@v4
36+
with:
37+
gpg_private_key: ${{ secrets.APTLY_GPG_KEY }}
38+
passphrase: ${{ secrets.APTLY_GPG_PASS }}
39+
40+
- name: Install cargo deb
41+
uses: actions-rs/cargo@v1
42+
with:
43+
command: install
44+
args: cargo-deb
45+
46+
- name: Cargo build
47+
uses: actions-rs/cargo@v1
48+
with:
49+
command: build
50+
args: --release
51+
52+
- name: Cargo deb
53+
uses: actions-rs/cargo@v1
54+
with:
55+
command: deb
56+
57+
- name: Upload binaries to repo
58+
env:
59+
AWS_SECRET_ACCESS_KEY: ${{ secrets.APTLY_SECRET_KEY }}
60+
AWS_ACCESS_KEY_ID: ${{ secrets.APTLY_ACCESS_KEY }}
61+
PLUGIN_REPO_NAME: ${{ secrets.APTLY_REPO }}
62+
PLUGIN_REGION: ${{ secrets.APTLY_REGION }}
63+
PLUGIN_GPG_KEY: ${{ secrets.APTLY_GPG_KEY }}
64+
PLUGIN_GPG_PASS: ${{ secrets.APTLY_GPG_PASS }}
65+
PLUGIN_ACL: 'public-read'
66+
PLUGIN_PREFIX: 'releases'
67+
PLUGIN_DEB_PATH: './target/debian'
68+
PLUGIN_OS_CODENAME: ${{ matrix.code_name }}
69+
run: ./ci/publish_deb_to_repo.sh
70+
71+
- name: Invalidate cloudfront
72+
uses: chetan/invalidate-cloudfront-action@v1
73+
env:
74+
DISTRIBUTION: ${{ secrets.APTLY_DIST_ID }}
75+
PATHS: "/*"
76+
AWS_REGION: ${{ secrets.APTLY_REGION }}
77+
AWS_ACCESS_KEY_ID: ${{ secrets.APTLY_ACCESS_KEY }}
78+
AWS_SECRET_ACCESS_KEY: ${{ secrets.APTLY_SECRET_KEY }}
79+

ci/publish_deb_to_repo.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# DEFAULTS
5+
PLUGIN_OS_CODENAME="${PLUGIN_OS_CODENAME:-bionic}"
6+
7+
# Verify all variables are present
8+
if [[ -z $PLUGIN_GPG_KEY || -z $PLUGIN_GPG_PASS || -z $PLUGIN_REGION \
9+
|| -z $PLUGIN_REPO_NAME || -z $PLUGIN_ACL || -z $PLUGIN_PREFIX \
10+
|| -z $AWS_SECRET_ACCESS_KEY || -z $AWS_ACCESS_KEY_ID \
11+
|| -z $PLUGIN_DEB_PATH || -z $PLUGIN_OS_CODENAME ]]; then
12+
echo "ERROR: Environment Variable Missing!"
13+
exit 1
14+
fi
15+
16+
# Verify if its the first time publishing. Will need to know later.
17+
# Probably an easier way to do this check :)
18+
EXISTS=$(aws s3 ls s3://"$PLUGIN_REPO_NAME"/releases/dists/ --region "$PLUGIN_REGION" | grep "$PLUGIN_OS_CODENAME") || EXISTS_RET="false"
19+
20+
# Sanity Check for later
21+
if [ "$EXISTS_RET" = "false" ]; then
22+
echo "First time uploading repo!"
23+
else
24+
echo "Repo Exists! Defaulting to publish update..."
25+
fi
26+
27+
### APTLY SECTION
28+
29+
# Move old config file to use in jq query
30+
mv ~/.aptly.conf ~/.aptly.conf.orig
31+
32+
# Inject ENV Variables and save as .aptly.conf
33+
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
34+
35+
# If aptly repo DOESNT exist locally already
36+
if [ ! "$(aptly repo list | grep $PLUGIN_OS_CODENAME)" ]; then
37+
aptly repo create -distribution="$PLUGIN_OS_CODENAME" -component=main "release-$PLUGIN_OS_CODENAME"
38+
fi
39+
40+
# If aptly mirror DOESNT exist locally already
41+
if [ ! "$(aptly mirror list | grep $PLUGIN_OS_CODENAME)" ] && [ ! "$EXISTS_RET" = "false" ] ; then
42+
aptly mirror create -ignore-signatures "local-repo-$PLUGIN_OS_CODENAME" https://"${PLUGIN_REPO_NAME}"/"${PLUGIN_PREFIX}"/ "${PLUGIN_OS_CODENAME}" main
43+
fi
44+
45+
# When it's not the first time uploading.
46+
if [ ! "$EXISTS_RET" = "false" ]; then
47+
aptly mirror update -ignore-signatures "local-repo-$PLUGIN_OS_CODENAME"
48+
# Found an article that said using 'Name' will select all packages for us
49+
aptly repo import "local-repo-$PLUGIN_OS_CODENAME" "release-$PLUGIN_OS_CODENAME" Name
50+
fi
51+
52+
# Add .debs to the local repo
53+
aptly repo add -force-replace "release-$PLUGIN_OS_CODENAME" "$PLUGIN_DEB_PATH"/*.deb
54+
55+
# Publish to S3
56+
if [ ! "$(aptly publish list | grep $PLUGIN_REPO_NAME | grep $PLUGIN_OS_CODENAME)" ]; then
57+
# If the repo is new
58+
aptly publish repo -batch -force-overwrite -passphrase="$PLUGIN_GPG_PASS" "release-$PLUGIN_OS_CODENAME" s3:"${PLUGIN_REPO_NAME}":
59+
else
60+
# If the repo exists
61+
aptly publish update -batch -force-overwrite -passphrase="$PLUGIN_GPG_PASS" "$PLUGIN_OS_CODENAME" s3:"${PLUGIN_REPO_NAME}":
62+
fi

0 commit comments

Comments
 (0)