Files
socktop-webterm/.gitea/workflows/build-and-deploy.yaml
T
jasonwitty 5637dea10b
Build and Deploy to K3s / test (push) Successful in 1m31s
Build and Deploy to K3s / lint (push) Successful in 59s
Build and Deploy to K3s / build-and-push (push) Successful in 5m40s
Build and Deploy to K3s / deploy (push) Successful in 1m9s
Gate image builds on socktop CLI compatibility; fix agent probe; caps for entrypoint
- CI now builds the image locally on the (arm64) runner and runs
  scripts/verify-image-socktop-flags.sh before pushing: every --flag the
  restricted/session shells pass must be documented by the socktop
  binary actually installed in the image. Catches the 0.3.9 failure
  class (cached apt layer shipping a pre-flag socktop) at build time.
- Manifest adds CHOWN/DAC_OVERRIDE/FOWNER alongside SETUID/SETGID:
  with ALL dropped, uid 0 has no implicit file privilege and
  prepare_demo_home crash-looped on the demo-owned 700 home dir.
  Sessions still run with zero capabilities via setpriv.
- Agent liveness probe uses /proc instead of kill -0: without CAP_KILL
  even root gets EPERM signalling the socktop-user agent, so the old
  check false-alarmed in the pod logs.
- 0.3.11

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 09:46:27 -07:00

193 lines
6.3 KiB
YAML

name: Build and Deploy to K3s
on:
push:
branches:
- main
pull_request:
branches:
- main
concurrency:
group: build-deploy-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: gt.wittyoneoff.com
IMAGE_NAME: jason/socktop-webterm
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust toolchain
run: |
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
rustup update stable
rustup default stable
- name: Run tests
run: cargo test --all-targets --all-features
env:
RUSTFLAGS: -D warnings
lint:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust toolchain
run: |
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
rustup update stable
rustup default stable
rustup component add rustfmt clippy
- name: Cargo fmt
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
build-and-push:
needs: lint
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
image_tag: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version from Cargo.toml
id: get_version
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Building version: ${VERSION}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
# Build into the runner's docker first (runner is arm64, so the image
# runs natively), gate on the CLI-compatibility check, and only then
# push. The layer cache makes the second build a no-op.
- name: Build Docker image (local, for verification)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/arm64
push: false
load: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:candidate
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
- name: Verify installed socktop understands the shells' flags
run: |
chmod +x scripts/verify-image-socktop-flags.sh
scripts/verify-image-socktop-flags.sh ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:candidate
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install kubectl
run: |
if ! command -v kubectl &> /dev/null; then
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
ARCH="arm64"
elif [ "$ARCH" = "x86_64" ]; then
ARCH="amd64"
fi
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
fi
kubectl version --client
- name: Configure kubectl
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Verify kubectl connection
run: |
kubectl get deployment socktop-webterm -n socktop || echo "Deployment will be created"
- name: Check and create/update deployment
run: |
VERSION="${{ needs.build-and-push.outputs.version }}"
# Check if deployment exists
if kubectl get deployment socktop-webterm -n socktop &> /dev/null; then
echo "Deployment exists, updating image..."
kubectl set image deployment/socktop-webterm \
webterm=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION} \
-n socktop
else
echo "Deployment does not exist, creating it..."
kubectl apply -f kubernetes/03-deployment.yaml -n socktop
# Update the image to the correct version
kubectl set image deployment/socktop-webterm \
webterm=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION} \
-n socktop
fi
- name: Wait for rollout to complete
run: |
kubectl rollout status deployment/socktop-webterm -n socktop --timeout=30m
- name: Verify deployment
run: |
kubectl get deployment socktop-webterm -n socktop
kubectl get pods -l app=socktop-webterm -n socktop
- name: Deployment summary
if: always()
run: |
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ needs.build-and-push.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-and-push.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pods Status" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
kubectl get pods -l app=socktop-webterm -n socktop >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY