Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable RPM and Deb package uploads to packages.smallstep.com #202

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
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
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PKG?=github.com/smallstep/step-kms-plugin
BINNAME?=step-kms-plugin
GOLANG_CROSS_VERSION?=v1.22
GOLANG_CROSS_VERSION?=v1.24

# Set V to 1 for verbose output from the Makefile
Q=$(if $V,,@)
Expand Down Expand Up @@ -115,19 +115,21 @@ govulncheck:

release-dev:
$Q @docker run -it --rm --privileged -e CGO_ENABLED=1 \
-e GORELEASER_KEY=${GORELEASER_KEY} \
jdoss marked this conversation as resolved.
Show resolved Hide resolved
--entrypoint /bin/bash \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PKG) \
-w /go/src/$(PKG) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION}
ghcr.io/goreleaser/goreleaser-cross-pro:${GOLANG_CROSS_VERSION}

release-dry-run:
$Q @docker run --rm --privileged -e CGO_ENABLED=1 \
-e GORELEASER_KEY=${GORELEASER_KEY} \
jdoss marked this conversation as resolved.
Show resolved Hide resolved
--entrypoint /go/src/$(PKG)/docker/build/entrypoint.sh \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PKG) \
-w /go/src/$(PKG) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
ghcr.io/goreleaser/goreleaser-cross-pro:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish

release:
Expand All @@ -136,11 +138,12 @@ release:
exit 1;\
fi
$Q @docker run --rm --privileged -e CGO_ENABLED=1 --env-file .release-env \
-e GORELEASER_KEY=${GORELEASER_KEY} \
--entrypoint /go/src/$(PKG)/docker/build/entrypoint.sh \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PKG) \
-w /go/src/$(PKG) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
ghcr.io/goreleaser/goreleaser-cross-pro:${GOLANG_CROSS_VERSION} \
release --clean

.PHONY: release-dev release-dry-run release
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
jdoss marked this conversation as resolved.
Show resolved Hide resolved

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
Loading