Skip to content

Commit 87f0e39

Browse files
authored
[keycloak] add configmaps & secrets to keycloak (#122)
* [keycloak] add configmaps & secrets to keycloak * [keycloak] fix keycloak pipeline yml
1 parent 8541ad9 commit 87f0e39

14 files changed

Lines changed: 2796 additions & 168 deletions

File tree

.github/workflows/keycloak-ci-cd.yml

Lines changed: 34 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,20 @@ on:
44
push:
55
paths:
66
- ".github/workflows/keycloak-ci-cd.yml"
7-
- 'server/keycloak/**'
87
- 'helm/keycloak/**'
98
workflow_dispatch:
109

1110
env:
12-
REGISTRY: ghcr.io
13-
IMAGE_NAME: server/keycloak-service
14-
WORKING_DIRECTORY: server/keycloak
15-
HELM_NAMESPACE: team-breaking-build
16-
HELM_RELEASE_NAME: recipefy-keycloak-service
17-
CHART_PATH: ./helm/keycloak-spi
11+
REGISTRY: oci://registry-1.docker.io
12+
IMAGE_NAME: bitnamicharts/keycloak
13+
NAMESPACE: recipefy
14+
RELEASE_NAME: keycloak
15+
CHART_PATH: ./helm/keycloak
16+
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
17+
SECRET_FOLDER: ./helm/keycloak/templates/secrets
18+
CONFIG_FOLDER: ./helm/keycloak/templates/configmaps
1819

1920
jobs:
20-
test:
21-
name: Test
22-
runs-on: ubuntu-latest
23-
defaults:
24-
run:
25-
working-directory: ${{ env.WORKING_DIRECTORY }}
26-
27-
steps:
28-
- name: Checkout code
29-
uses: actions/checkout@v4
30-
31-
- name: Set up JDK 21
32-
uses: actions/setup-java@v4
33-
with:
34-
java-version: '21'
35-
distribution: 'temurin'
36-
37-
- name: Run Gradle Build
38-
run: ./gradlew build --no-daemon
39-
40-
build:
41-
name: Build and Push Docker Images
42-
if: github.ref == 'refs/heads/main'
43-
runs-on: ubuntu-latest
44-
needs: test
45-
46-
steps:
47-
- name: Checkout code
48-
uses: actions/checkout@v4
49-
50-
- name: Log in to GitHub Container Registry
51-
uses: docker/login-action@v3
52-
with:
53-
registry: ${{ env.REGISTRY }}
54-
username: ${{ github.actor }}
55-
password: ${{ secrets.GITHUB_TOKEN }}
56-
57-
- name: Set up QEMU
58-
uses: docker/setup-qemu-action@v3
59-
with:
60-
platforms: all
61-
62-
- name: Set up Docker Buildx
63-
uses: docker/setup-buildx-action@v3
64-
65-
- name: Generate Docker Image Metadata
66-
id: meta
67-
uses: docker/metadata-action@v5
68-
with:
69-
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }}
70-
tags: |
71-
type=raw,value=latest,enable={{is_default_branch}}
72-
type=sha
73-
labels: |
74-
org.opencontainers.image.source=https://github.com/${{ github.repository }}
75-
76-
- name: Build and Push Docker Image
77-
uses: docker/build-push-action@v5
78-
with:
79-
context: ./${{ env.WORKING_DIRECTORY }}
80-
file: ./${{ env.WORKING_DIRECTORY }}/Dockerfile
81-
platforms: linux/amd64,linux/arm64
82-
push: true
83-
tags: ${{ steps.meta.outputs.tags }}
84-
labels: ${{ steps.meta.outputs.labels }}
85-
86-
8721
deploy:
8822
name: Deploy to Rancher with Helm
8923
if: github.ref == 'refs/heads/main'
@@ -103,7 +37,31 @@ jobs:
10337
method: kubeconfig
10438
kubeconfig: ${{ secrets.KUBE_CONFIG }}
10539

