Skip to content
Edit this page

Taskfile Build Image

Docker pulls

The Taskfile container runs every project with a Taskfile.

Source: https://git.taskfile.build/src/branch/main/image

Usage

Setup environment variables:

export GIT_URL="https://git.taskfile.build"
export TASK_COMMANDS="install,build-docs"
export CADDY_ROOT="site"

Run the Taskfile Build image:

run-container() {
    container_name="taskfile-build"
    image_tag="mintsystem/taskfile.build:latest"

    docker pull "$image_tag"
    docker rm -f "$container_name"
    docker volume rm "$container_name"

    echo "Open http://localhost:8080 in your browser"
    docker run -p 8080:80 -d \
        --name "$container_name" \
        -e GIT_URL="https://git.taskfile.build" \
        -e TASK_COMMANDS="install,build-docs" \
        -e CADDY_ROOT="site" \
        -v "$container_name":/app \
        "$image_tag"
}

The entrypoint.sh script of the container will clone the project from GIT_URL to /app/repo. If the project is already cloned it will pull from origin. Afterwards it runs each TASK_COMMANDS in the root of the cloned repository with the Taskfile ./task <command>. Finally, if not other command is given a Caddy webserver that serves static content from the CADDY_ROOT path is started.

SSH deploy keys

Private repos can be cloned with an SSH deploy key. The entrypoint runs add-ssh-key before the git clone.

export GIT_URL="git@github.com:Mint-System/Taskfile-Build-Demo.git"
export GIT_SSH_PRIVATE_KEY=$(cat ~/.ssh/id_ed25519 | base64 -w0)
export GIT_SSH_CONFIG="Host github.com\n  Hostname ssh.github.com\n  Port 443\n  User git"
  • GIT_SSH_PUBLIC_KEY: Public key, optional.
  • GIT_SSH_PRIVATE_KEY: Base64 encoded private key: cat ~/.ssh/id_ed25519 | base64 -w0.
  • SSH_ID_ALGORITHM: Filename of the key in ~/.ssh. Default is id_ed25519.
  • GIT_SSH_HOST: Hostname scanned into known_hosts, for example github.com.
  • GIT_SSH_CONFIG: Content of ~/.ssh/config.

Forgejo Action

The Taskfile Docker image is the perfect CI runner. It is based on node:slim and ships with these tools:

  • pnpm
  • uv
  • hugo
  • git
  • curl
  • caddy
  • kubectl
  • age
  • sops

Use the image as the workflow container:

jobs:
    deploy-docs:
        container: mintsystem/taskfile.build:latest

The image includes all common tools for building and deploying projects with a Taskfile.

Example

This example deploys a documentation site to a Kubernetes cluster. It decrypts secrets with sops and uses kubectl to restart the pods.

name: Deploy Docs
on:
    push:
        branches:
            - 'main'
        paths:
            - 'docs/**'

jobs:
    deploy-docs:
        name: Deploy Docs
        runs-on: ubuntu-latest
        container: mintsystem/taskfile.build:latest
        steps:
            - name: Decrypt secrets and create Kubeconfig
              env:
                  SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
              run: |
                  mkdir -p $HOME/.kube
                  set -a
                  eval "$(task show-dotenv secrets)"
                  set +a
                  echo "$KUBECONFIG_DEPLOY" > $HOME/.kube/config
            - name: Verify kubectl version
              run: kubectl version --client
            - name: Deploy to Kubernetes
              run: kubectl delete pods -l app=taskfile-build -n taskfile-build