FROM centos/systemd as production
# https://mtembo.com/technology/installing-keycloak/
#RUN yum update -y
RUN yum install -y java-1.8.0-openjdk-devel wget curl zip unzip
RUN mkdir -p /opt/keycloak
RUN wget https://github.com/keycloak/keycloak/releases/download/12.0.4/keycloak-12.0.4.zip -P /opt/keycloak
WORKDIR /opt/keycloak
RUN unzip keycloak-12.0.4.zip -d /opt/keycloak
WORKDIR /opt/keycloak/keycloak-12.0.4
### Proxy environment. This should be done in keycloak.cli but don't know how
RUN sed -i 's///g' standalone/configuration/standalone.xml
# postgres
# Download PostgreSQL database drivers
#RUN mkdir -p /opt/drivers/jdbc
#RUN wget https://jdbc.postgresql.org/download/postgresql-42.2.16.jar -P /opt/drivers/jdbc
#RUN /opt/keycloak/keycloak-12.0.4/bin/jboss-cli.sh -c --commands="module add --name=org.postgresql --dependencies=javax.api,javax.transaction.api --resources=/opt/drivers/jdbc/postgresql-42.2.16.jar"
#RUN /subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql,driver-class-name=org.postgresql.Driver)
#RUN /subsystem=datasources/data-source=KeycloakDS:remove
#RUN /subsystem=datasources/data-source=KeycloakDS:add(driver-name=postgresql,enabled=true,use-java-context=true,connection-url="jdbc:postgresql://host:port/database",jndi-name="java:/jboss/datasources/KeycloakDS",user-name=keycloak,password="PASSWORD",max-pool-size=20)
#RUN standalone.sh -b 0.0.0.0 -Djboss.http.port=9080 -Dkeycloak.import=/keycloak-work/freeipa-realm.json
RUN yum -y install systemd; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
RUN yum -y install freeipa-client freeipa-admintools jna sssd-dbus
RUN wget https://download.copr.fedorainfracloud.org/results/giesen/libunix-dbus-java/epel-8-x86_64/01134406-libunix-dbus-java/libunix-dbus-java-0.8.0-2.el8.x86_64.rpm
RUN yum install -y libunix-dbus-java-0.8.0-2.el8.x86_64.rpm
ADD docker-entrypoint.sh /
RUN chmod 700 /docker-entrypoint.sh
CMD ["/docker-entrypoint.sh"]
#CMD ["/opt/keycloak/keycloak-12.0.4/bin/standalone.sh","-b","0.0.0.0"]