Skip to content

docker: fix cleanup #121

docker: fix cleanup

docker: fix cleanup #121

name: Docker image
on:
schedule:
- cron: '0 1 * * *'
push:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-render-push-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
persist-credentials: false
# Collect Workflow Telemetry
- name: Collect Workflow Telemetry
uses: runforesight/workflow-telemetry-action@v1
# Free disk space
- name: Free disk space
run: |
df -h
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
docker rmi $(docker image ls -aq)
df -h
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Get current release version
id: release-version
run: |
version=$(grep -m1 -E '^Version: +' DESCRIPTION | sed -E 's/.*: +//')
echo "version=${version}" >> $GITHUB_OUTPUT
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PAT_GITHUB }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=true
type=raw,value=${{ steps.release-version.outputs.version }},enable=true
# This BUILDS the Docker image, RENDERS the book inside it, and PUSHES the image to GHCR
- name: Build and push multi-arch Docker image
uses: docker/build-push-action@v4
with:
context: .
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
platforms: linux/amd64
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ steps.release-version.outputs.version }}
outputs: type=image,annotation-index.org.opencontainers.image.description=OHCA
# Free disk space
- name: Free disk space
continue-on-error: true
run: |
df -h
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
docker system df
docker ps -s -a
docker kill $(docker ps -q -a)
docker rm $(docker ps -a -q)
docker rmi $(docker image ls -aq)
docker system df
df -h
# This (re)fetches the book from GHCR and extract the rendered book
- name: Extract OHCA book from Docker container
run: |
docker pull ghcr.io/js2264/ohca
sudo docker create --name OHCA ghcr.io/js2264/ohca
docker cp OHCA:/opt/OHCA/docs ./docs
# This DEPLOYS the book to gh-pages
- name: Deploy OHCA book to github pages
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
BRANCH: gh-pages # The branch the action should deploy to
FOLDER: docs # The folder the action should deploy
CLEAN: true # Automatically remove deleted files from the deploy branch