22 Commits

Author SHA1 Message Date
40ede07ab0 v0.2.2
All checks were successful
Ruby Lint / lint (push) Successful in 27s
Ruby Test / test (push) Successful in 23s
Release / docker (push) Successful in 3m9s
2025-05-10 18:14:39 -05:00
5165759558 add JWT secret reference
Some checks failed
Ruby Lint / lint (push) Successful in 20s
Ruby Test / test (push) Successful in 24s
Release / docker (push) Has been cancelled
2025-05-10 18:13:02 -05:00
10f73b96ec refer to the session secret using the application name prefix 2025-05-10 18:12:37 -05:00
5097e551e2 just call the Kubernetes secret "kubernaut" 2025-05-10 18:10:50 -05:00
820d2d8c51 move secret related contstants to Config class
Some checks failed
Ruby Lint / lint (push) Failing after 13s
Ruby Test / test (push) Successful in 16s
2025-05-10 17:46:46 -05:00
eb5c12ca91 remove secret from Kustomize 2025-05-10 17:46:46 -05:00
2d1c9f7418 /token should provide pretty-printing
All checks were successful
Ruby Test / test (push) Successful in 18s
Ruby Lint / lint (push) Successful in 24s
2025-05-09 10:50:26 -05:00
3c2e0cdcb8 /token should provide JSON 2025-05-09 10:49:24 -05:00
66c2c3b6a2 fix undefined references to JWT_SECRET 2025-05-09 10:47:10 -05:00
b92f6688c7 add .dockerignore 2025-05-06 17:38:23 -05:00
85d00a53f6 make RUN stanza formatting consistent 2025-05-06 17:13:36 -05:00
529abe67b1 break Gitea actions up into separate files
All checks were successful
Ruby Lint / lint (push) Successful in 25s
Ruby Test / test (push) Successful in 32s
Release / docker (push) Successful in 4m3s
2025-05-06 00:58:37 -05:00
2bef46ea1b use Docker cache mount for apk
All checks were successful
Gitea Actions Demo / lint (push) Successful in 25s
Gitea Actions Demo / test (push) Successful in 13s
Gitea Actions Demo / docker (push) Successful in 3m23s
2025-05-05 22:51:18 -05:00
19d1e60d2f use Docker cache mount for Ruby bundler 2025-05-05 22:47:24 -05:00
2da770623f use Docker cache mount for Ruby gems 2025-05-05 22:46:42 -05:00
e90966970a move main ENV section in Dockerfiles 2025-05-05 22:45:52 -05:00
a54a46b0a6 use Docker cache mount for apt 2025-05-05 22:18:04 -05:00
a719e5f820 add Docker DX 2025-05-05 22:06:27 -05:00
3c4f656ec8 add Docker ARG for DEBIAN_VERSION 2025-05-02 15:37:41 -05:00
e0e6bf2507 add Docker ARG for BASE_REGISTRY 2025-05-02 15:32:26 -05:00
84908c0a24 set Debian frontend to noninteractive 2025-05-02 15:28:56 -05:00
762169f563 enable Ruby's YJIT 2025-05-02 15:27:33 -05:00
13 changed files with 140 additions and 129 deletions

View File

@ -6,7 +6,7 @@
"vscode": {
"extensions": [
"Shopify.ruby-lsp",
"ms-azuretools.vscode-docker"
"docker.docker"
]
}
},

7
.dockerignore Normal file
View File

@ -0,0 +1,7 @@
**/.git
**/.gitignore
/.devcontainer
/.gitea
/.github
/.vscode
/charts

View File

@ -0,0 +1,23 @@
---
name: Ruby Lint
on:
push:
branches:
- "**"
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Ruby Setup
uses: ruby/setup-ruby@dffc446db9ba5a0c4446edb5bca1c5c473a806c5 # v1.235.0
with:
ruby-version: '3.4'
bundler-cache: true
- name: Standard Ruby
run: bundle exec standardrb

View File

@ -1,65 +1,16 @@
---
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
name: Release
on:
schedule:
- cron: "0 10 * * *"
- cron: "0 0 * * *"
push:
branches:
- "**"
- main
tags:
- "v*.*.*"
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
permissions:
checks: write
contents: write
steps:
- name: Login to Docker
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Ruby Setup
uses: ruby/setup-ruby@dffc446db9ba5a0c4446edb5bca1c5c473a806c5 # v1.235.0
with:
ruby-version: '3.4'
bundler-cache: true
- run: bundle install
- name: Standard Ruby
run: bundle exec standardrb
test:
needs: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Test
uses: ruby/setup-ruby@dffc446db9ba5a0c4446edb5bca1c5c473a806c5 # v1.235.0
with:
ruby-version: '3.4'
bundler-cache: true
- run: bundle exec rake
docker:
needs: test
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
env:
DOCKER_ORG: ryanc
DOCKER_LATEST: latest
@ -108,7 +59,8 @@ jobs:
latest=auto
bake-target: docker-metadata-action
tags: |
type=schedule
type=schedule,pattern=nightly
type=edge
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
@ -127,7 +79,8 @@ jobs:
latest=auto
suffix=-alpine,onlatest=true
tags: |
type=schedule
type=schedule,pattern=nightly
type=edge
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}

