# A code-server image with added
# openjdk@17 
# BaseX installed@10.6
# docker build --tag=vscode4.16-basex10.7 .
# @author Andy Bunce
# Bugs:
#    hardcoded for amd64

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

ARG TARGETARCH
ARG BUILDARCH
ARG PUID=1000
ARG PGID=1000
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-17
RUN apt-get update && \
    apt-get install -y openjdk-17-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-17-openjdk-amd64/
RUN export JAVA_HOME

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

# install docker cli only
# https://docs.docker.com/engine/install/ubuntu/
RUN install -m 0755 -d /etc/apt/keyrings && \
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
RUN chmod a+r /etc/apt/keyrings/docker.gpg
RUN echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update && apt-get install -y docker-ce-cli

#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.4/binaries/apache-maven-3.9.4-bin.tar.gz | \
    tar zxv -C /usr/local/bin && \
    cd /usr/local/bin && \
    ln -s apache-maven-3.9.4 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