From 364f5259a173a7960b19874123633d5a16616b92 Mon Sep 17 00:00:00 2001 From: Mayursinh Sarvaiya Date: Thu, 8 Feb 2024 17:54:26 -0400 Subject: [PATCH] feat: add cdk8s java support --- .github/workflows/release-java.yaml | 48 +++++++++++++++++++++++++++++ README.md | 4 +-- java/Dockerfile | 30 ++++++++++++++++++ java/README.md | 47 ++++++++++++++++++++++++++++ java/plugin.yaml | 14 +++++++++ 5 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release-java.yaml create mode 100644 java/Dockerfile create mode 100644 java/README.md create mode 100644 java/plugin.yaml diff --git a/.github/workflows/release-java.yaml b/.github/workflows/release-java.yaml new file mode 100644 index 0000000..01a456f --- /dev/null +++ b/.github/workflows/release-java.yaml @@ -0,0 +1,48 @@ +name: Create and publish a cdk8s-cmp-java Docker image + +on: + push: + tags: + - 'cdk8s-cmp-java/v*' +env: + REGISTRY: ghcr.io + ACTOR: ${{ github.actor }} + +jobs: + build-and-push-image: + env: + IMAGE_NAME: cdk8s-cmp-java + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.ACTOR }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.ACTOR }}/${{ env.IMAGE_NAME }} + tags: | + type=match,pattern=v(.*),group=1 + flavor: | + latest=auto + + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: ./java + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + github-token: ${{ secrets.GITHUB_TOKEN }} + diff --git a/README.md b/README.md index 21821c9..8fa9ab5 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ This repository contains individual and all-in-one Docker images for [cdk8s](htt 1. cdk8s Typescript 2. cdk8s Python -3. cdk8s Golang (Coming Soon) -4. cdk8s Java (Coming Soon) +3. cdk8s Golang +4. cdk8s Java 5. cdk8s with all of the above languages support (Coming Soon) Read more in README in each individual folder. diff --git a/java/Dockerfile b/java/Dockerfile new file mode 100644 index 0000000..ffb4f43 --- /dev/null +++ b/java/Dockerfile @@ -0,0 +1,30 @@ +ARG NODE_VERSION=20.11.0 +ARG CDK8S_CLI_VERSION=2.198.36 +ARG ALPINE_VERSION=3.15 + +FROM --platform=${BUILDPLATFORM} node:${NODE_VERSION}-alpine as node + +FROM alpine:${ALPINE_VERSION} + +USER root + +RUN addgroup -g 1000 argocd && \ + adduser -S -u 999 -G argocd -h /home/argocd argocd && \ + mkdir -p /home/argocd && \ + chown argocd:0 /home/argocd && \ + chmod g=u /home/argocd + +COPY --from=node /usr/lib /usr/lib +COPY --from=node /usr/local/lib /usr/local/lib +COPY --from=node /usr/local/include /usr/local/include +COPY --from=node /usr/local/bin /usr/local/bin + +RUN apk add --no-cache \ + openjdk11 \ + maven + +RUN npm install -g cdk8s-cli@${CDK8S_CLI_VERSION} + +USER argocd + +WORKDIR /home/argocd diff --git a/java/README.md b/java/README.md new file mode 100644 index 0000000..c11b376 --- /dev/null +++ b/java/README.md @@ -0,0 +1,47 @@ +# cdk8s Java CMP + +This generates kubernetes manifests using cdk8s in Java language. [Read more about cdk8s Java](https://cdk8s.io/docs/latest/get-started/java/) + +## Use-case + +When you have kubernetes manifests written in cdk8s Java and you want to turn it into raw YAML and provide ArgoCD to manage resources. + +Basically it requires 2 commands when generating raw YAML manifests + +1. Import cdk8s objects defined in cdk8s configuration YAML file and compile java + +```sh +cdk8s import && mvn compile +``` + +2. Generate manifests and print to stdout + +```sh +cdk8s synth --stdout +``` + +## Install and Use + +Register the plugin sidecar to `argocd-repo-server` + +```yaml +containers: +- name: cdk8s-java + image: ghcr.io/akuity/cdk8s-cmp-java:latest + .... +``` + +Apply [this plugin.yaml](./plugin.yaml) configuration. You can modify depending on your use-case (ie. for example injecting static or dynamic parameters). + +Use the plugin when you create an application. + +```yaml +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: guestbook +spec: + source: + plugin: + name: cdk8s-java +``` diff --git a/java/plugin.yaml b/java/plugin.yaml new file mode 100644 index 0000000..98d9181 --- /dev/null +++ b/java/plugin.yaml @@ -0,0 +1,14 @@ +apiVersion: argoproj.io/v1alpha1 +kind: ConfigManagementPlugin +metadata: + name: cdk8s-java +spec: + version: v1.0 + init: + command: [sh, -c] + args: [cdk8s import && mvn compile] + generate: + command: [cdk8s, synth] + args: [--stdout] + discover: + fileName: "pom.xml" \ No newline at end of file