Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0cc102e

Browse files
committed
Add devcontainer spec
1 parentee696af commit0cc102e

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed

‎.devcontainer/Dockerfile‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM continuumio/miniconda3
2+
3+
# Options for common setup script
4+
ARG INSTALL_ZSH="true"
5+
ARG UPGRADE_PACKAGES="false"
6+
ARG USERNAME=vscode
7+
ARG USER_UID=1000
8+
ARG USER_GID=$USER_UID
9+
10+
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
11+
COPY .devcontainer/library-scripts/*.sh /tmp/library-scripts/
12+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
13+
&& /bin/bash /tmp/library-scripts/common-debian.sh"${INSTALL_ZSH}""${USERNAME}""${USER_UID}""${USER_GID}""${UPGRADE_PACKAGES}" \
14+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
15+
16+
# Copy environment.yml (if found) to a temp locaition so we update the environment. Also
17+
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
18+
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
19+
RUN if [ -f"/tmp/conda-tmp/environment.yml" ]; then /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
20+
&& rm -rf /tmp/conda-tmp
21+
22+
# Install pylint
23+
RUN /opt/conda/bin/pip install pylint
24+
25+
# [Optional] Uncomment this section to install additional OS packages.
26+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
27+
# && apt-get -y install --no-install-recommends <your-package-list-here>
28+

‎.devcontainer/devcontainer.json‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.134.1/containers/python-3-miniconda
3+
{
4+
"name":"Python 3 - Miniconda",
5+
"context":"..",
6+
"dockerFile":"Dockerfile",
7+
8+
// Set *default* container specific settings.json values on container create.
9+
"settings": {
10+
"terminal.integrated.shell.linux":"/bin/bash",
11+
"python.pythonPath":"/opt/conda/bin/python",
12+
"python.linting.enabled":true,
13+
"python.linting.pylintEnabled":true,
14+
"python.linting.pylintPath":"/opt/conda/bin/pylint"
15+
},
16+
17+
// Add the IDs of extensions you want installed when the container is created.
18+
"extensions": [
19+
"ms-python.python"
20+
]
21+
22+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
23+
// "forwardPorts": [],
24+
25+
// Use 'postCreateCommand' to run commands after the container is created.
26+
// "postCreateCommand": "python --version",
27+
28+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
29+
// "remoteUser": "vscode"
30+
}
31+
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
7+
# Syntax: ./common-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag]
8+
9+
INSTALL_ZSH=${1:-"true"}
10+
USERNAME=${2:-"vscode"}
11+
USER_UID=${3:-1000}
12+
USER_GID=${4:-1000}
13+
UPGRADE_PACKAGES=${5:-"true"}
14+
15+
set -e
16+
17+
if ["$(id -u)"-ne 0 ];then
18+
echo -e'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
19+
exit 1
20+
fi
21+
22+
# Treat a user name of "none" as root
23+
if ["${USERNAME}"="none" ]|| ["${USERNAME}"="root" ];then
24+
USERNAME=root
25+
USER_UID=0
26+
USER_GID=0
27+
fi
28+
29+
# Load markers to see which steps have already run
30+
MARKER_FILE="/usr/local/etc/vscode-dev-containers/common"
31+
if [-f"${MARKER_FILE}" ];then
32+
echo"Marker file found:"
33+
cat"${MARKER_FILE}"
34+
source"${MARKER_FILE}"
35+
fi
36+
37+
# Ensure apt is in non-interactive to avoid prompts
38+
export DEBIAN_FRONTEND=noninteractive
39+
40+
# Function to call apt-get if needed
41+
apt-get-update-if-needed()
42+
{
43+
if [!-d"/var/lib/apt/lists" ]|| ["$(ls /var/lib/apt/lists/| wc -l)"="0" ];then
44+
echo"Running apt-get update..."
45+
apt-get update
46+
else
47+
echo"Skipping apt-get update."
48+
fi
49+
}
50+
51+
# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies
52+
if ["${PACKAGES_ALREADY_INSTALLED}"!="true" ];then
53+
apt-get-update-if-needed
54+
55+
PACKAGE_LIST="apt-utils\
56+
git\
57+
openssh-client\
58+
less\
59+
iproute2\
60+
procps\
61+
curl\
62+
wget\
63+
unzip\
64+
nano\
65+
jq\
66+
lsb-release\
67+
ca-certificates\
68+
apt-transport-https\
69+
dialog\
70+
gnupg2\
71+
libc6\
72+
libgcc1\
73+
libgssapi-krb5-2\
74+
libicu[0-9][0-9]\
75+
liblttng-ust0\
76+
libstdc++6\
77+
zlib1g\
78+
locales\
79+
sudo"
80+
81+
# Install libssl1.1 if available
82+
if [[!-z$(apt-cache --names-only search ^libssl1.1$) ]];then
83+
PACKAGE_LIST="${PACKAGE_LIST} libssl1.1"
84+
fi
85+
86+
# Install appropriate version of libssl1.0.x if available
87+
LIBSSL=$(dpkg-query -f'${db:Status-Abbrev}\t${binary:Package}\n' -W'libssl1\.0\.?'2>&1||echo'')
88+
if ["$(echo"$LIBSSL"| grep -o'libssl1\.0\.[0-9]:'| uniq| sort| wc -l)"-eq 0 ];then
89+
if [[!-z$(apt-cache --names-only search ^libssl1.0.2$) ]];then
90+
# Debian 9
91+
PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.2"
92+
elif [[!-z$(apt-cache --names-only search ^libssl1.0.0$) ]];then
93+
# Ubuntu 18.04, 16.04, earlier
94+
PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.0"
95+
fi
96+
fi
97+
98+
echo"Packages to verify are installed:${PACKAGE_LIST}"
99+
apt-get -y install --no-install-recommends${PACKAGE_LIST}2>>( grep -v'debconf: delaying package configuration, since apt-utils is not installed'>&2)
100+
101+
PACKAGES_ALREADY_INSTALLED="true"
102+
fi
103+
104+
# Get to latest versions of all packages
105+
if ["${UPGRADE_PACKAGES}"="true" ];then
106+
apt-get-update-if-needed
107+
apt-get -y upgrade --no-install-recommends
108+
apt-get autoremove -y
109+
fi
110+
111+
# Ensure at least the en_US.UTF-8 UTF-8 locale is available.
112+
# Common need for both applications and things like the agnoster ZSH theme.
113+
if ["${LOCALE_ALREADY_SET}"!="true" ];then
114+
echo"en_US.UTF-8 UTF-8">> /etc/locale.gen
115+
locale-gen
116+
LOCALE_ALREADY_SET="true"
117+
fi
118+
119+
# Create or update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user.
120+
if id -u$USERNAME> /dev/null2>&1;then
121+
# User exists, update if needed
122+
if ["$USER_GID"!="$(id -G$USERNAME)" ];then
123+
groupmod --gid$USER_GID$USERNAME
124+
usermod --gid$USER_GID$USERNAME
125+
fi
126+
if ["$USER_UID"!="$(id -u$USERNAME)" ];then
127+
usermod --uid$USER_UID$USERNAME
128+
fi
129+
else
130+
# Create user
131+
groupadd --gid$USER_GID$USERNAME
132+
useradd -s /bin/bash --uid$USER_UID --gid$USER_GID -m$USERNAME
133+
fi
134+
135+
# Add add sudo support for non-root user
136+
if ["${EXISTING_NON_ROOT_USER}"!="${USERNAME}" ];then
137+
echo$USERNAME ALL=\(root\) NOPASSWD:ALL> /etc/sudoers.d/$USERNAME
138+
chmod 0440 /etc/sudoers.d/$USERNAME
139+
EXISTING_NON_ROOT_USER="${USERNAME}"
140+
fi
141+
142+
# Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later)
143+
if ["${DOT_LOCAL_ALREADY_ADDED}"!="true" ];then
144+
echo"export PATH=\$PATH:\$HOME/.local/bin"| tee -a /root/.bashrc>> /home/$USERNAME/.bashrc
145+
chown$USER_UID:$USER_GID /home/$USERNAME/.bashrc
146+
DOT_LOCAL_ALREADY_ADDED="true"
147+
fi
148+
149+
# Optionally install and configure zsh
150+
if ["${INSTALL_ZSH}"="true" ]&& [!-d"/root/.oh-my-zsh" ]&& ["${ZSH_ALREADY_INSTALLED}"!="true" ];then
151+
apt-get-update-if-needed
152+
apt-get install -y zsh
153+
curl -fsSLo- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh| bash2>&1
154+
echo"export PATH=\$PATH:\$HOME/.local/bin">> /root/.zshrc
155+
if ["${USERNAME}"!="root" ];then
156+
cp -fR /root/.oh-my-zsh /home/$USERNAME
157+
cp -f /root/.zshrc /home/$USERNAME
158+
sed -i -e"s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc
159+
chown -R$USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc
160+
fi
161+
ZSH_ALREADY_INSTALLED="true"
162+
fi
163+
164+
# Write marker file
165+
mkdir -p"$(dirname"${MARKER_FILE}")"
166+
echo -e"\
167+
PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\
168+
LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\
169+
EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\
170+
DOT_LOCAL_ALREADY_ADDED=${DOT_LOCAL_ALREADY_ADDED}\n\
171+
ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}">"${MARKER_FILE}"
172+

‎.devcontainer/noop.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is copied into the container along with environment.yml* from the
2+
parent folder. This is done to prevent the Dockerfile COPY instruction from
3+
failing if no environment.yml is found.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp