Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@ jobs:
with:
version: 'latest'

- name: Assume AWS Marketplace ECR role
id: ecr-credentials
uses: aws-actions/configure-aws-credentials@v6.3.0
with:
role-to-assume: arn:aws:iam::588738614642:role/aws-marketplace-ecr
aws-region: us-east-1
translate-env-variables: false
output-credentials: true
output-env-credentials: false

- name: Run deploy script
env:
# Existing credentials publish the Helm repository to S3.
AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_REGION }}
# dev/ecr.sh uses the OIDC role credentials for Marketplace uploads.
ECR_AWS_ACCESS_KEY_ID: ${{ steps.ecr-credentials.outputs.aws-access-key-id }}
ECR_AWS_SECRET_ACCESS_KEY: ${{ steps.ecr-credentials.outputs.aws-secret-access-key }}
ECR_AWS_SESSION_TOKEN: ${{ steps.ecr-credentials.outputs.aws-session-token }}
run: |
chmod +x dev/deploy.sh
./dev/deploy.sh
32 changes: 32 additions & 0 deletions dev/aws-marketplace-ecr-trust-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "GitHubActions",
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::588738614642:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": [
"repo:pgdogdev/helm:*",
"repo:pgdogdev/pgdog:*"
]
}
}
},
{
"Sid": "AccountAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::588738614642:root"
},
"Action": "sts:AssumeRole"
}
]
}
9 changes: 7 additions & 2 deletions dev/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash

set -e
set -eo pipefail

SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_PATH/.."

CHART_NAME="pgdog"
DEPLOY_DIR="$PROJECT_ROOT/deploy"
PACKAGE_DIR="$(mktemp -d)"
trap 'rm -rf "$PACKAGE_DIR"' EXIT

echo "Creating deploy directory..."
rm -rf "$DEPLOY_DIR"
Expand All @@ -16,7 +18,8 @@ aws s3 sync s3://pgdog-helm "$DEPLOY_DIR"

echo "Packaging Helm chart..."
cd "$PROJECT_ROOT"
helm package . --destination "$DEPLOY_DIR"
helm package . --destination "$PACKAGE_DIR"
cp "$PACKAGE_DIR/$CHART_NAME-"*.tgz "$DEPLOY_DIR/"

echo "Creating/updating Helm repository index..."
helm repo index "$DEPLOY_DIR" --url "https://helm.pgdog.dev"
Expand All @@ -25,3 +28,5 @@ echo "Deployment artifacts created in $DEPLOY_DIR/"
ls -lsha "$DEPLOY_DIR/"

aws s3 sync "$DEPLOY_DIR" s3://pgdog-helm

bash "$SCRIPT_PATH/ecr.sh" "$PACKAGE_DIR/$CHART_NAME-"*.tgz
24 changes: 24 additions & 0 deletions dev/ecr-push-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AuthenticateToECR",
"Effect": "Allow",
"Action": "ecr:GetAuthorizationToken",
"Resource": "*"
},
{
"Sid": "PushImagesAndHelmCharts",
"Effect": "Allow",
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage"
],
"Resource": "arn:aws:ecr:us-east-1:709825985650:repository/pgdog/pgdog"
}
]
}
20 changes: 20 additions & 0 deletions dev/ecr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -eo pipefail

CHART_PACKAGE="${1:?Usage: ecr.sh <chart.tgz>}"
ECR_REGISTRY="709825985650.dkr.ecr.us-east-1.amazonaws.com"
ECR_REGION="us-east-1"

if [ -n "${ECR_AWS_ACCESS_KEY_ID:-}" ]; then
export AWS_ACCESS_KEY_ID="$ECR_AWS_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="${ECR_AWS_SECRET_ACCESS_KEY:?Missing ECR role secret access key}"
export AWS_SESSION_TOKEN="${ECR_AWS_SESSION_TOKEN:?Missing ECR role session token}"
fi

echo "Authenticating to AWS Marketplace ECR..."
aws ecr get-login-password --region "$ECR_REGION" | \
helm registry login --username AWS --password-stdin "$ECR_REGISTRY"

echo "Pushing Helm chart to AWS Marketplace ECR..."
helm push "$CHART_PACKAGE" "oci://$ECR_REGISTRY/pgdog"
Loading