diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 16ad72a..f7f145c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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' @@ -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}} @@ -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 }} diff --git a/assets/job.yaml b/assets/job.yaml new file mode 100644 index 0000000..8a4e26d --- /dev/null +++ b/assets/job.yaml @@ -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 diff --git a/assets/plural.yaml b/assets/plural.yaml deleted file mode 100644 index a9e989c..0000000 --- a/assets/plural.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: metallb-system ---- -apiVersion: helm.cattle.io/v1 -kind: HelmChart -metadata: - name: metallb - namespace: metallb-system -spec: - chart: metallb - repo: https://metallb.github.io/metallb - version: "@VERSION@" \ No newline at end of file diff --git a/bundle.Dockerfile b/bundle.Dockerfile new file mode 100644 index 0000000..a1b860b --- /dev/null +++ b/bundle.Dockerfile @@ -0,0 +1,4 @@ +FROM alpine as build +FROM scratch +COPY ./run.sh / +COPY ./assets /assets \ No newline at end of file diff --git a/Dockerfile b/cli.Dockerfile similarity index 100% rename from Dockerfile rename to cli.Dockerfile diff --git a/run.sh b/run.sh index 573bed2..f8e043f 100644 --- a/run.sh +++ b/run.sh @@ -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') @@ -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" @@ -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 } @@ -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}" \ No newline at end of file