# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/node:4-node18-appservice
# FROM mcr.microsoft.com/azure-functions/node:4-node18
FROM node:18.17.1-buster


RUN /bin/cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
    echo "Asia/Tokyo" > /etc/timezone
    
# Options for setup script
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="false"
ARG USERNAME=vscode
# 1000 はnodeで使われているためずらす
ARG USER_UID=1001
ARG USER_GID=$USER_UID

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
COPY library-scripts/common-debian.sh /tmp/library-scripts/
RUN bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \
    && apt-get install default-jre -y \
    && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts

# Update NPM
RUN npm install -g npm

# 以下 ユーザー権限で実施
USER $USERNAME
# copy init-script
COPY --chown=$USERNAME:$USERNAME init.sh /home/${USERNAME}/
RUN chmod +x /home/${USERNAME}/init.sh

# 初期化を行う
# node imageのデフォルトENTRYPOINTが邪魔するため上書き
ENTRYPOINT /home/vscode/init.sh