diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..d199e86 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,45 @@ +name: Create and publish a Docker image + +#on: +# push: +# branches: +# - main + +on: [ push, pull_request ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index f7f29a7..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Release LaTeX Document -on: - push: - branches: - - main -jobs: - build_and_release: - runs-on: ubuntu-latest - steps: - - name: Set up git repository - uses: actions/checkout@v3 - - name: Bake the book - uses: xu-cheng/texlive-action/full@v1 - with: - run: | - apk add make zip tidyhtml - wget https://archive.org/download/kindlegen_linux_2_6_i386_v2_9/kindlegen_linux_2.6_i386_v2_9.tar.gz - tar xzf kindlegen_linux_2.6_i386_v2_9.tar.gz - mv kindlegen /usr/bin - cd book - make 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: xu-cheng/texlive-action/full@v1 - with: - run: | - apk add make zip tidyhtml - make website - - name: Release baked website 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_WEBSITE }} - source_dir: book/static_website_html - destination_dir: static_html_root - - 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: - DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_WEBSITE }} - PATHS: "/*" - AWS_REGION: "us-east-1" - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/release-book.yml b/.github/workflows/release-book.yml new file mode 100644 index 0000000..5532ac1 --- /dev/null +++ b/.github/workflows/release-book.yml @@ -0,0 +1,32 @@ +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: Bake the book + uses: docker://ghcr.io/hendricius/the-sourdough-framework:latest + with: + run: | + make 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 }} diff --git a/.github/workflows/release-website.yml b/.github/workflows/release-website.yml new file mode 100644 index 0000000..250946d --- /dev/null +++ b/.github/workflows/release-website.yml @@ -0,0 +1,32 @@ +name: Release the website +on: + push: + branches: + - main +jobs: + build_and_release: + runs-on: ubuntu-latest + steps: + - name: Set up git repository + uses: actions/checkout@v3 + - name: Bake the book + uses: docker://ghcr.io/hendricius/the-sourdough-framework:latest + with: + run: | + make website + - name: Release baked website 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_WEBSITE }} + source_dir: book/static_website_html + destination_dir: static_html_root + - name: Invalidate Cloudfront website cache + uses: chetan/invalidate-cloudfront-action@v2 + env: + DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_WEBSITE }} + PATHS: "/*" + AWS_REGION: "us-east-1" + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index d3a9c34..cb9f486 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -7,12 +7,8 @@ jobs: - name: Set up git repository uses: actions/checkout@v3 - name: Test baking the release versions - uses: xu-cheng/texlive-action/full@v1 + uses: docker://ghcr.io/hendricius/the-sourdough-framework:latest with: run: | - apk add make zip tidyhtml - wget https://archive.org/download/kindlegen_linux_2_6_i386_v2_9/kindlegen_linux_2.6_i386_v2_9.tar.gz - tar xzf kindlegen_linux_2.6_i386_v2_9.tar.gz - mv kindlegen /usr/bin cd book make -j build_pdf build_serif_ebook diff --git a/Dockerfile b/Dockerfile index e8e3348..f345741 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,48 @@ -FROM ghcr.io/xu-cheng/texlive-full +FROM ubuntu:latest -WORKDIR /root +LABEL "maintainer"="Hendrik Kleinwächter " +LABEL "repository"="https://github.com/hendricius/the-sourdough-framework" +LABEL "homepage"="https://github.com/hendricius/the-sourdough-framework" +LABEL org.opencontainers.image.source="https://github.com/hendricius/the-sourdough-framework" -RUN apk add make zip tidyhtml git sudo pandoc -RUN wget https://archive.org/download/kindlegen_linux_2_6_i386_v2_9/kindlegen_linux_2.6_i386_v2_9.tar.gz -RUN tar xzf kindlegen_linux_2.6_i386_v2_9.tar.gz -RUN mv kindlegen /usr/bin -RUN git clone https://github.com/michal-h21/tex4ebook.git -WORKDIR /root/tex4ebook -RUN make -RUN make install -WORKDIR /root +# Install base depdendencies +RUN apt-get update && \ + apt-get install --yes -y --no-install-recommends \ + make \ + tidy \ + pandoc \ + zip \ + git \ + wget -WORKDIR /opt/the-sourdough-framework +# Install LaTeX +RUN apt-get install --yes -y --no-install-recommends \ + texlive-full \ + texlive-lang-all -COPY . . +# Install LaTeX extras +RUN apt-get install --yes -y --no-install-recommends \ + latexmk \ + lmodern \ + fonts-lmodern \ + tex-gyre \ + fonts-texgyre \ + dvisvgm \ + context -CMD ["/bin/sh"] +RUN apt-get autoclean && apt-get --purge --yes autoremove + +# Custom TeX packages on latest version +RUN git clone https://github.com/michal-h21/make4ht && \ + cd make4ht && \ + make justinstall SUDO="" + +RUN git clone https://github.com/michal-h21/tex4ebook.git && \ + cd tex4ebook && \ + make && \ + make install SUDO="" + +# Support to build amazon kindle books +RUN wget https://archive.org/download/kindlegen_linux_2_6_i386_v2_9/kindlegen_linux_2.6_i386_v2_9.tar.gz && \ + tar xzf kindlegen_linux_2.6_i386_v2_9.tar.gz && \ + mv kindlegen /usr/bin diff --git a/book/makefile b/book/makefile index f08873f..a527ea1 100644 --- a/book/makefile +++ b/book/makefile @@ -221,9 +221,6 @@ release_sans_serif: build_sans_serif_pdf build_sans_serif_ebook | make_release_d .PHONY: website website: - if command -v cowsay &> /dev/null; then\ - cowsay "baking the website";\ - fi rm -rf $(WEBSITE_DIR) make4ht -c website.cfg -a debug -uf html5+tidy+common_domfilters+dvisvgm_hashes -d $(WEBSITE_DIR) book.tex mv $(WEBSITE_DIR)/book.html $(WEBSITE_DIR)/index.html diff --git a/makefile b/makefile index 88e1d91..622820f 100644 --- a/makefile +++ b/makefile @@ -1,11 +1,25 @@ -PHONY: build_pdf +DOCKER_IMAGE := ghcr.io/hendricius/the-sourdough-framework + +.PHONY: build_pdf build_pdf: build_docker_image - docker run -it -v $(PWD):/opt/repo the-sourdough-framework /bin/bash -c "cd /opt/repo/book && make build_pdf" + docker run -it -v $(PWD):/opt/repo $(DOCKER_IMAGE) /bin/bash -c "cd /opt/repo/book && make" .PHONY: bake bake: build_docker_image - docker run -it -v $(PWD):/opt/repo the-sourdough-framework /bin/bash -c "cd /opt/repo/book && make bake" + docker run -it -v $(PWD):/opt/repo $(DOCKER_IMAGE) /bin/bash -c "cd /opt/repo/book && make bake" .PHONY: build_docker_image build_docker_image: - docker build -t the-sourdough-framework -f Dockerfile . + docker build -t $(DOCKER_IMAGE) -f Dockerfile --platform linux/amd64 . + +.PHONY: push_docker_image +push_docker_image: + docker push $(DOCKER_IMAGE):latest + +.PHONY: website +website: + docker run -it -v $(PWD):/opt/repo $(DOCKER_IMAGE) /bin/bash -c "cd /opt/repo/book && make website" + +.PHONY: validate +validate: + docker run -it -v $(PWD):/opt/repo $(DOCKER_IMAGE) /bin/bash -c "cd /opt/repo/book && make -j build_pdf build_serif_ebook"