Skip to content

Commit 35525cb

Browse files
authored
Merge pull request #1246 from smallstep/jdoss/Package_Repos
Add support in for signing and publishing RPM and Deb packages to GCP Artifact Registry
2 parents 01656b3 + 082fe65 commit 35525cb

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ jobs:
6767
permissions:
6868
id-token: write
6969
contents: write
70+
packages: write
7071
uses: smallstep/workflows/.github/workflows/goreleaser.yml@main
72+
with:
73+
enable-packages-upload: true
7174
secrets: inherit
7275

7376
build_upload_docker:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ go.work.sum
2222
coverage.txt
2323
output
2424
vendor
25+
dist/
2526
step
2627
.idea
2728
.envrc
29+
30+
# Packages files
31+
0x889B19391F774443-Certify.key
32+
gha-creds-*.json

.goreleaser.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# Documentation: https://goreleaser.com/customization/
2+
# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json
23
version: 2
34
project_name: step
45

6+
variables:
7+
packageName: step-cli
8+
packageRelease: 1 # Manually update release: in the nfpm section to match this value if you change this
9+
510
before:
611
hooks:
712
- go mod download
813

14+
after:
15+
hooks:
16+
- cmd: bash scripts/package-repo-import.sh {{ .Var.packageName }} {{ .Version }}
17+
output: true
18+
919
builds:
1020
- &BUILD
1121
id: default
@@ -86,8 +96,13 @@ nfpms:
8696
- &NFPM
8797
builds:
8898
- nfpm
89-
package_name: step-cli
90-
file_name_template: "{{ .PackageName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
99+
package_name: "{{ .Var.packageName }}"
100+
release: "1"
101+
file_name_template: >-
102+
{{- trimsuffix .ConventionalFileName .ConventionalExtension -}}
103+
{{- if and (eq .Arm "6") (eq .ConventionalExtension ".deb") }}6{{ end -}}
104+
{{- if not (eq .Amd64 "v1")}}{{ .Amd64 }}{{ end -}}
105+
{{- .ConventionalExtension -}}
91106
vendor: Smallstep Labs
92107
homepage: https://github.com/smallstep/cli
93108
maintainer: Smallstep <[email protected]>
@@ -113,6 +128,13 @@ nfpms:
113128
scripts:
114129
postinstall: scripts/postinstall.sh
115130
postremove: scripts/postremove.sh
131+
rpm:
132+
signature:
133+
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
134+
deb:
135+
signature:
136+
key_file: "{{ .Env.GPG_PRIVATE_KEY_FILE }}"
137+
type: origin
116138
-
117139
<< : *NFPM
118140
id: unversioned
@@ -134,6 +156,13 @@ signs:
134156
args: ["sign-blob", "--oidc-issuer=https://token.actions.githubusercontent.com", "--output-certificate=${certificate}", "--output-signature=${signature}", "${artifact}", "--yes"]
135157
artifacts: all
136158

159+
publishers:
160+
- name: Google Cloud Artifact Registry
161+
ids:
162+
- packages
163+
cmd: ./scripts/package-upload.sh {{ abs .ArtifactPath }} {{ .Var.packageName }} {{ .Version }} {{ .Var.packageRelease }}
164+
disable: "{{ if .Prerelease }}true{{ end }}"
165+
137166
snapshot:
138167
name_template: "{{ .Tag }}-next"
139168

scripts/package-repo-import.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 \
24+
--repository "${REPO}" \
25+
--location "${GCLOUD_LOCATION}" \
26+
--package "${PACKAGE}" \
27+
--filter "VERSION:${VER}" \
28+
--format json 2> /dev/null \
29+
| jq -re '.[].name?' >/dev/null 2>&1 \
30+
|| EXITCODE=$?
31+
if [[ "${EXITCODE}" -eq 0 ]]; then
32+
echo "Package version already exists. Removing it..."
33+
gcloud artifacts versions delete \
34+
--quiet "${VER}" \
35+
--package "${PACKAGE}" \
36+
--repository "${REPO}" \
37+
--location "${GCLOUD_LOCATION}"
38+
touch /tmp/version-deleted.stamp
39+
fi
40+
fi
41+
}
42+
43+
if [[ ${GORELEASER_PHASE} != "publish" ]]; then
44+
echo "Skipping artifact import; GORELEASER_PHASE is not 'publish'"
45+
exit 0;
46+
fi
47+
48+
check_package "${GCLOUD_RPM_REPO}" "${EPOCH}:${VERSION}-${RELEASE}"
49+
gcloud artifacts yum import "${GCLOUD_RPM_REPO}" \
50+
--location "${GCLOUD_LOCATION}" \
51+
--gcs-source "gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/*"
52+
53+
check_package ${GCLOUD_DEB_REPO} "${VERSION}-${RELEASE}"}
54+
gcloud artifacts apt import "${GCLOUD_DEB_REPO}" \
55+
--location "${GCLOUD_LOCATION}" \
56+
--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)