Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target/
.git/
.github/
.settings/
.classpath
.project
.sts4-cache/
.idea/
.vscode/
.DS_Store
README.md
111 changes: 111 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: CI

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Maven verification
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Set up Java
uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0
with:
distribution: temurin
java-version: "21"
cache: maven

- name: Verify application
run: ./mvnw --batch-mode --no-transfer-progress verify

helm:
name: Helm validation
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Set up Helm
uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
with:
version: v4.2.0

- name: Lint chart
run: helm lint helm --strict

- name: Render chart
run: |
helm template config-server helm \
--set image.tag="${GITHUB_SHA}" \
> rendered.yaml
test -s rendered.yaml
container:
name: Container build and smoke test
needs:
- test
- helm
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0

- name: Build container image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
load: true
push: false
tags: digital-bank-java/config-server:ci
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Smoke test container
shell: bash
run: |
docker run --detach \
--name config-server-ci \
--publish 8888:8888 \
digital-bank-java/config-server:ci

trap 'docker rm --force config-server-ci' EXIT

ready=false
for attempt in {1..30}; do
if curl --fail --silent \
http://localhost:8888/actuator/health > /dev/null; then
ready=true
break
fi
sleep 2
done

if [[ "${ready}" != "true" ]]; then
docker logs config-server-ci
exit 1
fi

curl --fail --silent \
http://localhost:8888/customer-service/local \
| grep --quiet '"name":"customer-service"'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HELP.md
.DS_Store
target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
Expand Down
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM eclipse-temurin:21-jdk-jammy AS builder

WORKDIR /workspace

COPY .mvn/ .mvn/
COPY mvnw pom.xml ./
RUN chmod +x mvnw && ./mvnw --batch-mode dependency:go-offline

COPY src/ src/
RUN ./mvnw --batch-mode clean package

FROM eclipse-temurin:21-jre-jammy

RUN groupadd --gid 10001 spring \
&& useradd --uid 10001 --gid spring --no-create-home \
--shell /usr/sbin/nologin spring

WORKDIR /app

COPY --from=builder --chown=10001:10001 \
/workspace/target/config-server-*.jar app.jar

COPY --chown=10001:10001 config-repo/ config-repo/

USER 10001:10001

EXPOSE 8888

ENTRYPOINT ["java", "-jar", "app.jar"]
117 changes: 116 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ config-repo/
- Java 21.
- Git.
- Network access to Maven Central for the initial dependency download.
- Docker Desktop for container builds.
- Docker Desktop Kubernetes and Helm 4 for the local SIT deployment.

A global Maven installation is not required because the repository includes the Maven Wrapper.

Expand All @@ -59,6 +61,9 @@ Verify the environment:
```bash
java -version
./mvnw --version
docker version
kubectl config current-context
helm version --short
```

## Run Locally
Expand Down Expand Up @@ -119,6 +124,115 @@ config-repo/application.yml

More specific profile and service configuration takes precedence over shared defaults.

## Run With Docker

Build the image from the repository root:

```bash
docker build \
--tag digital-bank-java/config-server:0.0.1 \
.
```

Run the container as a non-root user:

```bash
docker run --detach \
--rm \
--name digital-bank-java-config-server \
--publish 8888:8888 \
digital-bank-java/config-server:0.0.1
```

Verify the container and stop it:

```bash
curl --fail http://localhost:8888/actuator/health
curl --fail http://localhost:8888/customer-service/local
docker stop digital-bank-java-config-server
```

The runtime image uses the numeric non-root user `10001:10001`. The native `config-repo` directory is included in the image only for the current local configuration phase.

## Deploy To Local SIT

The Helm chart deploys Config Server to Docker Desktop Kubernetes. Confirm that the active context is `docker-desktop` before continuing:

```bash
kubectl config current-context
kubectl get nodes
```

Validate the chart without changing the cluster:

```bash
helm lint helm

helm template config-server helm |
kubectl apply --dry-run=client -f -
```

Install or upgrade the release in the SIT namespace:

```bash
helm upgrade --install config-server helm \
--namespace digital-bank-sit \
--create-namespace \
--wait \
--timeout 5m
```

Inspect the release:

```bash
helm status config-server --namespace digital-bank-sit
kubectl get deployment,pods,service --namespace digital-bank-sit
kubectl logs deployment/config-server --namespace digital-bank-sit
```

Forward the internal Kubernetes Service to the workstation:

```bash
kubectl port-forward \
service/config-server 8888:8888 \
--namespace digital-bank-sit
```

While port forwarding is active, run the health and configuration requests from another terminal. Stop port forwarding with `Ctrl+C`.

Remove only this Helm release when cleanup is required:

```bash
helm uninstall config-server --namespace digital-bank-sit
```

## Deployment Security

The Kubernetes deployment:

- Runs as numeric non-root user and group `10001`.
- Disables privilege escalation.
- Drops Linux capabilities.
- Uses a read-only root filesystem with bounded temporary storage.
- Does not mount the default Kubernetes service account token.
- Exposes Config Server only through an internal `ClusterIP` Service.

## CI Validation

Pull requests and changes to `main` run independent CI jobs that:

- Execute Maven verification with Java 21.
- Lint and render the Helm chart with Helm 4.2.0.
- Build the container image and smoke-test its health and configuration endpoints.

Third-party GitHub Actions are pinned to immutable commit SHAs.

## Environment Promotion

The same container and Helm chart are intended to move through SIT, UAT, and PROD without application rebuilds. Hosted environments will provide environment-specific image repositories, immutable image tags, resource sizing, and infrastructure configuration through the deployment pipeline.

The current native configuration backend is suitable for local development and SIT bootstrap. Migration to the dedicated Git-backed `platform-config` repository is required before the hosted UAT and PROD deployment. Secrets must remain outside Git and Helm values and be supplied through the environment's approved secret-management integration.

## Development Workflow

Changes must be made on a dedicated branch and merged through a pull request. Do not commit directly to `main`.
Expand All @@ -135,7 +249,8 @@ Before opening a pull request:

```bash
git status
./mvnw test
./mvnw verify
helm lint helm --strict
git diff --check
```

Expand Down
6 changes: 6 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: config-server
description: Helm chart for the Digital Bank Java Config Server
type: application
version: 0.1.0
appVersion: "0.0.1"
29 changes: 29 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- define "config-server.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "config-server.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{- define "config-server.selectorLabels" -}}
app.kubernetes.io/name: {{ include "config-server.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "config-server.labels" -}}
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" }}
{{ include "config-server.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: digital-bank-java
{{- end }}
Loading