Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update devcontainer with java and non-root user #776

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions e2e_samples/parking_sensors/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root for license information.
#-----------------------------------------------------------------------------------------
FROM python:3.7
FROM python:3

ARG USERNAME=mdwuser
# Add non-root user: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Configure apt
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install --no-install-recommends apt-utils 2>&1

# Install git, process tools, lsb-release (common in install instructions for CLIs)
RUN apt-get -y install git procps lsb-release
Expand All @@ -17,6 +23,8 @@ RUN apt-get install -y libicu[0-9][0-9]

# Install Azure CLI and application insights and azure devops extension
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN az config set extension.use_dynamic_install=yes_without_prompt
RUN az config set extension.dynamic_install_allow_preview=true
RUN az extension add --name application-insights
RUN az extension add --name azure-devops

Expand All @@ -28,13 +36,20 @@ RUN apt-get update \
&& apt-get -y install jq makepasswd

# Install java
RUN apt-get install -y openjdk-11-jdk
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64

RUN mkdir /workspace
WORKDIR /workspace
RUN wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | apt-key add -
RUN echo "deb https://packages.adoptium.net/artifactory/deb \
$(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" \
| tee /etc/apt/sources.list.d/adoptium.list
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
temurin-21-jdk
ENV JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME

RUN mkdir /home/$USERNAME/workspace
WORKDIR /home/$USERNAME/workspace

# Clean up
RUN apt-get autoremove -y \
Expand Down
23 changes: 14 additions & 9 deletions e2e_samples/parking_sensors/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"dockerComposeFile": "docker-compose.yml",
"workspaceFolder": "/workspace/e2e_samples/parking_sensors",
"service": "parking_sensor_dc",
"extensions": [
"ms-python.python",
"eamodio.gitlens",
"DavidAnson.vscode-markdownlint",
"yzhang.markdown-all-in-one",
"ms-azuretools.vscode-bicep"
],
"settings": {
"python.pythonPath": "/usr/local/bin/python"
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"eamodio.gitlens",
"DavidAnson.vscode-markdownlint",
"yzhang.markdown-all-in-one",
"ms-azuretools.vscode-bicep"
]
},
"settings": {
"python.pythonPath": "/usr/local/bin/python"
}
},
"remoteUser": "mdwuser",
"postCreateCommand": "./.devcontainer/post_create.sh"
}
8 changes: 2 additions & 6 deletions e2e_samples/parking_sensors/.devcontainer/post_create.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env bash
#!/bin/bash

# Configure az devops cli
az devops configure --defaults organization="$AZDO_ORGANIZATION_URL" project="$AZDO_PROJECT"

# Install requirements depending if devcontainer was openned at root or in parking_sensor folder.
if [ -f "../e2e_samples/parking_sensors/src/ddo_transform/requirements_dev.txt" ]; then
pip install -r ../e2e_samples/parking_sensors/src/ddo_transform/requirements_dev.txt
elif [ -f "e2e_samples/parking_sensors/src/ddo_transform/requirements_dev.txt" ]; then
pip install -r e2e_samples/parking_sensors/src/ddo_transform/requirements_dev.txt
fi
pip install -r /workspace/e2e_samples/parking_sensors/src/ddo_transform/requirements_dev.txt