-
Notifications
You must be signed in to change notification settings - Fork 8.1k
cloudfront update with lambda function for redirects #15151
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
thaJeztah
merged 5 commits into
docker:master
from
crazy-max:cloudfront-lambda-redirects
Aug 17, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92948cb
lab: cloudfront update with lambda edge function for redirects
crazy-max a0c0aec
lab: move s3 redirects to lambda function
crazy-max 4429162
ci: create deploy workflow for new way to deploy docs
crazy-max 73a7690
ci: set aws config for stage env
crazy-max 1b93493
ci: set aws config for prod env
crazy-max 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,121 @@ | ||
| name: deploy | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - lab | ||
| - master | ||
| - published | ||
|
|
||
| # these permissions are needed to interact with GitHub's OIDC Token endpoint. | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-20.04 | ||
| steps: | ||
| - | ||
| name: Prepare | ||
| run: | | ||
| JEKYLL_ENV=development | ||
| DOCS_AWS_REGION=us-east-1 | ||
| if [ "${{ github.ref }}" = "refs/heads/master" ]; then | ||
| DOCS_URL="https://docs-stage2.docker.com" # TODO: change this to https://docs-stage.docker.com when new env switched and ready | ||
| DOCS_AWS_IAM_ROLE="arn:aws:iam::710015040892:role/stage-docs-docker.github.io-20220816140248629900000003" | ||
| DOCS_S3_BUCKET="stage-docs-docker.github.io" | ||
| DOCS_S3_CONFIG="s3-config.json" | ||
| DOCS_CLOUDFRONT_ID="E1R7CSW3F0X4H8" | ||
| DOCS_LAMBDA_FUNCTION_REDIRECTS="DockerDocsRedirectFunction-stage" | ||
| DOCS_SLACK_MSG="Successfully deployed docs-stage2 from master branch. $DOCS_URL" # TODO: change to "deployed docs-stage" when new env switched and ready | ||
| elif [ "${{ github.ref }}" = "refs/heads/published" ]; then | ||
| #JEKYLL_ENV=production # TODO: uncomment when new env switched and ready | ||
| DOCS_URL="https://docs2.docker.com" # TODO: change this to https://docs.docker.com when new env switched and ready | ||
| DOCS_AWS_IAM_ROLE="arn:aws:iam::710015040892:role/prod-docs-docker.github.io-20220816161549883800000001" | ||
| DOCS_S3_BUCKET="prod-docs-docker.github.io" | ||
| DOCS_S3_CONFIG="s3-config.json" | ||
| DOCS_CLOUDFRONT_ID="E228TTN20HNU8F" | ||
| DOCS_LAMBDA_FUNCTION_REDIRECTS="DockerDocsRedirectFunction-prod" | ||
| DOCS_SLACK_MSG="Successfully deployed docs2 from published branch. $DOCS_URL" # TODO: change to "deployed docs" when new env switched and ready | ||
| elif [ "${{ github.ref }}" = "refs/heads/lab" ]; then | ||
| DOCS_URL="https://docs-labs.docker.com" | ||
| DOCS_AWS_IAM_ROLE="arn:aws:iam::710015040892:role/labs-docs-docker.github.io-20220728143917865600000003" | ||
| DOCS_S3_BUCKET="labs-docs-docker.github.io" | ||
| DOCS_S3_CONFIG="s3-config.json" | ||
| DOCS_CLOUDFRONT_ID="E1MYDYF65FW3HG" | ||
| DOCS_LAMBDA_FUNCTION_REDIRECTS="DockerDocsRedirectFunction-labs" | ||
| DOCS_SLACK_MSG="Successfully deployed docs-labs from lab branch. $DOCS_URL" | ||
| else | ||
| echo >&2 "ERROR: unknown branch ${{ github.ref }}" | ||
| exit 1 | ||
| fi | ||
| SEND_SLACK_MSG="true" | ||
| if [ -z "$DOCS_AWS_IAM_ROLE" ] || [ -z "$DOCS_S3_BUCKET" ] || [ -z "$DOCS_CLOUDFRONT_ID" ] || [ -z "$DOCS_SLACK_MSG" ]; then | ||
| SEND_SLACK_MSG="false" | ||
| fi | ||
| echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | ||
| echo "JEKYLL_ENV=$JEKYLL_ENV" >> $GITHUB_ENV | ||
| echo "DOCS_URL=$DOCS_URL" >> $GITHUB_ENV | ||
| echo "DOCS_AWS_REGION=$DOCS_AWS_REGION" >> $GITHUB_ENV | ||
| echo "DOCS_AWS_IAM_ROLE=$DOCS_AWS_IAM_ROLE" >> $GITHUB_ENV | ||
| echo "DOCS_S3_BUCKET=$DOCS_S3_BUCKET" >> $GITHUB_ENV | ||
| echo "DOCS_S3_CONFIG=$DOCS_S3_CONFIG" >> $GITHUB_ENV | ||
| echo "DOCS_CLOUDFRONT_ID=$DOCS_CLOUDFRONT_ID" >> $GITHUB_ENV | ||
| echo "DOCS_LAMBDA_FUNCTION_REDIRECTS=$DOCS_LAMBDA_FUNCTION_REDIRECTS" >> $GITHUB_ENV | ||
| echo "DOCS_SLACK_MSG=$DOCS_SLACK_MSG" >> $GITHUB_ENV | ||
| echo "SEND_SLACK_MSG=$SEND_SLACK_MSG" >> $GITHUB_ENV | ||
| - | ||
| name: Checkout | ||
| uses: actions/checkout@v3 | ||
| - | ||
| name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
| - | ||
| name: Build website | ||
| uses: docker/bake-action@v2 | ||
| with: | ||
| targets: release | ||
| set: | | ||
| *.cache-from=type=gha,scope=deploy-${{ env.BRANCH_NAME }} | ||
| *.cache-to=type=gha,scope=deploy-${{ env.BRANCH_NAME }},mode=max | ||
| - | ||
| name: Configure AWS Credentials | ||
| if: ${{ env.DOCS_AWS_IAM_ROLE != '' }} | ||
| uses: aws-actions/configure-aws-credentials@v1 | ||
| with: | ||
| role-to-assume: ${{ env.DOCS_AWS_IAM_ROLE }} | ||
| aws-region: ${{ env.DOCS_AWS_REGION }} | ||
| - | ||
| name: Upload files to S3 bucket | ||
| if: ${{ env.DOCS_S3_BUCKET != '' }} | ||
| run: | | ||
| aws --region ${{ env.DOCS_AWS_REGION }} s3 sync --acl public-read _site s3://${{ env.DOCS_S3_BUCKET }}/ --delete | ||
| - | ||
| name: Update S3 config | ||
| if: ${{ env.DOCS_S3_BUCKET != '' && env.DOCS_S3_CONFIG != '' }} | ||
| uses: docker/bake-action@v2 | ||
| with: | ||
| targets: aws-s3-update-config | ||
| set: | | ||
| *.cache-from=type=gha,scope=releaser | ||
| env: | ||
| AWS_REGION: ${{ env.DOCS_AWS_REGION }} | ||
| AWS_S3_BUCKET: ${{ env.DOCS_S3_BUCKET }} | ||
| AWS_S3_CONFIG: ${{ env.DOCS_S3_CONFIG }} | ||
| - | ||
| name: Update Cloudfront config | ||
| if: ${{ env.DOCS_CLOUDFRONT_ID != '' }} | ||
| uses: docker/bake-action@v2 | ||
| with: | ||
| targets: aws-cloudfront-update | ||
| env: | ||
| AWS_REGION: us-east-1 # cloudfront and lambda edge functions are only available in us-east-1 region | ||
| AWS_CLOUDFRONT_ID: ${{ env.DOCS_CLOUDFRONT_ID }} | ||
| AWS_LAMBDA_FUNCTION: ${{ env.DOCS_LAMBDA_FUNCTION_REDIRECTS }} | ||
| - | ||
| name: Send Slack notification | ||
| if: ${{ env.SEND_SLACK_MSG == 'true' }} | ||
| run: | | ||
| curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ env.DOCS_SLACK_MSG }}"}' ${{ secrets.SLACK_WEBHOOK }} | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably too late now (?) to rename these buckets but we should really try to get rid of that
docker.github.ioeverywhere, and usedocs.docker.com(also rename the repository back todocsordocumentationordocs.docker.comat some point)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's to match the name of the repository. Am I right @VictorBersy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was to match the repo name, but I don't mind renaming them. It's not too late for that.
I can name everything as docs.docker.com. Ideally, it would match the future name of the repository. Let me know 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have a final "verdict" on the repository name (but anything else than
docker.github.io😂)docker/docswould work for me (with the caveat that we used to have a repository with that name that's now archived; https://github.com/docker-archive/docs.docker.comOh, LOL, and which apparently also was renamed to
docs.docker.com😂 so either way we would break a redirect (not really important, that stuff is pre-historic).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know when you have one, ideally before the production release, as it would make the migration more tedious 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VictorBersy if it's ok with you that potentially the name of the bucket doesn't match the name of the repository, I'm inclined to name the buckets after the domain they're for (
docs.docker.com/docs-stage.docker.cometc) as those are unlikely to change.@crazy-max WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh absolutely, no problem with that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it