40+
- name: Set up SOPS
41+
uses: nhedger/setup-sops@v2
42+
with:
43+
version: 3.8.1
44+
45+
- name: Decrypt secret
46+
run: |
47+
sops --decrypt "$SECRET_FOLDER/auth-secret.yaml" > tmp && mv tmp "$SECRET_FOLDER/auth-secret.decrypted.yaml" && \
48+
sops --decrypt "$SECRET_FOLDER/db-secret.yaml" > tmp && mv tmp "$SECRET_FOLDER/db-secret.decrypted.yaml" && \
49+
sops --decrypt "$SECRET_FOLDER/realms-secret.yaml" > tmp && mv tmp "$SECRET_FOLDER/realms-secret.decrypted.yaml"
50+
51+
- name: Apply secret to Kubernetes
52+
run: |
53+
kubectl apply -f "$SECRET_FOLDER/auth-secret.decrypted.yaml" --namespace "$NAMESPACE" && \
54+
kubectl apply -f "$SECRET_FOLDER/db-secret.decrypted.yaml" --namespace "$NAMESPACE" && \
55+
kubectl apply -f "$SECRET_FOLDER/realms-secret.decrypted.yaml" --namespace "$NAMESPACE"
56+
57+
- name: Apply configMaps to Kubernetes
58+
run: |
59+
kubectl apply -f "$CONFIG_FOLDER/keycloak-configmaps.yaml" --namespace "$NAMESPACE" && \
60+
kubectl apply -f "$CONFIG_FOLDER/realm-import-configmaps.yaml" --namespace "$NAMESPACE"
61+
10662
- name: Deploy Helm Chart
10763
run: |
108-
helm upgrade --install ${{ env.HELM_RELEASE_NAME }} ${{ env.CHART_PATH }} \
109-
--namespace ${{ env.HELM_NAMESPACE }}
64+
helm repo add bitnami https://charts.bitnami.com/bitnami
65+
helm repo update
66+
helm upgrade ${{ env.RELEASE_NAME }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
67+
-n ${{ env.HNAMESPACE }} -f ${{ env.CHART_PATH }}/values.yaml
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: CI/CD Pipeline for Keycloak SPI
2+
3+
on:
4+
push:
5+
paths:
6+
- ".github/workflows/keycloak-service-ci-cd.yml"
7+
- 'server/keycloak/**'
8+
- 'helm/keycloak-service/**'
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: server/keycloak-service
14+
WORKING_DIRECTORY: server/keycloak
15+
NAMESPACE: recipefy
16+
RELEASE_NAME: keycloak-service
17+
CHART_PATH: ./helm/keycloak-service
18+
19+
jobs:
20+
test:
21+
name: Test
22+
runs-on: ubuntu-latest
23+
defaults:
24+
run:
25+
working-directory: ${{ env.WORKING_DIRECTORY }}
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up JDK 21
32+
uses: actions/setup-java@v4
33+
with:
34+
java-version: '21'
35+
distribution: 'temurin'
36+
37+
- name: Run Gradle Build
38+
run: ./gradlew build --no-daemon
39+
40+
build:
41+
name: Build and Push Docker Images
42+
if: github.ref == 'refs/heads/main'
43+
runs-on: ubuntu-latest
44+
needs: test
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Log in to GitHub Container Registry
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ${{ env.REGISTRY }}
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Set up QEMU
58+
uses: docker/setup-qemu-action@v3
59+
with:
60+
platforms: all
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
65+
- name: Generate Docker Image Metadata
66+
id: meta
67+
uses: docker/metadata-action@v5
68+
with:
69+
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }}
70+
tags: |
71+
type=raw,value=latest,enable={{is_default_branch}}
72+
type=sha
73+
labels: |
74+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
75+
76+
- name: Build and Push Docker Image
77+
uses: docker/build-push-action@v5
78+
with:
79+
context: ./${{ env.WORKING_DIRECTORY }}
80+
file: ./${{ env.WORKING_DIRECTORY }}/Dockerfile
81+
platforms: linux/amd64,linux/arm64
82+
push: true
83+
tags: ${{ steps.meta.outputs.tags }}
84+
labels: ${{ steps.meta.outputs.labels }}
85+
86+
87+
deploy:
88+
name: Deploy to Rancher with Helm
89+
if: github.ref == 'refs/heads/main'
90+
runs-on: ubuntu-latest
91+
needs: build
92+
93+
steps:
94+
- name: Checkout code
95+
uses: actions/checkout@v4
96+
97+
- name: Set up Helm
98+
uses: azure/setup-helm@v4
99+
100+
- name: Configure Kubernetes Context
101+
uses: azure/k8s-set-context@v4
102+
with:
103+
method: kubeconfig
104+
kubeconfig: ${{ secrets.KUBE_CONFIG }}
105+
106+
- name: Set up SOPS
107+
uses: nhedger/setup-sops@v2
108+
with:
109+
version: 3.8.1
110+
111+
- name: Decrypt secret
112+
run: |
113+
sops --decrypt "$SECRET_FILE" > tmp && mv tmp "$SECRET_FILE"
114+
115+
- name: Set image tag
116+
run: |
117+
if [ -z "$GITHUB_SHA" ]; then
118+
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
119+
else
120+
echo "IMAGE_TAG=sha-$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
121+
fi
122+
123+
- name: Deploy Helm Chart
124+
run: |
125+
helm upgrade --install ${{ env.RELEASE_NAME }} ${{ env.CHART_PATH }} \
126+
--set image.tag=${{ env.IMAGE_TAG }} \
127+
--namespace ${{ env.NAMESPACE }}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: keycloak-service-config
5+
data:
6+
KEYCLOAK_BASE_URL: 'http://keycloak:8080'

helm/keycloak/Chart.lock

Lines changed: 0 additions & 6 deletions
This file was deleted.

helm/keycloak/Chart.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

helm/keycloak/templates/_helpers.tpl

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: keycloak-config
5+
data:
6+
KEYCLOAK_DATABASE_HOST: 'postgresql-pgpool.recipefy-database.svc.cluster.local'
7+
KEYCLOAK_DATABASE_PORT: '5432'

0 commit comments

Comments
 (0)