-
Notifications
You must be signed in to change notification settings - Fork 1.2k
ci: Amplify Website Hosting Workflows #8301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
606844f
ci: Amplify Website Hosting Workflows
ryan-mist 82daf9f
change cleanup script to go
ryan-mist a81e41d
fix comments
ryan-mist 5d5095a
replace duplicate work with action
ryan-mist 0273f12
Merge pull request #15 from ryan-mist/amplify-workflow
ryan-mist b50b4fc
replace duplicate work with action
ryan-mist 1d9f756
naming fixes
ryan-mist 6aa077a
Merge branch 'main' into amplify-workflow
ryan-mist dd5eff5
change amplify action input
ryan-mist 07d9cd8
for testing
ryan-mist f873d56
fix action
ryan-mist d595f20
remove testing part
ryan-mist 70c1f73
Merge branch 'main' into amplify-workflow
ryan-mist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}\`` | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.