Skip to content

Commit 7fcbad4

Browse files
author
Joe Doss
committed
Add support in for signing and publishing RPM and Deb packages to GCP Artifact Registry.
1 parent 9df0fa8 commit 7fcbad4

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

.goreleaser.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ before:
66
hooks:
77
- go mod download
88

9+
after:
10+
hooks:
11+
- cmd: bash scripts/package-repo-import.sh {{ .Var.packageName }} {{ .Version }}
12+
output: true
13+
914
builds:
1015
- &BUILD
1116
id: default
@@ -87,7 +92,7 @@ nfpms:
8792
builds:
8893
- nfpm
8994
package_name: step-cli
90-
file_name_template: "{{ .PackageName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
95+
file_name_template: "{{.ConventionalFileName}}"
9196
vendor: Smallstep Labs
9297
homepage: https://github.com/smallstep/cli
9398
maintainer: Smallstep <[email protected]>
@@ -113,6 +118,13 @@ nfpms:
113118
scripts:
114119
postinstall: scripts/postinstall.sh
115120
postremove: scripts/postremove.sh
121+
rpm:
122+
signature:
123+
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
124+
deb:
125+
signature:
126+
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
127+
type: origin
116128
-
117129
<< : *NFPM
118130
id: unversioned
@@ -134,6 +146,13 @@ signs:
134146
args: ["sign-blob", "--oidc-issuer=https://token.actions.githubusercontent.com", "--output-certificate=${certificate}", "--output-signature=${signature}", "${artifact}", "--yes"]
135147
artifacts: all
136148

149+
publishers:
150+
- name: Google Cloud Artifact Registry
151+
ids:
152+
- packages
153+
cmd: ./scripts/package-upload.sh {{ abs .ArtifactPath }} {{ .Var.packageName }} {{ .Version }} {{ .Var.packageRelease }}
154+
disable: "{{ if .IsNightly }}true{{ end }}"
155+
137156
snapshot:
138157
name_template: "{{ .Tag }}-next"
139158

scripts/package-repo-import.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
: ${GCLOUD_LOCATION:=us-central1}
6+
: ${GCLOUD_RPM_REPO:=rpms}
7+
: ${GCLOUD_DEB_REPO:=debs}
8+
9+
PACKAGE="${1}"
10+
VERSION="${2}"
11+
RELEASE="1"
12+
EPOCH="0"
13+
GORELEASER_PHASE=${GORELEASER_PHASE:-release}
14+
15+
echo "Package: ${PACKAGE}"
16+
echo "Version: ${VERSION}"
17+
18+
check_package() {
19+
local EXITCODE=0
20+
local REPO="${1}"
21+
local VER="${2}"
22+
if [ ! -f /tmp/version-deleted.stamp ]; then
23+
gcloud artifacts versions list --repository "${REPO}" --location "${GCLOUD_LOCATION}" --package "${PACKAGE}" \
24+
--filter "VERSION:${VER}" --format json 2> /dev/null |jq -re '.[].name?' >/dev/null 2>&1 || EXITCODE=$?
25+
if [[ "${EXITCODE}" -eq 0 ]]; then
26+
echo "Package version already exists. Removing it..."
27+
gcloud artifacts versions delete --quiet "${VER}" --package "${PACKAGE}" --repository "${REPO}" --location "${GCLOUD_LOCATION}"
28+
touch /tmp/version-deleted.stamp
29+
fi
30+
fi
31+
}
32+
33+
if [[ ${GORELEASER_PHASE} != "publish" ]]; then
34+
echo "Skipping artifact import; GORELEASER_PHASE is not 'publish'"
35+
exit 0;
36+
fi
37+
38+
check_package "${GCLOUD_RPM_REPO}" "${EPOCH}:${VERSION}-${RELEASE}"
39+
gcloud artifacts yum import "${GCLOUD_RPM_REPO}" \
40+
--location "${GCLOUD_LOCATION}" \
41+
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/*"
42+
43+
check_package ${GCLOUD_DEB_REPO} "${VERSION}-${RELEASE}"}
44+
gcloud artifacts apt import "${GCLOUD_DEB_REPO}" \
45+
--location "${GCLOUD_LOCATION}" \
46+
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/*"

scripts/package-upload.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
FILE="${1}"
6+
PACKAGE="${2}"
7+
VERSION="${3}"
8+
9+
echo "Package File: ${FILE}"
10+
echo "Package: ${PACKAGE}"
11+
echo "Version: ${VERSION}"
12+
echo "Release: ${RELEASE}"
13+
echo "Location: ${GCLOUD_LOCATION}"
14+
15+
if [ "${FILE: -4}" == ".deb" ]; then
16+
gcloud storage cp ${FILE} gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/
17+
else
18+
gcloud storage cp ${FILE} gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/
19+
fi

0 commit comments

Comments
 (0)