Build docker image for each PR (#300)

This builds a docker image for each PR and then one for the release
tagged as :latest.
This commit is contained in:
Hendrik Kleinwaechter
2023-12-10 00:04:32 +01:00
committed by GitHub
parent 354737861f
commit bce4f84040
4 changed files with 76 additions and 76 deletions

View File

@@ -1,9 +1,7 @@
name: Create and publish a Docker image
on:
push:
branches:
- main
workflow_call:
env:
REGISTRY: ghcr.io
@@ -26,20 +24,33 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Figure out branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Determine docker image tag
shell: bash
id: determine_tag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "tag=${{ steps.extract_branch.outputs.branch }}" >> $GITHUB_OUTPUT
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
# Buildx for caching
- uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.determine_tag.outputs.tag }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -1,10 +1,18 @@
name: Release the website
name: Release the book and website
on:
push:
branches:
- main
env:
IMAGE: ghcr.io/${{ github.repository }}:latest
jobs:
build_and_release:
build-and-push-image:
uses: ./.github/workflows/docker-build-push.yml
release-book-website:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: Set up git repository
@@ -12,7 +20,7 @@ jobs:
- name: Print dependency versions
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
@@ -20,7 +28,7 @@ jobs:
- name: Print build variables
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
@@ -28,7 +36,23 @@ jobs:
- name: Bake the book
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
make -j bake
- name: Release baked book to S3
uses: shallwefootball/s3-upload-action@master
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: ${{ secrets.AWS_BUCKET_BOOK }}
source_dir: book/release
destination_dir: release
- name: Bake the website
uses: addnab/docker-run-action@v3
with:
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
@@ -41,6 +65,18 @@ jobs:
aws_bucket: ${{ secrets.AWS_BUCKET_WEBSITE }}
source_dir: website/static_website_html
destination_dir: static_html_root
invalidate-book-website-cache:
needs: release-book-website
runs-on: ubuntu-latest
steps:
- name: Invalidate Cloudfront book cache
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_BOOK }}
PATHS: "/*"
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Invalidate Cloudfront website cache
uses: chetan/invalidate-cloudfront-action@v2
env:

View File

@@ -1,51 +0,0 @@
name: Release the book
on:
push:
branches:
- main
jobs:
build_and_release:
runs-on: ubuntu-latest
steps:
- name: Set up git repository
uses: actions/checkout@v3
- name: Print dependency versions
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
make show_tools_version
- name: Print build variables
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
make printvars
- name: Bake the book
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
make -j bake
- name: Release baked book to S3
uses: shallwefootball/s3-upload-action@master
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: ${{ secrets.AWS_BUCKET_BOOK }}
source_dir: book/release
destination_dir: release
- name: Invalidate Cloudfront book cache
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_BOOK }}
PATHS: "/*"
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

View File

@@ -1,13 +1,17 @@
name: Validate LaTeX Document
name: Test building book and website
on:
push:
branches:
- '**' # All branches
- '!main' # But main as will do it anyway and more in release_book
pull_request:
env:
IMAGE: ghcr.io/${{ github.repository }}:${{ github.event.pull_request.head.ref }}
jobs:
test_building_book:
build-and-push-image:
uses: ./.github/workflows/docker-build-push.yml
test-building-book-website:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: Set up git repository
@@ -15,7 +19,7 @@ jobs:
- name: Print dependency versions
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
@@ -23,7 +27,7 @@ jobs:
- name: Print build variables
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
@@ -31,7 +35,7 @@ jobs:
- name: Test baking the release versions
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book
@@ -39,7 +43,7 @@ jobs:
- name: Test building website
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/hendricius/the-sourdough-framework:latest
image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app
run: |
cd /app/book