Skip to content
Merged
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
101 changes: 101 additions & 0 deletions .github/actions/deploy-website/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: 'Deploy Website to Amplify'
description: 'Build Hugo site and deploy to AWS Amplify'
inputs:
role:
description: 'AWS IAM role ARN to assume'
required: true
region:
description: 'AWS region for Amplify'
required: true
amplify-app-id:
description: 'AWS Amplify App ID'
required: true
amplify-branch-name:
description: 'AWS Amplify branch name'
required: true
s3-bucket:
description: 'S3 bucket for website files'
required: true
s3-prefix:
description: 'S3 prefix/path for website files'
required: false
default: ''
hugo-base-url:
description: 'Base URL for Hugo build'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Install Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version-file: test/hack/resource/parse-redirects/go.mod
check-latest: true
cache-dependency-path: "test/hack/resource/go.sum"
- name: Install Hugo
uses: peaceiris/actions-hugo@16361eb4acea8698b220b76c0d4e84e1fd22c61d # v2.6.0
with:
hugo-version: '0.120.3'
extended: true
- name: Build Hugo site (preview)
working-directory: website
shell: bash
env:
HUGO_ENV: production
HUGO_ENABLEGITINFO: true
TZ: America/Los_Angeles
HUGO_CACHEDIR: ${{ github.workspace }}/.hugo
NPM_CONFIG_CACHE: ${{ github.workspace }}/.npm
if: github.event_name == 'pull_request'
run: |
npm ci --prefer-offline
hugo --gc --minify --buildFuture -b "${{ inputs.hugo-base-url }}"
- name: Build Hugo site (production)
working-directory: website
shell: bash
env:
HUGO_ENV: production
HUGO_ENABLEGITINFO: true
TZ: America/Los_Angeles
HUGO_CACHEDIR: ${{ github.workspace }}/.hugo
NPM_CONFIG_CACHE: ${{ github.workspace }}/.npm
if: github.event_name == 'push'
run: |
npm ci --prefer-offline
hugo --gc --minify
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
with:
role-to-assume: ${{ inputs.role }}
aws-region: ${{ inputs.region }}
- name: Upload to S3
shell: bash
run: |
S3_PATH="s3://${{ inputs.s3-bucket }}/${{ inputs.s3-prefix }}"
aws s3 sync website/public/ "$S3_PATH" --delete
- name: Create Amplify branch (if preview and doesn't exist)
shell: bash
if: github.event_name == 'pull_request'
run: |
if ! aws amplify get-branch --app-id ${{ inputs.amplify-app-id }} --branch-name "${{ inputs.amplify-branch-name }}" 2>/dev/null; then
aws amplify create-branch \
--app-id ${{ inputs.amplify-app-id }} \
--branch-name "${{ inputs.amplify-branch-name }}"
fi
- name: Configure redirects
shell: bash
run: |
REDIRECT_RULES=$(go run test/hack/resource/parse-redirects/main.go)
aws amplify update-app \
--app-id ${{ inputs.amplify-app-id }} \
--custom-rules "$REDIRECT_RULES"
- name: Deploy to Amplify
shell: bash
run: |
SOURCE_URL="s3://${{ inputs.s3-bucket }}/${{ inputs.s3-prefix }}"
aws amplify start-deployment \
--app-id ${{ inputs.amplify-app-id }} \
--branch-name "${{ inputs.amplify-branch-name }}" \
--source-url "$SOURCE_URL" \
--source-url-type BUCKET_PREFIX
26 changes: 26 additions & 0 deletions .github/workflows/website-cleanup-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Cleanup Website PR Preview
on:
pull_request:
types: [ closed ]
paths: [ website/** ]
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- id: metadata
run: |
pr_number="${{ github.event.number }}"
echo PR_NUMBER="$pr_number" >> "$GITHUB_ENV"
echo BRANCH_NAME="pr-$pr_number" >> "$GITHUB_ENV"
- uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
with:
role-to-assume: arn:aws:iam::${{ vars.RELEASE_PREVIEW_ACCOUNT_ID }}:role/${{ vars.WEBSITE_ROLE_NAME }}
aws-region: ${{ vars.AMPLIFY_REGION }}
- run: |
if aws amplify get-branch --app-id ${{ vars.AMPLIFY_APP_ID_PREVIEW }} --branch-name "${{ env.BRANCH_NAME }}" 2>/dev/null; then
aws amplify delete-branch --app-id ${{ vars.AMPLIFY_APP_ID_PREVIEW }} --branch-name "${{ env.BRANCH_NAME }}"
fi
- run: aws s3 rm s3://${{ vars.AMPLIFY_S3_BUCKET_BETA }}/pr-${{ env.PR_NUMBER }}/ --recursive
21 changes: 21 additions & 0 deletions .github/workflows/website-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deploy Website to Amplify
on:
push:
branches: [ main ]
paths: [ website/** ]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Deploy website
uses: ./.github/actions/deploy-website
with:
role: arn:aws:iam::${{ vars.RELEASE_ACCOUNT_ID }}:role/${{ vars.WEBSITE_ROLE_NAME }}
region: ${{ vars.AMPLIFY_REGION }}
amplify-app-id: ${{ vars.AMPLIFY_APP_ID }}
amplify-branch-name: ${{ vars.BRANCH_NAME }}
s3-bucket: ${{ vars.AMPLIFY_S3_BUCKET }}
60 changes: 60 additions & 0 deletions .github/workflows/website-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Deploy Website Preview to Amplify
on:
pull_request:
types: [ opened, synchronize, reopened ]
branches: [ main ]
paths: [ website/** ]
jobs:
preview:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- id: metadata
run: |
pr_number="${{ github.event.number }}"
pr_commit="${{ github.event.pull_request.head.sha }}"
{
echo PR_COMMIT="$pr_commit"
echo PR_NUMBER="$pr_number"
echo BRANCH_NAME="pr-$pr_number"
} >> "$GITHUB_ENV"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
with:
role-to-assume: arn:aws:iam::${{ vars.RELEASE_PREVIEW_ACCOUNT_ID }}:role/${{ vars.WEBSITE_ROLE_NAME }}
aws-region: ${{ vars.AMPLIFY_REGION }}
- name: Get preview URL
run: |
APP_DOMAIN=$(aws amplify get-app --app-id ${{ vars.AMPLIFY_APP_ID_PREVIEW }} --query 'app.defaultDomain' --output text)
PREVIEW_URL="https://${{ env.BRANCH_NAME }}.$APP_DOMAIN"
echo PREVIEW_URL="$PREVIEW_URL" >> "$GITHUB_ENV"
- name: Deploy website
uses: ./.github/actions/deploy-website
with:
role: arn:aws:iam::${{ vars.RELEASE_PREVIEW_ACCOUNT_ID }}:role/${{ vars.WEBSITE_ROLE_NAME }}
region: ${{ vars.AMPLIFY_REGION }}
amplify-app-id: ${{ vars.AMPLIFY_APP_ID_PREVIEW }}
amplify-branch-name: ${{ env.BRANCH_NAME }}
s3-bucket: ${{ vars.AMPLIFY_S3_BUCKET_BETA }}
s3-prefix: pr-${{ env.PR_NUMBER }}/
hugo-base-url: ${{ env.PREVIEW_URL }}
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
PREVIEW_URL: ${{ env.PREVIEW_URL }}
PR_COMMIT: ${{ env.PR_COMMIT }}
with:
script: |
github.rest.issues.createComment({
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: `**Preview deployment ready!**

**Preview URL:** ${process.env.PREVIEW_URL}

Built from commit \`${process.env.PR_COMMIT}\``
})
3 changes: 3 additions & 0 deletions test/hack/resource/parse-redirects/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/aws/karpenter-provider-aws/test/hack/resource/parse-redirects

go 1.24.4
112 changes: 112 additions & 0 deletions test/hack/resource/parse-redirects/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"strings"
)

type RedirectRule struct {
Source string `json:"source"`
Target string `json:"target"`
Status string `json:"status"`
}

func getAvailableKarpenterVersions() []string {
// scans the website content directory to find available for wildcard redirect expansion
contentDir := "website/content/en"
entries, err := os.ReadDir(contentDir)
if err != nil {
log.Fatalf("Error: Failed to read content directory: %v\n", err)
}
var versions []string
for _, entry := range entries {
if entry.IsDir() {
name := entry.Name()
versions = append(versions, name)
}
}
return versions
}

func getRule(source string, target string, versions []string) []RedirectRule {
var rules []RedirectRule

if !strings.Contains(source, "*") {
return []RedirectRule{{
Source: source,
Target: target,
Status: "301",
}}
}

// Expand wildcard for each version
for _, version := range versions {
if strings.Contains(target, version) { // ensure non-looping redirects
continue
}
expandedSource := strings.ReplaceAll(source, "*", version)
rules = append(rules, RedirectRule{
Source: expandedSource,
Target: target,
Status: "301",
})
}

return rules
}

func main() {
redirectsFile := "website/static/_redirects"
versions := getAvailableKarpenterVersions()
file, err := os.Open(redirectsFile)
if err != nil {
log.Fatalf("Error reading %s: %v\n", redirectsFile, err)
}
defer file.Close()

var rules []RedirectRule
scanner := bufio.NewScanner(file)
lineNum := 0
for scanner.Scan() {
lineNum++
line := strings.TrimSpace(scanner.Text())

if line == "" || strings.HasPrefix(line, "#") {
continue
}
parts := strings.Fields(line)
if len(parts) == 2 {
expandedRules := getRule(parts[0], parts[1], versions)
rules = append(rules, expandedRules...)
} else {
log.Fatalf("Error: Invalid redirect format on line %d: %s\n", lineNum, line)
}
}

if err := scanner.Err(); err != nil {
log.Fatalf("Error reading %s: %v\n", redirectsFile, err)
}
jsonData, err := json.Marshal(rules)
if err != nil {
log.Fatalf("Error marshaling JSON: %v\n", err)
}
fmt.Println(string(jsonData))
}
5 changes: 4 additions & 1 deletion website/layouts/partials/navbar-version-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
{{ end }}
{{ $pagePath := replace .Page.RelPermalink "docs" "" }}
{{ $pagePath = replace $pagePath $pageDir "" }}
{{ $pagePath = trim $pagePath "/" }}

<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ $pageDir }} {{ if eq (index .Site.Params.versions 0) $pageDir }} (latest) {{ end }}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink" id="navbarVersionSelector">
{{ range $index, $version := .Site.Params.versions }}
<a class="dropdown-item" href='/{{ $version }}{{ $pagePath }}' data-docs-version="{{ $version }}">
<a class="dropdown-item"
href='/{{ $version }}{{ if not (hasPrefix $pagePath "/") }}{{ "/" }}{{ end }}{{ $pagePath }}'
data-docs-version="{{ $version }}">
{{ $version }} {{ if eq $index 0 }} (latest) {{ end }}
</a>
{{ end }}
Expand Down
Loading