From ef3dd4f81c738ddd8a8c55ea4c2a26ce2174fdf3 Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Mon, 13 Jul 2026 21:11:42 -0300 Subject: [PATCH] adding build images --- .gitea/workflows/build-images.yaml | 49 +++++++++++++++++++++++++ deploy-restart/action.yaml | 57 ++++++++++++++++++++++++++++-- images/full/Dockerfile | 40 +++++++++++++++++++++ images/slim/Dockerfile | 22 ++++++++++++ kubectl-apply/action.yaml | 57 ++++++++++++++++++++++++++++-- 5 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 .gitea/workflows/build-images.yaml create mode 100644 images/full/Dockerfile create mode 100644 images/slim/Dockerfile diff --git a/.gitea/workflows/build-images.yaml b/.gitea/workflows/build-images.yaml new file mode 100644 index 0000000..daca121 --- /dev/null +++ b/.gitea/workflows/build-images.yaml @@ -0,0 +1,49 @@ +name: Build and Push Runner Images + +on: + push: + branches: + - main + paths: + - 'images/**' + - '.gitea/workflows/build-images.yaml' + workflow_dispatch: {} + +env: + SLIM_IMAGE: git.ivanch.me/ivanch/runner-images + FULL_IMAGE: git.ivanch.me/ivanch/runner-images + +jobs: + build-slim: + name: Build Slim Runner Image + runs-on: ubuntu-amd64 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Build and push slim image + uses: https://git.ivanch.me/ivanch/pipeline-actions/build-and-push@main + with: + image: ${{ env.SLIM_IMAGE }} + image_tag: slim + build_context: images/slim + build_dockerfile: Dockerfile + registry_password: ${{ secrets.REGISTRY_PASSWORD }} + ssh_key: ${{ secrets.SSH_KEY_DOCKERBUILD }} + + build-full: + name: Build Full Runner Image + runs-on: ubuntu-amd64 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Build and push full image + uses: https://git.ivanch.me/ivanch/pipeline-actions/build-and-push@main + with: + image: ${{ env.FULL_IMAGE }} + image_tag: full + build_context: images/full + build_dockerfile: Dockerfile + registry_password: ${{ secrets.REGISTRY_PASSWORD }} + ssh_key: ${{ secrets.SSH_KEY_DOCKERBUILD }} diff --git a/deploy-restart/action.yaml b/deploy-restart/action.yaml index 624dd49..4a528ea 100644 --- a/deploy-restart/action.yaml +++ b/deploy-restart/action.yaml @@ -38,15 +38,66 @@ runs: env: KUBE_VERSION: ${{ inputs.kube_version }} run: | - apt-get update -y - apt-get install -y curl + # strip stray CR (CRLF checkout via core.autocrlf) + KUBE_VERSION=$(printf '%s' "${KUBE_VERSION}" | tr -d '\r') + + # 1. Check if kubectl is already pre-installed and meets version requirements + if command -v kubectl &> /dev/null; then + INSTALLED_VER=$(kubectl version --client --output=json 2>/dev/null | grep -oE '"gitVersion": "[^"]+"' | cut -d'"' -f4) + if [ -z "${INSTALLED_VER}" ]; then + INSTALLED_VER=$(kubectl version --client 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+') + fi + echo "Found pre-installed kubectl version: ${INSTALLED_VER}" + + # If stable or version matches, reuse pre-installed kubectl + if [ "${KUBE_VERSION}" = "stable" ] || [ "${INSTALLED_VER}" = "${KUBE_VERSION}" ]; then + echo "Using pre-installed kubectl." + exit 0 + fi + fi + + # 2. Check/install curl if missing + if ! command -v curl &> /dev/null; then + echo "curl not found, attempting to install..." + if command -v apt-get &> /dev/null; then + apt-get update -y && apt-get install -y curl + elif command -v apk &> /dev/null; then + apk add --no-cache curl + elif command -v dnf &> /dev/null; then + dnf install -y curl + elif command -v yum &> /dev/null; then + yum install -y curl + else + echo "::error::curl is missing and no supported package manager (apt-get, apk, dnf, yum) was found." + exit 1 + fi + fi + + # 3. Resolve version if [ "${KUBE_VERSION}" = "stable" ]; then KUBE_VER="$(curl -L -s https://dl.k8s.io/release/stable.txt)" else KUBE_VER="${KUBE_VERSION}" fi + + # 4. Download kubectl + echo "Downloading kubectl version ${KUBE_VER}..." curl -LO "https://dl.k8s.io/release/${KUBE_VER}/bin/linux/amd64/kubectl" - install -m 0755 kubectl /usr/local/bin/kubectl + + # 5. Install kubectl to a writable directory + if [ -w "/usr/local/bin" ]; then + install -m 0755 kubectl /usr/local/bin/kubectl + echo "Installed kubectl to /usr/local/bin" + else + echo "/usr/local/bin is not writable. Installing locally and updating PATH..." + LOCAL_BIN="${HOME}/.local/bin" + mkdir -p "${LOCAL_BIN}" + install -m 0755 kubectl "${LOCAL_BIN}/kubectl" + echo "${LOCAL_BIN}" >> "$GITHUB_PATH" + export PATH="${LOCAL_BIN}:${PATH}" + echo "Installed kubectl to ${LOCAL_BIN}" + fi + kubectl version --client - name: Set up kubeconfig diff --git a/images/full/Dockerfile b/images/full/Dockerfile new file mode 100644 index 0000000..9dd9658 --- /dev/null +++ b/images/full/Dockerfile @@ -0,0 +1,40 @@ +FROM ubuntu:24.04 + +ENV DEBIAN_FRONTEND=noninteractive + +ARG TARGETARCH + +# Install base tools, Docker, and utilities +RUN apt-get update && apt-get install -y \ + bash \ + curl \ + wget \ + git \ + openssh-client \ + ca-certificates \ + tar \ + gzip \ + unzip \ + zip \ + jq \ + rsync \ + gettext-base \ + make \ + build-essential \ + docker.io \ + docker-buildx \ + docker-compose-v2 \ + && rm -rf /var/lib/apt/lists/* + +# Download and install kubectl matching the target architecture +RUN KUBE_VER=$(curl -L -s https://dl.k8s.io/release/stable.txt) && \ + curl -LO "https://dl.k8s.io/release/${KUBE_VER}/bin/linux/${TARGETARCH}/kubectl" && \ + install -m 0755 kubectl /usr/local/bin/kubectl && \ + rm kubectl + +# Install yq (Go-based binary) +RUN YQ_VER="v4.44.1" && \ + curl -Lo /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VER}/yq_linux_${TARGETARCH}" && \ + chmod +x /usr/local/bin/yq + +CMD ["/bin/bash"] diff --git a/images/slim/Dockerfile b/images/slim/Dockerfile new file mode 100644 index 0000000..b351820 --- /dev/null +++ b/images/slim/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:3.20 + +ARG TARGETARCH + +# Install required packages +RUN apk add --no-cache \ + bash \ + curl \ + wget \ + git \ + openssh-client \ + ca-certificates \ + tar \ + gzip + +# Download and install kubectl matching the target architecture +RUN KUBE_VER=$(curl -L -s https://dl.k8s.io/release/stable.txt) && \ + curl -LO "https://dl.k8s.io/release/${KUBE_VER}/bin/linux/${TARGETARCH}/kubectl" && \ + install -m 0755 kubectl /usr/local/bin/kubectl && \ + rm kubectl + +CMD ["/bin/bash"] diff --git a/kubectl-apply/action.yaml b/kubectl-apply/action.yaml index d713c5d..4eb4a8e 100644 --- a/kubectl-apply/action.yaml +++ b/kubectl-apply/action.yaml @@ -47,15 +47,66 @@ runs: env: KUBE_VERSION: ${{ inputs.kube_version }} run: | - apt-get update -y - apt-get install -y curl + # strip stray CR (CRLF checkout via core.autocrlf) + KUBE_VERSION=$(printf '%s' "${KUBE_VERSION}" | tr -d '\r') + + # 1. Check if kubectl is already pre-installed and meets version requirements + if command -v kubectl &> /dev/null; then + INSTALLED_VER=$(kubectl version --client --output=json 2>/dev/null | grep -oE '"gitVersion": "[^"]+"' | cut -d'"' -f4) + if [ -z "${INSTALLED_VER}" ]; then + INSTALLED_VER=$(kubectl version --client 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+') + fi + echo "Found pre-installed kubectl version: ${INSTALLED_VER}" + + # If stable or version matches, reuse pre-installed kubectl + if [ "${KUBE_VERSION}" = "stable" ] || [ "${INSTALLED_VER}" = "${KUBE_VERSION}" ]; then + echo "Using pre-installed kubectl." + exit 0 + fi + fi + + # 2. Check/install curl if missing + if ! command -v curl &> /dev/null; then + echo "curl not found, attempting to install..." + if command -v apt-get &> /dev/null; then + apt-get update -y && apt-get install -y curl + elif command -v apk &> /dev/null; then + apk add --no-cache curl + elif command -v dnf &> /dev/null; then + dnf install -y curl + elif command -v yum &> /dev/null; then + yum install -y curl + else + echo "::error::curl is missing and no supported package manager (apt-get, apk, dnf, yum) was found." + exit 1 + fi + fi + + # 3. Resolve version if [ "${KUBE_VERSION}" = "stable" ]; then KUBE_VER="$(curl -L -s https://dl.k8s.io/release/stable.txt)" else KUBE_VER="${KUBE_VERSION}" fi + + # 4. Download kubectl + echo "Downloading kubectl version ${KUBE_VER}..." curl -LO "https://dl.k8s.io/release/${KUBE_VER}/bin/linux/amd64/kubectl" - install -m 0755 kubectl /usr/local/bin/kubectl + + # 5. Install kubectl to a writable directory + if [ -w "/usr/local/bin" ]; then + install -m 0755 kubectl /usr/local/bin/kubectl + echo "Installed kubectl to /usr/local/bin" + else + echo "/usr/local/bin is not writable. Installing locally and updating PATH..." + LOCAL_BIN="${HOME}/.local/bin" + mkdir -p "${LOCAL_BIN}" + install -m 0755 kubectl "${LOCAL_BIN}/kubectl" + echo "${LOCAL_BIN}" >> "$GITHUB_PATH" + export PATH="${LOCAL_BIN}:${PATH}" + echo "Installed kubectl to ${LOCAL_BIN}" + fi + kubectl version --client - name: Set up kubeconfig