diff --git a/roles/keycloak/defaults/main.yml b/roles/keycloak/defaults/main.yml index b348b0c..a1be9d0 100644 --- a/roles/keycloak/defaults/main.yml +++ b/roles/keycloak/defaults/main.yml @@ -8,6 +8,9 @@ keycloak_container_image_name: "keycloak:{{ keycloak_version }}-custom" keycloak_container_database_vendor: postgres keycloak_container_build_directory: /opt/keycloak/build +keycloak_container_build_jar_directory: providers +keycloak_container_build_flags: {} +keycloak_provider_jars_directory: "{{ keycloak_container_build_directory }}/{{ keycloak_container_build_jar_directory }}" keycloak_database_hostname: localhost keycloak_database_port: 5432 diff --git a/roles/keycloak/tasks/main.yml b/roles/keycloak/tasks/main.yml index 6983400..1ba5852 100644 --- a/roles/keycloak/tasks/main.yml +++ b/roles/keycloak/tasks/main.yml @@ -7,11 +7,18 @@ recurse: yes mode: 0700 +- name: Ensure provider jars directory exists + file: + name: "{{ keycloak_provider_jars_directory }}" + state: directory + mode: 0775 + - name: Ensure Dockerfile is templated template: src: Dockerfile.j2 dest: "{{ keycloak_container_build_directory }}/Dockerfile" - mode: 0640 + mode: 0700 + register: keycloak_buildfile_info - name: Ensure Keycloak container image is present docker_image: @@ -46,3 +53,5 @@ --db-password {{ keycloak_database_password }} --db-url jdbc:postgresql://{{ keycloak_database_hostname }}:{{ keycloak_database_port }}/{{ keycloak_database_database }} --optimized + tags: + - keycloak-container diff --git a/roles/keycloak/templates/Dockerfile.j2 b/roles/keycloak/templates/Dockerfile.j2 index 2875e41..0e6da59 100644 --- a/roles/keycloak/templates/Dockerfile.j2 +++ b/roles/keycloak/templates/Dockerfile.j2 @@ -9,7 +9,18 @@ ARG DB_VENDOR ENV KC_DB=$DB_VENDOR WORKDIR {{ keycloak_container_working_directory }} -RUN {{ keycloak_container_working_directory }}/bin/kc.sh build + +ADD ./providers/* providers/ +# Workaround to set correct mode on jar files +USER root +RUN chmod -R 0770 providers/* +USER keycloak + +RUN {{ keycloak_container_working_directory }}/bin/kc.sh --verbose \ +{% for argument in keycloak_container_build_flags | dict2items(key_name='flag', value_name='value') %} + --{{- argument['flag'] -}}{{- argument['value'] | default(false, true) | ternary('=' + argument['value'], '') }} \ +{% endfor%} + build FROM {{ keycloak_container_upstream_image_name }}:{{ keycloak_version }}