Skip to content

Commit

Permalink
add plural bundle for kairos
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks committed Jan 8, 2025
1 parent 73df02b commit b9aed61
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
publish-docker:
name: Build and push custom image
name: Build and push bundle image
runs-on: ubuntu-20.04
permissions:
contents: 'read'
Expand All @@ -23,8 +23,8 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/pluralsh/edge
docker.io/pluralsh/edge
ghcr.io/pluralsh/kairos-plural-bundle
docker.io/pluralsh/kairos-plural-bundle
tags: |
type=sha
type=semver,pattern={{version}}
Expand All @@ -48,7 +48,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: "."
file: "./Dockerfile"
file: "./bundle.Dockerfile"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
40 changes: 40 additions & 0 deletions assets/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: plural-join
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: plural-join
subjects:
- kind: ServiceAccount
name: plural-join
namespace: default
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: Job
metadata:
name: plural-join
namespace: default
spec:
template:
spec:
containers:
- name: plural-cloud
image: "@BASE_IMAGE@"
command: ["plural"]
args: ["cd", "clusters", "bootstrap", "--project", "@PROJECT@", "--name", "@CLUSTER_NAME@", "--tag", "@TAG@"]
env:
- name: PLURAL_CONSOLE_TOKEN
value: "@TOKEN@"
- name: PLURAL_CONSOLE_URL
value: "@URL@"
restartPolicy: Never
serviceAccountName: plural-join
backoffLimit: 4
14 changes: 0 additions & 14 deletions assets/plural.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions bundle.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine as build
FROM scratch
COPY ./run.sh /
COPY ./assets /assets
File renamed without changes.
54 changes: 42 additions & 12 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ set -ex

K3S_MANIFEST_DIR=${K3S_MANIFEST_DIR:-/var/lib/rancher/k3s/server/manifests/}

# DEFAULTS
# renovate: datasource=docker depName=ghcr.io/pluralsh/plural-cli-cloud
BASE_IMAGE=ghcr.io/pluralsh/plural-cli-cloud:0.11.1
TOKEN=""
URL=""
CLUSTER_NAME="plural-edge"
PROJECT="default"
TAG="plural=edge"

getConfig() {
local l=$1
key=$(kairos-agent config get "${l}" | tr -d '\n')
Expand All @@ -13,10 +22,6 @@ getConfig() {
echo
}

# renovate: depName=metallb repoUrl=https://metallb.github.io/metallb
VERSION="0.14.9"
ADDRESS_POOL="192.168.1.10-192.168.1.20"

templ() {
local file="$3"
local value="$2"
Expand All @@ -25,13 +30,34 @@ templ() {
}

readConfig() {
_version=$(getConfig metallb.version)
if [ "$_version" != "" ]; then
VERSION=$_version
_baseImage=$(getConfig plural.baseImage)
if [ "$_baseImage" != "" ]; then
BASE_IMAGE=$_baseImage
fi

_token=$(getConfig plural.token)
if [ "$_token" != "" ]; then
TOKEN=$_token
fi

_url=$(getConfig plural.url)
if [ "$_url" != "" ]; then
URL=$_url
fi
_addresspool=$(getConfig metallb.address_pool)
if [ "$_version" != "" ]; then
ADDRESS_POOL=$_addresspool

_clusterName=$(getConfig plural.clusterName)
if [ "$_clusterName" != "" ]; then
CLUSTER_NAME=$_clusterName
fi

_project=$(getConfig plural.project)
if [ "$_project" != "" ]; then
PROJECT=$_project
fi

_tag=$(getConfig plural.tag)
if [ "$_tag" != "" ]; then
TAG=$_tag
fi
}

Expand All @@ -41,8 +67,12 @@ readConfig

# Copy manifests, and template them
for FILE in assets/*; do
templ "VERSION" "${VERSION}" "${FILE}"
templ "ADDRESS_POOL" "${ADDRESS_POOL}" "${FILE}"
templ "BASE_IMAGE" "${BASE_IMAGE}" "${FILE}"
templ "TOKEN" "${TOKEN}" "${FILE}"
templ "URL" "${URL}" "${FILE}"
templ "CLUSTER_NAME" "${CLUSTER_NAME}" "${FILE}"
templ "PROJECT" "${PROJECT}" "${FILE}"
templ "TAG" "${TAG}" "${FILE}"
done;

cp -rf assets/* "${K3S_MANIFEST_DIR}"

0 comments on commit b9aed61

Please sign in to comment.