FROM ucalgary/glassfish:latest
MAINTAINER Alexander Ryan (alexander_the_1st@hotmail.com) [MT1ST]
# First things first - Alpine Linux apparently needs apk to be updated to access to apache-ant.
# We need to do some modification of "/etc/apk/repositories" to enable the community repo further, as I understand, as 3.7 is the version of our latest image.
# Sort of - we also need to make sure that alpine linux edge keys are updated...by "allowing untrusted".
#RUN ["apk", "add", "-X", "https://nl.alpinelinux.org/alpine/v3.14/main", "-u", "alpine-keys", "--allow-untrusted"]
RUN ["sed", "-i", "-e", "s%^http:\/\/dl-cdn.alpinelinux.org\/alpine\/v3.7\/%http:\/\/dl-cdn.alpinelinux.org\/alpine\/v3.14\/%", "/etc/apk/repositories"]
RUN ["apk", "update"]
#RUN ["apk", "add", "-X", "https://nl.alpinelinux.org/alpine/edge/main", "-u", "alpine-keys", "--allow-untrusted"]
RUN ["apk", "add", "openjdk11"]
#RUN ["apk", "--no-cache", "add", "openjdk11", "--repository=http://dl-cdn.alpinelinux.org/alpine/edge/community"]
RUN ["apk", "add", "apache-ant"]
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-11-openjdk/jre/bin:/usr/lib/jvm/java-11-openjdk/bin:
ENV JAVA_VERSION=11u151
ENV JAVA_ALPINE_VERSION=11.151.2.6.11-r0
#Take our codebase, and attempt to install.
COPY ./ ./
#RUN ["java", "--version"]
RUN ["ant"]
# Pushing this to the autodeploy folder so that we can actually see the site.
RUN ["mv", "/usr/local/glassfish3/dist/FlickrAPIProject2.war", "/usr/local/glassfish3/glassfish/domains/domain1/autodeploy/FlickrAPIProject2.war"]
# If this works, may want to make specific .
#COPY /usr/local/glashfish3/glassfish/dist/FlickrAPIProject2.war /usr/local/glashfish3/glassfish/domains/domain1/autodeploy/ROOT.war
ENV PATH="$PATH:$GLASSFISH_HOME/bin"
RUN ["apk", "add", "sed"]
#RUN ["sed", "-i", "-e", "%$a\n%AS_JAVA=\/usr\/lib\/jvm\/java-11-openjdk\/%" "/usr/local/glassfish3/glassfish/config/asenv.conf", ]

# Resetting the ENVs to what worked for glassfish. We needed higher version Java to run ant, but...Glassfish 3 doesn't like the nwer version.
ENV GLASSFISH_PKG=/tmp/glassfish-3.1.2.2.zip GLASSFISH_URL=http://download.oracle.com/glassfish/3.1.2.2/release/glassfish-3.1.2.2.zip GLASSFISH_HOME=/usr/local/glassfish3 MD5=ae8e17e9dcc80117cb4b39284302763f PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.7-openjdk/jre/bin:/usr/lib/jvm/java-1.7-openjdk/bin:/usr/local/glassfish3/bin

RUN echo "AS_JAVA=/usr/lib/jvm/java-1.7-openjdk" >> "/usr/local/glassfish3/glassfish/config/asenv.conf"
# Okay, in order to get ssl working for openjdk-1.7, we...need to make it clearer we *want* to use 1.7 for the application.
# openjdk-11 was used for ant installation, but ant and openjdk-11 is causing problems for ssl certifications.
RUN ["apk", "del", "apache-ant"]
RUN ["apk", "del", "openjdk11"]
RUN ["update-ca-certificates"]
#RUN ["certutil", "-A", -n "Amazon Root CA 1" -t "P,u,u", "-d", "$GLASSFISH_HOME/FlickrAPIProject2", "-i", "/etc/ssl/certs/ca-cert-Amazon_Root_CA_1.pem"]
#RUN ["apk update && apk get -only-upgrade-ca-certificates"] # Hopefully works this way.
#RUN ["keytool -importcert -alias 'Amazon Root CA 1' -keystore -file '/etc/ssl/certs/ca-cert-Amazon_Root_CA_1.pem' --storepass changeit"]
#RUN ["ls"]
#RUN ["keytool -importcert -alias 'Flickr.com' -cacerts -file 'flickr.com.crt' --no-prompt"]
# "ca-certs" file for Java is in Java 11, but we also need it in Java 1.7 - so we're just making the folder it would be in and copying it there.
# This should be important to make sure that our server can make https requests, as the Flickr API it connects to no longer supports http.
#RUN ["mkdir /usr/lib/jvm/java-1.7-openjdk/lib/security"]
#RUN ["cp -r /usr/lib/jvm/java-11-openjdk/lib/security /usr/lib/jvm/java-1.7-openjdk/lib/"]
#RUN ["ln -s $JAVA_HOME/lib/security /usr/lib/jvm/java-1.7-openjdk/lib/security"] # For some reason, these folders don't appear to exist at this point?
#ENTRYPOINT ["/usr/local/glassfish3/docker-entrypoint.sh"]
ENTRYPOINT ["asadmin", "start-domain", "--verbose"]
# -Djavax.net.ssl.trustStore to make this work in localhost instances for https server certs, as I understand.
#ENTRYPOINT ["yes"]
#EXPOSE 8080
# Okay, this *should* work now, sort of maybe deploying the glassfish server, but currently blocked on Ant's build configurations. 