Merge pull request #14768 from crazy-max/ci-jobs

ci: split build and publish workflows and set up cache
This commit is contained in:
Sebastiaan van Stijn 2022-05-18 17:50:09 +02:00 committed by GitHub
commit a2d43f4584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 56 deletions

View File

@ -2,36 +2,15 @@ name: build
on:
push:
# needs push event on default branch otherwise cache is evicted when pull request is merged
branches:
- master
- published
pull_request:
jobs:
release:
build:
runs-on: ubuntu-20.04
steps:
-
name: Prepare
run: |
JEKYLL_ENV=development
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
DOCS_S3_HOST="docs.docker.com-stage-us-east-1"
DOCS_AWS_LAMBDA="arn:aws:lambda:us-east-1:710015040892:function:docs-stage-cache-invalidator"
DOCS_SLACK_MSG="Successfully promoted docs-stage from master. https://docs-stage.docker.com/"
DOCS_WEBCONFIG="_website-config-docs-stage.json"
elif [ "${{ github.ref }}" = "refs/heads/published" ]; then
JEKYLL_ENV=production
DOCS_S3_HOST="docs.docker.com-us-east-1"
DOCS_AWS_LAMBDA="arn:aws:lambda:us-east-1:710015040892:function:docs-cache-invalidator"
DOCS_SLACK_MSG="Successfully published docs. https://docs.docker.com/"
DOCS_WEBCONFIG="_website-config-docs.json"
fi
echo "JEKYLL_ENV=$JEKYLL_ENV" >> $GITHUB_ENV
echo "DOCS_S3_HOST=$DOCS_S3_HOST" >> $GITHUB_ENV
echo "DOCS_AWS_LAMBDA=$DOCS_AWS_LAMBDA" >> $GITHUB_ENV
echo "DOCS_SLACK_MSG=$DOCS_SLACK_MSG" >> $GITHUB_ENV
echo "DOCS_WEBCONFIG=$DOCS_WEBCONFIG" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v3
@ -43,51 +22,28 @@ jobs:
uses: docker/bake-action@v2
with:
targets: release
-
name: Upload files to S3 bucket
if: github.event_name != 'pull_request'
run: |
aws --region us-east-1 s3 sync --acl public-read _site s3://${{ env.DOCS_S3_HOST }}/ --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Update S3 website config
if: github.event_name != 'pull_request'
uses: ./.github/actions/update-website-config
with:
bucketName: ${{ env.DOCS_S3_HOST }}
regionName: us-east-1
websiteConfig: ${{ env.DOCS_WEBCONFIG }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Invalidate docs website cache
if: github.event_name != 'pull_request'
run: |
aws --region us-east-1 lambda invoke --function-name ${{ env.DOCS_AWS_LAMBDA }} response.json
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Send Slack notification
if: github.event_name != 'pull_request'
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ env.DOCS_SLACK_MSG }}"}' ${{ secrets.SLACK_WEBHOOK }}
set: |
*.cache-from=type=gha,scope=build
*.cache-to=type=gha,scope=build,mode=max
validate:
runs-on: ubuntu-20.04
if: github.event_name == 'pull_request'
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Check for broken links
uses: docker/bake-action@v2
with:
targets: htmlproofer
set: |
*.cache-from=type=gha,scope=build
*.cache-from=type=gha,scope=validate
*.cache-to=type=gha,scope=validate,mode=max
# Disabled netlify-deploy due to flakey 502 http errors
# - name: copy static files

75
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,75 @@
name: publish
on:
push:
branches:
- master
- published
jobs:
publish:
runs-on: ubuntu-20.04
steps:
-
name: Prepare
run: |
JEKYLL_ENV=development
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
DOCS_S3_HOST="docs.docker.com-stage-us-east-1"
DOCS_AWS_LAMBDA="arn:aws:lambda:us-east-1:710015040892:function:docs-stage-cache-invalidator"
DOCS_SLACK_MSG="Successfully promoted docs-stage from master. https://docs-stage.docker.com/"
DOCS_WEBCONFIG="_website-config-docs-stage.json"
elif [ "${{ github.ref }}" = "refs/heads/published" ]; then
JEKYLL_ENV=production
DOCS_S3_HOST="docs.docker.com-us-east-1"
DOCS_AWS_LAMBDA="arn:aws:lambda:us-east-1:710015040892:function:docs-cache-invalidator"
DOCS_SLACK_MSG="Successfully published docs. https://docs.docker.com/"
DOCS_WEBCONFIG="_website-config-docs.json"
fi
echo "JEKYLL_ENV=$JEKYLL_ENV" >> $GITHUB_ENV
echo "DOCS_S3_HOST=$DOCS_S3_HOST" >> $GITHUB_ENV
echo "DOCS_AWS_LAMBDA=$DOCS_AWS_LAMBDA" >> $GITHUB_ENV
echo "DOCS_SLACK_MSG=$DOCS_SLACK_MSG" >> $GITHUB_ENV
echo "DOCS_WEBCONFIG=$DOCS_WEBCONFIG" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build
uses: docker/bake-action@v2
with:
targets: release
set: |
*.cache-from=type=gha,scope=publish
*.cache-to=type=gha,scope=publish,mode=max
-
name: Upload files to S3 bucket
run: |
aws --region us-east-1 s3 sync --acl public-read _site s3://${{ env.DOCS_S3_HOST }}/ --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Update S3 website config
uses: ./.github/actions/update-website-config
with:
bucketName: ${{ env.DOCS_S3_HOST }}
regionName: us-east-1
websiteConfig: ${{ env.DOCS_WEBCONFIG }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Invalidate docs website cache
run: |
aws --region us-east-1 lambda invoke --function-name ${{ env.DOCS_AWS_LAMBDA }} response.json
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Send Slack notification
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ env.DOCS_SLACK_MSG }}"}' ${{ secrets.SLACK_WEBHOOK }}