View File

@ -0,0 +1,22 @@
---
name: Ruby Test
on:
push:
branches:
- "**"
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Test
uses: ruby/setup-ruby@dffc446db9ba5a0c4446edb5bca1c5c473a806c5 # v1.235.0
with:
ruby-version: '3.4'
bundler-cache: true
- run: bundle exec rake

14
app.rb
View File

@ -21,11 +21,9 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require "config"
VERSION = "0.2.1"
VERSION = "0.2.2"
CHUNK_SIZE = 1024**2
SESSION_SECRET_HEX_LENGTH = 64
JWT_SECRET_HEX_LENGTH = 64
DEFAULT_FLAKEY = 50
NAME = "kubernaut".freeze
@ -380,19 +378,21 @@ get "/pid", provides: "json" do
jsonify({ppid: ppid, pid: Process.pid}, pretty:)
end
get "/token" do
get "/token", provides: "json" do
pretty = params.key? :pretty
exp = Time.now.to_i + SECONDS_PER_MINUTE * 2
payload = {name: "anonymous", exp: exp, jti: Random.uuid}
expires_at = Time.at(exp).to_datetime
token = JWT.encode payload, JWT_SECRET, "HS256"
token = JWT.encode payload, config.jwt_secret.unwrap, "HS256"
x = {token: token, expires_at: expires_at}
jsonify x
jsonify x, pretty:
end
get "/token/validate" do
token = req_headers["authorization"].split[1]
payload = JWT.decode token, JWT_SECRET, true, algorithm: "HS256"
payload = JWT.decode token, config.jwt_secret.unwrap, true, algorithm: "HS256"
jsonify payload
end

View File

@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.1
version: 0.2.2
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.2.1"
appVersion: "0.2.2"

View File

@ -1,34 +1,38 @@
ARG RUBY_VERSION="3.4.3"
FROM docker.io/library/ruby:${RUBY_VERSION}-alpine AS base
WORKDIR /kubernaut
RUN <<EOT
apk update -q
apk add bash jemalloc
rm -rf /var/cache/apk
gem update --system --no-document
gem install -N bundler
EOT
ARG BASE_REGISTRY="docker.io"
FROM ${BASE_REGISTRY}/ruby:${RUBY_VERSION}-alpine AS base
ENV RACK_ENV="production" \
BUNDLE_DEPLOYMENT=true \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development test"
BUNDLE_WITHOUT="development test" \
RUBY_YJIT_ENABLE=true
WORKDIR /kubernaut
RUN \
--mount=type=cache,id=var-cache-apk,target=/var/cache/apk,sharing=locked \
apk update -q; \
apk add bash jemalloc
RUN \
--mount=type=cache,id=usr-local-bundle-cache,target=${BUNDLE_PATH},sharing=locked \
gem update --system --no-document; \
gem install -N bundler
FROM base AS build
RUN <<EOT
apk add musl-dev gcc make
rm -rf /var/cache/apk
EOT
RUN \
--mount=type=cache,id=var-cache-apk,target=/var/cache/apk,sharing=locked \
apk update -q; \
apk add musl-dev gcc make; \
apk add bash jemalloc
COPY Gemfile Gemfile.lock ./
RUN <<EOT
RUN \
--mount=type=cache,id=usr-local-bundle-ruby-cache,target=${BUNDLE_PATH}/ruby/3.4.0/cache,sharing=locked \
bundle install
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
EOT
COPY . .
@ -36,10 +40,9 @@ FROM base
ENV PORT=4567
RUN <<EOT
addgroup --system --gid 666 kubernaut
RUN \
addgroup --system --gid 666 kubernaut; \
adduser --system --uid 666 --ingroup kubernaut --shell /bin/bash --disabled-password kubernaut
EOT
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /kubernaut /kubernaut

View File

