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 name: Create and publish a Docker image
on: on:
push: workflow_call:
branches:
- main
env: env:
REGISTRY: ghcr.io REGISTRY: ghcr.io
@@ -26,20 +24,33 @@ jobs:
registry: ${{ env.REGISTRY }} registry: ${{ env.REGISTRY }}
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} 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 - name: Extract metadata (tags, labels) for Docker
id: meta id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 uses: docker/metadata-action@v5
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: | # Buildx for caching
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - uses: docker/setup-buildx-action@v3
- name: Build and push Docker image - name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 uses: docker/build-push-action@v5
with: with:
context: . context: .
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.determine_tag.outputs.tag }}
labels: ${{ steps.meta.outputs.labels }} 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: on:
push: push:
branches: branches:
- main - main
env:
IMAGE: ghcr.io/${{ github.repository }}:latest
jobs: 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 runs-on: ubuntu-latest
steps: steps:
- name: Set up git repository - name: Set up git repository
@@ -12,7 +20,7 @@ jobs:
- name: Print dependency versions - name: Print dependency versions
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ghcr.io/hendricius/the-sourdough-framework:latest image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -20,7 +28,7 @@ jobs:
- name: Print build variables - name: Print build variables
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ghcr.io/hendricius/the-sourdough-framework:latest image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -28,7 +36,23 @@ jobs:
- name: Bake the book - name: Bake the book
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: 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 options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -41,6 +65,18 @@ jobs:
aws_bucket: ${{ secrets.AWS_BUCKET_WEBSITE }} aws_bucket: ${{ secrets.AWS_BUCKET_WEBSITE }}
source_dir: website/static_website_html source_dir: website/static_website_html
destination_dir: static_html_root 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 - name: Invalidate Cloudfront website cache
uses: chetan/invalidate-cloudfront-action@v2 uses: chetan/invalidate-cloudfront-action@v2
env: 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: on:
push:
branches:
- '**' # All branches
- '!main' # But main as will do it anyway and more in release_book
pull_request: pull_request:
env:
IMAGE: ghcr.io/${{ github.repository }}:${{ github.event.pull_request.head.ref }}
jobs: 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 runs-on: ubuntu-latest
steps: steps:
- name: Set up git repository - name: Set up git repository
@@ -15,7 +19,7 @@ jobs:
- name: Print dependency versions - name: Print dependency versions
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ghcr.io/hendricius/the-sourdough-framework:latest image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -23,7 +27,7 @@ jobs:
- name: Print build variables - name: Print build variables
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ghcr.io/hendricius/the-sourdough-framework:latest image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -31,7 +35,7 @@ jobs:
- name: Test baking the release versions - name: Test baking the release versions
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ghcr.io/hendricius/the-sourdough-framework:latest image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book
@@ -39,7 +43,7 @@ jobs:
- name: Test building website - name: Test building website
uses: addnab/docker-run-action@v3 uses: addnab/docker-run-action@v3
with: with:
image: ghcr.io/hendricius/the-sourdough-framework:latest image: ${{ env.IMAGE }}
options: -v ${{ github.workspace }}:/app options: -v ${{ github.workspace }}:/app
run: | run: |
cd /app/book cd /app/book