Skip to content

Commit

Permalink
feat: add cdk8s java support
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin9 committed Feb 8, 2024
1 parent f6f942f commit 364f525
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 2 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/release-java.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions java/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -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
```
14 changes: 14 additions & 0 deletions java/plugin.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 364f525

Please sign in to comment.