@ -1,35 +1,46 @@
ARG RUBY_VERSION="3.4.3"
FROM docker.io/library/ruby:${RUBY_VERSION}-slim-bookworm AS base
WORKDIR /kubernaut
RUN <<EOT
apt-get update -qq
apt-get install --yes --no-install-recommends libjemalloc2
rm -rf /var/lib/apt/lists /var/cache/apt/archives
gem update --system --no-document
gem install -N bundler
EOT
ARG BASE_REGISTRY="docker.io"
ARG DEBIAN_VERSION="bookworm"
FROM ${BASE_REGISTRY}/ruby:${RUBY_VERSION}-slim-${DEBIAN_VERSION} AS base
ENV RACK_ENV="production" \
BUNDLE_DEPLOYMENT=true \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development test"
BUNDLE_WITHOUT="development test" \
RUBY_YJIT_ENABLE=true
WORKDIR /kubernaut
RUN rm -f /etc/apt/apt.conf.d/docker-clean
RUN \
--mount=type=cache,id=var-cache-apt,target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=var-lib-apt,target=/var/lib/apt,sharing=locked \
apt-get update -qq; \
apt-get install --yes --no-install-recommends \
libjemalloc2
RUN \
--mount=type=cache,id=usr-local-bundle-cache,target=${BUNDLE_PATH},sharing=locked \
gem update --system --no-document; \
gem install -N bundler
ENV DEBIAN_FRONTEND="noninteractive"
FROM base AS build
RUN <<EOT
apt-get update -qq
apt-get install --yes --no-install-recommends gcc make libc-dev
rm -rf /var/lib/apt/lists /var/cache/apt/archives
EOT
RUN \
--mount=type=cache,id=var-cache-apt,target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=var-lib-apt,target=/var/lib/apt,sharing=locked \
apt-get update -qq; \
apt-get install --yes --no-install-recommends \
build-essential
COPY Gemfile Gemfile.lock ./
RUN <<EOT
RUN \
--mount=type=cache,id=usr-local-bundle-ruby-cache,target=${BUNDLE_PATH}/ruby/3.4.0/cache,sharing=locked \
bundle install
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
EOT
COPY . .
@ -37,10 +48,9 @@ FROM base
ENV PORT=4567
RUN <<EOT
groupadd --system --gid 666 kubernaut
RUN \
groupadd --system --gid 666 kubernaut; \
useradd --system --uid 666 --gid kubernaut --create-home --shell /bin/bash kubernaut
EOT
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /kubernaut /kubernaut

View File

@ -16,18 +16,24 @@ spec:
spec:
containers:
- name: kubernaut
image: git.kill0.net/ryanc/kubernaut:0.2.1
image: git.kill0.net/ryanc/kubernaut:0.2.2
imagePullPolicy: Always
ports:
- name: sinatra-web
containerPort: 4567
env:
- name: SESSION_SECRET
- name: KUBERNAUT_SESSION_SECRET
valueFrom:
secretKeyRef:
name: kubernaut-session-secret
name: kubernaut
key: session_secret
optional: true
- name: KUBERNAUT_JWT_SECRET
valueFrom:
secretKeyRef:
name: kubernaut
key: jwt_secret
optional: true
envFrom:
- configMapRef:
name: kubernaut-configmap

View File

@ -3,7 +3,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: kubernaut
resources:
- secret.yaml
- configmap.yaml
- deployment.yaml
- hpa.yaml

View File

@ -1,15 +0,0 @@
---
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
creationTimestamp: null
name: kubernaut-session-secret
namespace: kubernaut
spec:
encryptedData:
session_secret: AgCY08t0AU418znEZt5d252J+lH+fwYki2g6jdJpfdRfVQjnA+b52P0KWrs/x5pB0PKab6Z3JY/Tz0SQCaoIsCR4IzUO3a095aulRqb6Qr1Lz8udBVta4JJMZLmo26tuUfVHlpD1d6J8rkBSm8vzckFLkOA1Wfl/9rS3K4qwiDogA5pI0ULghFkeEx1yKdRwPq0k8PuvOvLUJ6oNq3e5n+B/BrVWdQ+7XQxUq/AMANJrDbe+RD33f99LArHYA7bFMbY8YRazXSTAkeunpTlxTjuGZKYvJKupo29LHz2OVbZVX/hI0nZkdVpcgqvbxF6Vw9CuCeAmtKYl7A3qsAWqDLUdP3hRLsk2P9RDNhEzYWh4ml8APzziWzihdJbGEjwLy7HsHgKslM0XbBnRQDlxp/JtvcWdjQp33A+QOON32zOKHi+qJjDYyGebS1+xkPbnyb1MPSJVAtFpj7dlLbFekLFDZEbXuJYUl1wKdFOIjJHmNK/MTEV2kOhtiVj/aeKgSXwor9hR7Uxzs5ZSawp9uWw+hpr58EX6I+RtfO4yjFC6FjnagiU6SlI1Q2F7/nv82g1UWTYMpNN5bduS1YFWmsnXvK+W7YQHpSForr5ndtCSHmclbXb5Fc33sywC5u6Bi2Gu5/MW6d73BOog5BC3QtOuEQ044Q+cuU3RIlKADBqKLzZmHlmukyyGuZfXJnGjlWGKp3J1KecucTo6XC9QHpUkjXEKdlE63mOI1VuOGyBIHl60v4bnWiBg+aDZVHipz4JLKsVB0HOgBBK7+tOX6tr1GDG/F7Nz/i9ebzUV6i8Ec1jHf+2ZcTtBkNXBIkHc84+4Qd33/gOuP+lizLfIhfQ3DFWbwyfYumpVbeapyYhB0CE=
template:
metadata:
creationTimestamp: null
name: kubernaut-session-secret
namespace: kubernaut

View File

@ -1,5 +1,8 @@
require "sensitive"
SESSION_SECRET_HEX_LENGTH = 64
JWT_SECRET_HEX_LENGTH = 64
class Config
attr_accessor :cat
@ -9,7 +12,7 @@ class Config
@prefix = prefix
@cat = cat
session_secret ||= ENV.fetch "SESSION_SECRET" do
session_secret ||= fetch_env "SESSION_SECRET" do
SecureRandom.hex SESSION_SECRET_HEX_LENGTH
end