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
26 changes: 21 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,33 @@ jobs:
- name: Smoke test container
shell: bash
run: |
config_repo_fixture="$(mktemp -d)"
cp -R src/test/resources/config-repo/. "${config_repo_fixture}/"
git -C "${config_repo_fixture}" init --initial-branch=main
git -C "${config_repo_fixture}" config user.name "Config Server CI"
git -C "${config_repo_fixture}" config user.email "config-server-ci@localhost"
git -C "${config_repo_fixture}" add .
git -C "${config_repo_fixture}" commit --message "Create CI configuration fixture"
chmod -R a+rwX "${config_repo_fixture}"

cleanup() {
docker rm --force config-server-ci > /dev/null 2>&1 || true
rm -rf "${config_repo_fixture}"
}
trap cleanup EXIT

docker run --detach \
--name config-server-ci \
--publish 8888:8888 \
--env CONFIG_REPO_URI=file:/platform-config \
--env CONFIG_REPO_DEFAULT_LABEL=main \
--volume "${config_repo_fixture}:/platform-config" \
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
http://localhost:8888/actuator/health/liveness > /dev/null; then
ready=true
break
fi
Expand All @@ -107,5 +123,5 @@ jobs:
fi

curl --fail --silent \
http://localhost:8888/customer-service/local \
| grep --quiet '"name":"customer-service"'
http://localhost:8888/test-service/default \
| grep --quiet '"test.message":"config-server-integration-test"'
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ RUN groupadd --gid 10001 spring \

WORKDIR /app

ENV XDG_CONFIG_HOME=/tmp/.config

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
Expand Down
75 changes: 58 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ Centralized configuration service for the Digital Bank Java platform, built with

## Configuration Model

The service currently uses the Spring Cloud Config native backend and reads configuration from the local `config-repo` directory.
The service uses the Spring Cloud Config Git backend. Client configuration is owned by the separate `platform-config` repository so configuration can change independently of the Config Server image.

### Config Server Runtime Configuration

`src/main/resources/application.yml` configures the Config Server process itself, including:

- HTTP port.
- Active Spring profile.
- Native configuration search locations.
- Git repository URI and default branch.
- Service-specific configuration search paths.
- Git authentication supplied through runtime environment variables.
- Actuator endpoint exposure.

### Client Configuration Repository

`config-repo` contains configuration served to client services:
The sibling `platform-config` repository contains configuration served to client services:

```text
config-repo/
platform-config/
├── application.yml
├── application-local.yml
└── customer-service/
Expand Down Expand Up @@ -68,7 +69,15 @@ helm version --short

## Run Locally

Run commands from the repository root so the native backend can resolve `./config-repo`.
Clone `platform-config` beside this repository. The default local repository URI is `file:../platform-config`:

```text
digital-bank-java/
├── config-server/
└── platform-config/
```

Run commands from the `config-server` repository root.

Execute the test suite:

Expand Down Expand Up @@ -116,32 +125,43 @@ curl --fail http://localhost:8888/customer-service/local
The local response combines configuration from:

```text
config-repo/customer-service/customer-service-local.yml
config-repo/application-local.yml
config-repo/customer-service/customer-service.yml
config-repo/application.yml
platform-config/customer-service/customer-service-local.yml
platform-config/application-local.yml
platform-config/customer-service/customer-service.yml
platform-config/application.yml
```

More specific profile and service configuration takes precedence over shared defaults.
More specific profile and service configuration takes precedence over shared defaults. The response `version` identifies the exact `platform-config` Git commit used.

## Run With Docker

Build the image from the repository root:

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

Run the container as a non-root user:
Create a disposable writable copy of the local configuration repository. JGit requires write access for checkout metadata, so the real working repository is not mounted directly:

```bash
CONFIG_REPO_FIXTURE="$(mktemp -d)"
cp -R ../platform-config/. "$CONFIG_REPO_FIXTURE/"
chmod -R a+rwX "$CONFIG_REPO_FIXTURE"
```

Run the container as a non-root user with the fixture mounted as its Git repository:

```bash
docker run --detach \
--rm \
--name digital-bank-java-config-server \
--publish 8888:8888 \
digital-bank-java/config-server:0.0.1
--env CONFIG_REPO_URI=file:/platform-config \
--env CONFIG_REPO_DEFAULT_LABEL=main \
--volume "$CONFIG_REPO_FIXTURE:/platform-config" \
digital-bank-java/config-server:0.0.2
```

Verify the container and stop it:
Expand All @@ -150,9 +170,11 @@ Verify the container and stop it:
curl --fail http://localhost:8888/actuator/health
curl --fail http://localhost:8888/customer-service/local
docker stop digital-bank-java-config-server
test -n "$CONFIG_REPO_FIXTURE" && rm -rf "$CONFIG_REPO_FIXTURE"
unset CONFIG_REPO_FIXTURE
```

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.
The runtime image uses the numeric non-root user `10001:10001`. Client configuration and credentials are not included in the image.

