From 1222e55a9e7d690fc972184b835393707453f434 Mon Sep 17 00:00:00 2001 From: peterstone2017 <12449837+YunchuWang@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:45:52 -0700 Subject: [PATCH] feat: enabling java function dev experience in vscode + devcontainer --- .devcontainer/Dockerfile | 56 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 32 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..f82c4e61 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,56 @@ +# Reference: https://github.com/devcontainers/images/blob/main/src/java/.devcontainer/Dockerfile +ARG TARGET_JAVA_VERSION=21 +ARG BASE_IMAGE_VERSION_CODENAME=bookworm +FROM mcr.microsoft.com/devcontainers/base:${BASE_IMAGE_VERSION_CODENAME} + +USER root +ARG TARGET_JAVA_VERSION +ENV JAVA_HOME /usr/lib/jvm/msopenjdk-current +ENV PATH "${JAVA_HOME}/bin:${PATH}" +# Default to UTF-8 file.encoding +ENV LANG en_US.UTF-8 + +# Install Microsoft OpenJDK +RUN arch="$(dpkg --print-architecture)" \ + && case "$arch" in \ + "amd64") \ + jdkUrl="https://aka.ms/download-jdk/microsoft-jdk-${TARGET_JAVA_VERSION}-linux-x64.tar.gz"; \ + ;; \ + "arm64") \ + jdkUrl="https://aka.ms/download-jdk/microsoft-jdk-${TARGET_JAVA_VERSION}-linux-aarch64.tar.gz"; \ + ;; \ + *) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; \ + esac \ + \ + && wget --progress=dot:giga -O msopenjdk.tar.gz "${jdkUrl}" \ + && wget --progress=dot:giga -O sha256sum.txt "${jdkUrl}.sha256sum.txt" \ + \ + && sha256sumText=$(cat sha256sum.txt) \ + && sha256=$(expr substr "${sha256sumText}" 1 64) \ + && echo "${sha256} msopenjdk.tar.gz" | sha256sum --strict --check - \ + && rm sha256sum.txt* \ + \ + && mkdir -p "$JAVA_HOME" \ + && tar --extract \ + --file msopenjdk.tar.gz \ + --directory "$JAVA_HOME" \ + --strip-components 1 \ + --no-same-owner \ + && rm msopenjdk.tar.gz* \ + \ + && ln -s ${JAVA_HOME} /docker-java-home \ + && ln -s ${JAVA_HOME} /usr/local/openjdk-${TARGET_JAVA_VERSION} + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + + +# Install Maven +RUN apt-get update && apt-get install -y maven + +# Install coretools package from linux software repository +RUN curl -sSL -O https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb \ + && dpkg -i packages-microsoft-prod.deb \ + && rm packages-microsoft-prod.deb \ + && apt-get update && apt-get install azure-functions-core-tools-4 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..375c558a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,32 @@ +{ + "name": "Azure Java Function Worker Development", + "build": { + "dockerfile": "./Dockerfile", + "context": "." + }, + "features": { + "ghcr.io/devcontainers/features/java:1": { + "version": "none" + }, + "ghcr.io/devcontainers/features/node:1": "none", + "ghcr.io/devcontainers/features/git:1": { + "version": "latest", + "ppa": "false" + } + }, + "containerEnv": { + "JAVA_HOME": "/usr/lib/jvm/msopenjdk-current" + }, + "customizations": { + "vscode": { + "extensions": [ + "vscjava.vscode-java-pack", // Java extension pack for VS Code + "vscjava.vscode-java-debug", // Java debug extension + "vscjava.vscode-maven", // Maven extension for VS Code + "ms-azuretools.vscode-azurefunctions", // Azure Functions extension + "ms-azuretools.vscode-azurestorage", // Azure Storage, + "Azurite.azurite" // Azurite extension + ] + } + } +}