Skip to content

Commit aab2269

Browse files
author
Victor Santos
committed
feat: add S3 environment variable validation and improve architecture detection
- Implemented a validation function for required S3 environment variables in upload_to_cloudsmith.sh, ensuring necessary credentials are set before proceeding with uploads. - Updated the architecture validation function in setup.apk.sh to enhance clarity and messaging, renaming it from validate_arch to detect_arch.
1 parent f5c0162 commit aab2269

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

scripts/setup.apk.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ check_tool() {
5151
fi
5252
}
5353

54-
validate_arch() {
55-
echo_status "RUN" "Validating system architecture..."
56-
local arch=$(uname -m)
57-
case "$arch" in
54+
detect_arch() {
55+
echo_status "RUN" "Detecting system architecture..."
56+
local raw_arch=$(uname -m)
57+
case "$raw_arch" in
5858
x86_64|amd64)
59+
arch="x86_64"
5960
;;
6061
aarch64|arm64)
62+
arch="aarch64"
6163
;;
6264
*)
63-
echo_status "FAIL" "Validating system architecture"
64-
die "Unsupported architecture: $arch. Supported: x86_64, aarch64"
65+
echo_status "FAIL" "Detecting system architecture"
66+
die "Unsupported architecture: $raw_arch. Supported: x86_64, aarch64"
6567
;;
6668
esac
67-
echo_status "OK" "Architecture supported: $arch"
69+
echo_status "OK" "Architecture detected: $arch"
6870
}
6971

7072
import_rsa_key() {
@@ -183,7 +185,7 @@ fi
183185
check_tool "wget"
184186

185187
# Setup
186-
validate_arch
188+
detect_arch
187189
import_rsa_key
188190
setup_repository
189191
update_apk

upload_to_cloudsmith.sh

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ set -eo pipefail
33

44
cd dist || { echo "Failed to cd into dist"; exit 1; }
55

6+
# Validate required environment variables for S3 uploads
7+
validate_s3_env() {
8+
local missing=()
9+
[ -z "$INFISICAL_CLI_S3_BUCKET" ] && missing+=("INFISICAL_CLI_S3_BUCKET")
10+
[ -z "$AWS_ACCESS_KEY_ID" ] && missing+=("AWS_ACCESS_KEY_ID")
11+
[ -z "$AWS_SECRET_ACCESS_KEY" ] && missing+=("AWS_SECRET_ACCESS_KEY")
12+
13+
if [ ${#missing[@]} -gt 0 ]; then
14+
echo "Warning: Missing environment variables for S3 uploads: ${missing[*]}"
15+
echo "S3 upload steps will be skipped."
16+
return 1
17+
fi
18+
return 0
19+
}
20+
21+
S3_ENABLED=false
22+
validate_s3_env && S3_ENABLED=true
23+
624
# ============================================
725
# APK - Upload to Cloudsmith (keep until S3 is validated)
826
# ============================================
@@ -14,7 +32,7 @@ done
1432
# ============================================
1533
# APK - Upload to S3 and generate APKINDEX
1634
# ============================================
17-
if ls *.apk 1> /dev/null 2>&1; then
35+
if ls *.apk 1> /dev/null 2>&1 && [ "$S3_ENABLED" = "true" ]; then
1836
echo "Processing APK packages..."
1937

2038
# Create local directory structure
@@ -91,22 +109,24 @@ done
91109
# ============================================
92110
# RPM - Upload to S3 and regenerate repo metadata
93111
# ============================================
94-
for i in *.rpm; do
95-
[ -f "$i" ] || break
96-
97-
# Sign the RPM package
98-
rpmsign --addsign --key-id="$INFISICAL_CLI_REPO_SIGNING_KEY_ID" "$i"
99-
100-
# Upload to S3
101-
aws s3 cp "$i" "s3://$INFISICAL_CLI_S3_BUCKET/rpm/Packages/"
102-
done
112+
if [ "$S3_ENABLED" = "true" ]; then
113+
for i in *.rpm; do
114+
[ -f "$i" ] || break
115+
116+
# Sign the RPM package
117+
rpmsign --addsign --key-id="$INFISICAL_CLI_REPO_SIGNING_KEY_ID" "$i"
118+
119+
# Upload to S3
120+
aws s3 cp "$i" "s3://$INFISICAL_CLI_S3_BUCKET/rpm/Packages/"
121+
done
103122

104-
# Regenerate RPM repository metadata with mkrepo
105-
# Note: mkrepo uses boto3 which automatically reads AWS_ACCESS_KEY_ID and
106-
# AWS_SECRET_ACCESS_KEY from environment variables set in the workflow
107-
if ls *.rpm 1> /dev/null 2>&1; then
108-
export GPG_SIGN_KEY=$INFISICAL_CLI_REPO_SIGNING_KEY_ID
109-
mkrepo "s3://$INFISICAL_CLI_S3_BUCKET/rpm" \
110-
--s3-region="us-east-1" \
111-
--sign
123+
# Regenerate RPM repository metadata with mkrepo
124+
# Note: mkrepo uses boto3 which automatically reads AWS_ACCESS_KEY_ID and
125+
# AWS_SECRET_ACCESS_KEY from environment variables set in the workflow
126+
if ls *.rpm 1> /dev/null 2>&1; then
127+
export GPG_SIGN_KEY=$INFISICAL_CLI_REPO_SIGNING_KEY_ID
128+
mkrepo "s3://$INFISICAL_CLI_S3_BUCKET/rpm" \
129+
--s3-region="us-east-1" \
130+
--sign
131+
fi
112132
fi

0 commit comments

Comments
 (0)