Skip to content

Commit

Permalink
Enable RPM and Deb package uploads to packages.smallstep.com
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoss committed Dec 11, 2024
1 parent 44758a9 commit 26b19bf
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ dist/

# Dependency directories (remove the comment below to include it)
# vendor/

# Packages files
0x889B19391F774443-Certify.key
gha-creds-*.json
36 changes: 33 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
# - https://github.com/goreleaser/goreleaser-cross
# - https://github.com/goreleaser/goreleaser-cross-example
project_name: step-kms-plugin
version: 2

variables:
packageName: step-kms-plugin
packageRelease: 1 # Manually update release: in the nfpm section to match this value if you change this

after:
hooks:
# This script depends on IS_PRERELEASE env being set. This is set by CI in the Is Pre-release step.
- cmd: bash scripts/package-repo-import.sh {{ .Var.packageName }} {{ .Version }}
output: true

builds:
- id: linux-amd64
Expand Down Expand Up @@ -113,11 +124,17 @@ archives:
- completions/*

nfpms:
- builds:
- id: packages
builds:
- linux-amd64
- linux-arm64
package_name: step-kms-plugin
file_name_template: "{{ .PackageName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
package_name: "{{ .Var.packageName }}"
release: "1"
file_name_template: >-
{{- trimsuffix .ConventionalFileName .ConventionalExtension -}}
{{- if and (eq .Arm "6") (eq .ConventionalExtension ".deb") }}6{{ end -}}
{{- if not (eq .Amd64 "v1")}}{{ .Amd64 }}{{ end -}}
{{- .ConventionalExtension -}}
vendor: Smallstep Labs
homepage: https://github.com/smallstep/step-kms-plugin
maintainer: Smallstep <techadmin@smallstep.com>
Expand All @@ -139,6 +156,13 @@ nfpms:
- src: completions/zsh_completion
dst: /usr/share/zsh/site-functions/_step-kms-plugin
packager: rpm
rpm:
signature:
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
deb:
signature:
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
type: origin
overrides:
deb:
dependencies:
Expand All @@ -160,6 +184,12 @@ sboms:
checksum:
name_template: "checksums.txt"

publishers:
- name: Google Cloud Artifact Registry
ids:
- packages
cmd: ./scripts/package-upload.sh {{ abs .ArtifactPath }} {{ .Var.packageName }} {{ .Version }} {{ .Var.packageRelease }}

snapshot:
name_template: "{{ .Tag }}"

Expand Down
56 changes: 56 additions & 0 deletions scripts/package-repo-import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

set -e

: ${GCLOUD_LOCATION:=us-central1}
: ${GCLOUD_RPM_REPO:=rpms}
: ${GCLOUD_DEB_REPO:=debs}

PACKAGE="${1}"
VERSION="${2}"
RELEASE="1"
EPOCH="0"
GORELEASER_PHASE=${GORELEASER_PHASE:-release}

echo "Package: ${PACKAGE}"
echo "Version: ${VERSION}"

check_package() {
local EXITCODE=0
local REPO="${1}"
local VER="${2}"
if [ ! -f /tmp/version-deleted.stamp ]; then
gcloud artifacts versions list \
--repository "${REPO}" \
--location "${GCLOUD_LOCATION}" \
--package "${PACKAGE}" \
--filter "VERSION:${VER}" \
--format json 2> /dev/null \
| jq -re '.[].name?' >/dev/null 2>&1 \
|| EXITCODE=$?
if [[ "${EXITCODE}" -eq 0 ]]; then
echo "Package version already exists. Removing it..."
gcloud artifacts versions delete \
--quiet "${VER}" \
--package "${PACKAGE}" \
--repository "${REPO}" \
--location "${GCLOUD_LOCATION}"
touch /tmp/version-deleted.stamp
fi
fi
}

if [[ ${IS_PRERELEASE} == "true" ]]; then
echo "Skipping artifact import; IS_PRERELEASE is 'true'"
exit 0;
fi

check_package "${GCLOUD_RPM_REPO}" "${EPOCH}:${VERSION}-${RELEASE}"
gcloud artifacts yum import "${GCLOUD_RPM_REPO}" \
--location "${GCLOUD_LOCATION}" \
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/*"

check_package ${GCLOUD_DEB_REPO} "${VERSION}-${RELEASE}"}
gcloud artifacts apt import "${GCLOUD_DEB_REPO}" \
--location "${GCLOUD_LOCATION}" \
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/*"
24 changes: 24 additions & 0 deletions scripts/package-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e
set -x

FILE="${1}"
PACKAGE="${2}"
VERSION="${3}"

echo "Package File: ${FILE}"
echo "Package: ${PACKAGE}"
echo "Version: ${VERSION}"
echo "Release: ${RELEASE}"
echo "Location: ${GCLOUD_LOCATION}"

if [ "${FILE: -4}" == ".deb" ]; then
if [[ "${FILE}" =~ "armhf6" ]]; then
echo "Skipping ${FILE} due to GCP Artifact Registry armhf conflict!"
else
gcloud storage cp ${FILE} gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/
fi
else
gcloud storage cp ${FILE} gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/
fi

0 comments on commit 26b19bf

Please sign in to comment.