# A code-server image with added
# openjdk@11 
# BaseX installed@9.7.3
# @author Andy Bunce
# Bugs:
#    hardcoded for amd64

# Main image
FROM ghcr.io/linuxserver/code-server:latest

ARG TARGETARCH
ARG BUILDARCH
RUN echo "I'm building vscode-basex for ${BUILDARCH} on ${TARGETARCH} User: ${PUID}"

LABEL author="Andy Bunce"
LABEL company="Quodatum Ltd"
LABEL maintainer="quodatum@gmail.com"

# Install OpenJDK-8
RUN apt-get update && \
    apt-get install -y openjdk-8-jdk-headless;
  
# Fix certificate issues
RUN apt-get update && \
    apt-get install ca-certificates-java && \
    apt-get clean && \
    update-ca-certificates -f;

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME

# install BaseX to /basex/
RUN curl https://files.basex.org/releases/9.5.1/BaseX951.zip | jar xv && \
    chown -R 1000:1000 /basex && chmod a+x /basex/bin/* ;
ENV PATH=$PATH:/basex/bin

# install docker cli only
RUN curl https://download.docker.com/linux/static/stable/x86_64/docker-23.0.1.tgz  | tar zxv -C /tmp/ && \
    cp /tmp/docker/docker /usr/local/bin && rm -r /tmp/docker;

# install maven
RUN curl https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz | \
    tar zxv -C /usr/local/bin && \
    cd /usr/local/bin && \
    ln -s apache-maven-3.9.0 maven 
ENV PATH=$PATH:/usr/local/bin/maven/bin

# install node+npm LTS see https://www.how2shout.com/linux/how-to-install-node-js-npm-on-debian-11-bullseye/
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
    apt install nodejs

#RUN chmod 666 /var/run/docker.sock
 
#RUN /usr/local/bin/code-server --install-extension vscode-basex-0.0.21.vsix

# ports and volumes
EXPOSE 8443