Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using keycloak as gitlab-ci service

I am trying to run my integration tests in gitlab-ci versus a keycloak instance started via a service. gitlab-ci yaml configuration can be found over here: https://gitlab.com/viae-modules/viae-modules/-/blob/master/.gitlab-ci.yml

services:
  - docker:dind
  - name: mongo:latest
    alias: mongodb
  - name: jboss/keycloak:10.0.1
    alias: sso
    command: ["-b", "0.0.0.0"]

Now I can't connect to this instance. I added some curl commands to validate the connection, but there I see something strange happening:

going to http://sso:8080 gives the following (keycloak) response

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
     <meta http-equiv="refresh" content="0; url=/auth/" />
     <meta name="robots" content="noindex, nofollow">
     <script type="text/javascript">
         window.location.href = "/auth/"
     </script>
 </head>
 <body>
     If you are not redirected automatically, follow this <a href='/auth'>link</a>.
 </body>
 </html>

which means that keycloak is up and running. Then, connecting to http://sso:8080/auth gives a 404...

I would expect that this was due to not binding to 0.0.0.0, but I did this in the service configuration.

I assume this has something to do with the gitlab configuration/runner as the following image is responding in a dockerized environment (i.e. not related to docker options/configurations of the base image):

FROM jboss/keycloak:10.0.1
EXPOSE 8080

COPY themes /opt/jboss/keycloak/themes

#Database
ENV DB_VENDOR=xxx
ENV DB_DATABASE=xxx
ENV DB_ADDR=xxx
ENV DB_PORT=xxx

#Admin user
ENV KEYCLOAK_USER=xxx
ENV KEYCLOAK_PASSWORD=xxx

Anyone having a clue of what I did do wrong?

like image 839
VIAE IT Avatar asked Oct 18 '25 20:10

VIAE IT


1 Answers

I was not able to fix this, but I was able to find a workaround:

I created a base image which contains GraalVM and a standalone keycloak server: https://gitlab.com/viae-modules/viae-modules/-/blob/master/modules/docker-base-images/graalvm-keycloak-dockerfile

FROM centos:7
RUN mkdir /home/viae
RUN mkdir /home/viae/keycloak
WORKDIR /home/viae

COPY config/start_keycloak.sh /home/viae/start_keycloak.sh

RUN yum install -y wget zip unzip git
RUN wget -q https://downloads.jboss.org/keycloak/10.0.1/keycloak-10.0.1.zip
RUN unzip -q keycloak-10.0.1.zip
RUN mv /home/viae/keycloak-10.0.1/* /home/viae/keycloak

RUN wget -q https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz
RUN tar -zxf graalvm-ce-java11-linux-amd64-20.1.0.tar.gz

ENV PATH="/home/viae/graalvm-ce-java11-20.1.0/bin:${PATH}"
ENV JAVA_HOME="/home/viae/graalvm-ce-java11-20.1.0"

RUN /home/viae/keycloak/bin/add-user-keycloak.sh -r master -u admin -p admin

I then can use this embedded keycloak in my CI scripts: https://gitlab.com/viae-modules/viae-modules/-/blob/master/.gitlab-ci.yml (Be careful: keycloak should still be started from within the script ==> provide some time to give keycloak the time to start up.

image: docker:stable

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle
  - chmod a+rx `pwd`/gradlew

services:
  - docker:dind
  - name: mongo:latest
    alias: mongodb
...

.java-base-config:
  image: registry.gitlab.com/viae-modules/viae-modules/viae-graalvm-keycloak/viae-graalvm-keycloak:0.0.2
  ...

.execute-tests-template:
  extends: .java-base-config
  ...

test-viae-oauth2.0-validator:
  extends: .execute-tests-template
  stage: test
  script:
    - date
    - /home/viae/keycloak/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 &
    - sleep 30
    - date
    - curl http://localhost:8080
    - curl http://localhost:8080/auth
    - curl http://localhost:8080/auth/realms/master
    - curl http://localhost:8080/auth/realms/master/protocol/openid-connect/certs
    - MICRONAUT_ENVIRONMENTS=ci ./gradlew --no-daemon :modules:viae-oauth2.0-validator:jacocoTestReport -Pmicronaut.environments=ci
like image 83
VIAE IT Avatar answered Oct 21 '25 11:10

VIAE IT