## Deploy To Local SIT

Expand All @@ -172,6 +194,24 @@ helm template config-server helm |
kubectl apply --dry-run=client -f -
```

Create the namespace and an opaque Secret containing a repository-scoped, read-only GitHub credential. Never commit the token or place it in Helm values:

```bash
kubectl create namespace digital-bank-sit --dry-run=client -o yaml |
kubectl apply -f -

read -s CONFIG_REPO_TOKEN
printf %s "$CONFIG_REPO_TOKEN" |
kubectl create secret generic config-server-git-credentials \
--namespace digital-bank-sit \
--from-literal=username=YOUR_GITHUB_USERNAME \
--from-file=token=/dev/stdin \
--dry-run=client \
--output yaml |
kubectl apply -f -
unset CONFIG_REPO_TOKEN
```

Install or upgrade the release in the SIT namespace:

```bash
Expand Down Expand Up @@ -216,22 +256,23 @@ The Kubernetes deployment:
- 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.
- Reads Git credentials from an existing Kubernetes Secret rather than Helm values.

## 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.
- Build the container image and smoke-test it against a disposable Git repository fixture.

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.
Configuration is promoted independently through the dedicated Git-backed `platform-config` repository. Secrets must remain outside Git and Helm values and be supplied through the environment's approved secret-management integration. AWS environments will replace the manually created SIT Secret with managed secret delivery and rotation.

## Development Workflow

Expand Down
4 changes: 0 additions & 4 deletions config-repo/application-local.yml

This file was deleted.

3 changes: 0 additions & 3 deletions config-repo/application.yml

This file was deleted.

3 changes: 0 additions & 3 deletions config-repo/customer-service/customer-service-local.yml

This file was deleted.

11 changes: 0 additions & 11 deletions config-repo/customer-service/customer-service.yml

This file was deleted.

15 changes: 15 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ spec:
- name: {{ include "config-server.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: CONFIG_REPO_URI
value: {{ .Values.configRepository.uri | quote }}
- name: CONFIG_REPO_DEFAULT_LABEL
value: {{ .Values.configRepository.defaultLabel | quote }}
- name: CONFIG_REPO_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.configRepository.credentialsSecret.name }}
key: {{ .Values.configRepository.credentialsSecret.usernameKey }}
- name: CONFIG_REPO_TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.configRepository.credentialsSecret.name }}
key: {{ .Values.configRepository.credentialsSecret.tokenKey }}
securityContext:
{{- toYaml .Values.containerSecurityContext | nindent 12 }}
ports:
Expand Down
12 changes: 10 additions & 2 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ revisionHistoryLimit: 3

image:
repository: digital-bank-java/config-server
tag: "0.0.1"
tag: "0.0.2"
pullPolicy: IfNotPresent

configRepository:
uri: https://github.com/digital-bank-java/platform-config.git
defaultLabel: main
credentialsSecret:
name: config-server-git-credentials
usernameKey: username
tokenKey: token

service:
type: ClusterIP
port: 8888
Expand All @@ -22,7 +30,7 @@ resources:

probes:
startup:
path: /actuator/health
path: /actuator/health/liveness
failureThreshold: 30
periodSeconds: 5
liveness:
Expand Down
25 changes: 19 additions & 6 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ server:
spring:
application:
name: config-server
profiles:
active: native
cloud:
config:
server:
native:
search-locations:
- file:./config-repo
- file:./config-repo/{application}
accept-empty: false
git:
uri: "${CONFIG_REPO_URI:file:../platform-config}"
default-label: "${CONFIG_REPO_DEFAULT_LABEL:main}"
try-master-branch: false
search-paths:
- "{application}"
clone-on-start: true
force-pull: true
delete-untracked-branches: true
timeout: 10
username: "${CONFIG_REPO_USERNAME:}"
password: "${CONFIG_REPO_TOKEN:}"
health:
repositories:
platform-config:
name: customer-service
profiles: local
label: "${CONFIG_REPO_DEFAULT_LABEL:main}"

management:
endpoints:
Expand Down
Loading