Skip to content

Commit d3ba430

Browse files
committed
feat: Prepare the keycloak federation test
1 parent 278d28c commit d3ba430

File tree

3 files changed

+138
-2
lines changed

3 files changed

+138
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Push Keycloak Service Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'tools/keycloak.Dockerfile' # Trigger build only when Dockerfile changes
9+
workflow_dispatch: # Allows manual trigger
10+
11+
jobs:
12+
build_and_push:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Log in to Docker Hub (or GHCR)
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: gtema
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Build and push Keycloak image
26+
uses: docker/build-push-action@v6
27+
with:
28+
context: .
29+
file: tools/keycloak.Dockerfile
30+
push: true
31+
tags: |
32+
ghcr.io/gtema/keycloak-ci-service:latest@26.2
33+
ghcr.io/gtema/keycloak-ci-service:${{ github.sha }}

.github/workflows/functional.yml

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ on:
1212
- 'src/'
1313

1414
jobs:
15-
test:
16-
name: interop
15+
interop:
1716
runs-on: ubuntu-latest
1817
services:
1918
postgres:
@@ -148,3 +147,105 @@ jobs:
148147
- name: Dump rust keystone log
149148
if: failure()
150149
run: cat rust.log
150+
151+
federation:
152+
runs-on: ubuntu-latest
153+
services:
154+
postgres:
155+
image: postgres:17
156+
env:
157+
POSTGRES_USER: keystone
158+
POSTGRES_PASSWORD: '1234'
159+
ports:
160+
- 5432:5432
161+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
162+
keycloak:
163+
image: ghcr.io/gtema/keycloak-ci-service:26.2
164+
env:
165+
KC_BOOTSTRAP_ADMIN_USERNAME: admin
166+
KC_BOOTSTRAP_ADMIN_PASSWORD: password
167+
ports:
168+
- 8082:8080
169+
command: start-dev
170+
steps:
171+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
172+
173+
- name: Enable cache
174+
uses: actions/cache@v4
175+
with:
176+
path: |
177+
~/.cache/pip
178+
~/.cargo
179+
key: ${{ runner.os }}-integration
180+
181+
- name: Rust Cache
182+
uses: swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
183+
184+
- uses: actions/setup-python@v5
185+
with:
186+
python-version: '3.12'
187+
188+
- name: Install Rust
189+
uses: dtolnay/rust-toolchain@888c2e1ea69ab0d4330cbf0af1ecc7b68f368cc1 # stable
190+
with:
191+
toolchain: stable
192+
193+
- name: Install sea-orm-cli
194+
run: cargo install sea-orm-cli@1.1.0
195+
196+
- name: Install necessary python packages
197+
run: pip install keystone uwsgi psycopg2
198+
199+
- name: Install osc
200+
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/gtema/openstack/releases/latest/download/openstack_cli-installer.sh | sh
201+
202+
- name: Prepare keystone config file
203+
run: |
204+
mkdir -p etc
205+
echo "[database]" >> etc/keystone.conf
206+
echo "connection = postgresql://keystone:1234@127.0.0.1:5432/keystone" >> etc/keystone.conf
207+
echo "[fernet_receipts]" >> etc/keystone.conf
208+
echo "key_repository = $(pwd)/etc/fernet" >> etc/keystone.conf
209+
echo "[fernet_tokens]" >> etc/keystone.conf
210+
echo "key_repository = $(pwd)/etc/fernet" >> etc/keystone.conf
211+
cat etc/keystone.conf
212+
213+
- name: Init keystone
214+
env:
215+
OS_KEYSTONE_CONFIG_DIR: ${{ github.workspace }}/etc
216+
run: |
217+
mkdir -p etc/fernet
218+
keystone-manage --config-file etc/keystone.conf db_sync
219+
keystone-manage --config-file etc/keystone.conf fernet_setup
220+
keystone-manage --config-file etc/keystone.conf bootstrap --bootstrap-password password
221+
222+
- name: Apply DB changes
223+
env:
224+
DATABASE_URL: postgresql://keystone:1234@127.0.0.1:5432/keystone
225+
run: sea-orm-cli migrate up
226+
227+
- name: Create client in keycloak
228+
env:
229+
KEYCLOAK_URL: "http://localhost:8082"
230+
REALM_NAME: "master"
231+
ADMIN_USERNAME: "admin"
232+
ADMIN_PASSWORD: "password"
233+
TOKEN_ENDPOINT: "http://localhost:8082/realms/master/protocol/openid-connect/token"
234+
CLIENT_ID: "keystone"
235+
CLIENT_SECRET: "keystone-secret"
236+
run: |
237+
# Get the access token
238+
ACCESS_TOKEN=$(curl -s -X POST \
239+
-d "client_id=admin-cli" \
240+
-d "username=${ADMIN_USERNAME}" \
241+
-d "password=${ADMIN_PASSWORD}" \
242+
-d "grant_type=password" \
243+
"${KEYCLOAK_URL}/realms/${REALM_NAME}/protocol/openid-connect/token" | jq -r '.access_token') # Using 'jq -r .access_token' to parse the JSON and get the raw token
244+
245+
if [ -z "$ACCESS_TOKEN" ]; then
246+
echo "Failed to obtain access token. Check your Keycloak URL, credentials, and realm."
247+
exit 1
248+
fi
249+
250+
# Create the client
251+
curl "${KEYCLOAK_URL}/realms/${REALM_NAME}/clients" -H "Authorization: Bearer ${ACCESS_TOKEN}" -X POST -H "Content-Type: application/json" -d '{"clientId":"{CLIENT_ID}", "secret": "${CLIENT_SECRET}", "redirectUris": ["http://localhost:8050/*"], "enabled":true}'

tools/Dockerfile.keycloak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM quay.io/keycloak/keycloak:26.2
2+
CMD ["start-dev"]

0 commit comments

Comments
 (0)