Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 2dd74c1

Browse files
authored
Merge pull request #476 from microsoft/clantz/az-block-library-scripts
Update azure-blockchain to use library-scripts
2 parents c773aac + fd63c90 commit 2dd74c1

File tree

5 files changed

+197
-35
lines changed

5 files changed

+197
-35
lines changed

containers/azure-blockchain/.devcontainer/Dockerfile

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,31 @@
11
FROM python:2.7-stretch
22

3-
# This Dockerfile adds a non-root user with sudo access. Update the “remoteUser” property in
4-
# devcontainer.json to use it. More info: https://aka.ms/vscode-remote/containers/non-root-user.
3+
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
4+
ARG INSTALL_ZSH="true"
5+
ARG UPGRADE_PACKAGES="false"
56
ARG USERNAME=vscode
67
ARG USER_UID=1000
78
ARG USER_GID=$USER_UID
8-
9-
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
10-
RUN apt-get update \
11-
&& export DEBIAN_FRONTEND=noninteractive \
12-
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
13-
#
14-
# Verify git, process tools installed
15-
&& apt-get -y install git openssh-client less iproute2 procps \
16-
#
17-
# Install nodejs
18-
&& curl -sL https://deb.nodesource.com/setup_10.x | bash - \
19-
&& apt-get install -y nodejs \
20-
#
21-
# Install Truffle Suite
22-
&& npm i --unsafe-perm -g truffle \
23-
#
24-
# Install Ganache CLI
25-
&& npm install -g ganache-cli \
26-
#
27-
# Install the Azure CLI
28-
&& apt-get install -y apt-transport-https curl gnupg2 lsb-release \
9+
ENV NVM_DIR=/usr/local/share/nvm
10+
ENV NVM_SYMLINK_CURRENT=true \
11+
PATH=${NVM_DIR}/current/bin:${PATH}
12+
COPY library-scripts/*.sh /tmp/library-scripts/
13+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
14+
&& bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \
15+
# Install Node
16+
&& bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "12" "${USERNAME}" \
17+
# Install Azure CLI
2918
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \
3019
&& curl -sL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 2>/dev/null \
3120
&& apt-get update \
3221
&& apt-get install -y azure-cli \
33-
#
34-
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
35-
&& groupadd --gid $USER_GID $USERNAME \
36-
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
37-
# [Optional] Add sudo support for the non-root user
38-
&& apt-get install -y sudo \
39-
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
40-
&& chmod 0440 /etc/sudoers.d/$USERNAME \
41-
#
4222
# Clean up
43-
&& apt-get autoremove -y \
44-
&& apt-get clean -y \
45-
&& rm -rf /var/lib/apt/lists/*
23+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
24+
25+
# Install Truffle Suite and Ganache CLI
26+
RUN sudo -u ${USERNAME} bash -c "source ${NVM_DIR}/nvm.sh \
27+
&& npm i --unsafe-perm -g truffle \
28+
&& npm i -g ganache-cli"
4629

4730
# [Optional] Uncomment this section to install additional OS packages.
4831
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Warning: Folder contents may be replaced
2+
3+
The contents of this folder will be automatically replaced with a file of the same name in the repository's [script-library folder](https://github.com/microsoft/vscode-dev-containers/tree/master/script-library) whenever the repository is packaged.
4+
5+
To retain your edits, move the file to a different location. You may also delete the files if they are not needed.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
set -e
10+
11+
INSTALL_ZSH=${1:-"true"}
12+
USERNAME=${2:-"$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)"}
13+
USER_UID=${3:-1000}
14+
USER_GID=${4:-1000}
15+
UPGRADE_PACKAGES=${5:-"true"}
16+
17+
if [ "$(id -u)" -ne 0 ]; then
18+
echo 'Script must be run a root. Use sudo or set "USER root" before running the 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+
# Ensure apt is in non-interactive to avoid prompts
30+
export DEBIAN_FRONTEND=noninteractive
31+
32+
# Install apt-utils to avoid debconf warning
33+
apt-get -y install --no-install-recommends apt-utils 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
34+
35+
# Get to latest versions of all packages
36+
if [ "${UPGRADE_PACKAGES}" = "true" ]; then
37+
apt-get -y upgrade --no-install-recommends
38+
fi
39+
40+
# Install common developer tools and dependencies
41+
apt-get -y install --no-install-recommends \
42+
git \
43+
openssh-client \
44+
less \
45+
iproute2 \
46+
procps \
47+
curl \
48+
wget \
49+
unzip \
50+
nano \
51+
jq \
52+
lsb-release \
53+
ca-certificates \
54+
apt-transport-https \
55+
dialog \
56+
gnupg2 \
57+
libc6 \
58+
libgcc1 \
59+
libgssapi-krb5-2 \
60+
libicu[0-9][0-9] \
61+
liblttng-ust0 \
62+
libstdc++6 \
63+
zlib1g \
64+
locales
65+
66+
# Ensure at least the en_US.UTF-8 UTF-8 locale is available.
67+
# Common need for both applications and things like the agnoster ZSH theme.
68+
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
69+
locale-gen
70+
71+
# Install libssl1.1 if available
72+
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
73+
apt-get -y install --no-install-recommends libssl1.1
74+
fi
75+
76+
# Install appropriate version of libssl1.0.x if available
77+
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
78+
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
79+
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then
80+
# Debian 9
81+
apt-get -y install --no-install-recommends libssl1.0.2
82+
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then
83+
# Ubuntu 18.04, 16.04, earlier
84+
apt-get -y install --no-install-recommends libssl1.0.0
85+
fi
86+
fi
87+
88+
# Create or update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user.
89+
if id -u $USERNAME > /dev/null 2>&1; then
90+
# User exists, update if needed
91+
if [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
92+
groupmod --gid $USER_GID $USERNAME
93+
usermod --gid $USER_GID $USERNAME
94+
fi
95+
if [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
96+
usermod --uid $USER_UID $USERNAME
97+
fi
98+
else
99+
# Create user
100+
groupadd --gid $USER_GID $USERNAME
101+
useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME
102+
fi
103+
104+
# Add add sudo support for non-root user
105+
apt-get install -y sudo
106+
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
107+
chmod 0440 /etc/sudoers.d/$USERNAME
108+
109+
# Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later)
110+
echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc
111+
chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc
112+
113+
# Optionally install and configure zsh
114+
if [ "$INSTALL_ZSH" = "true" ] && [ ! -d "/root/.oh-my-zsh" ]; then
115+
apt-get install -y zsh
116+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
117+
echo "export PATH=\$PATH:\$HOME/.local/bin" >> /root/.zshrc
118+
cp -R /root/.oh-my-zsh /home/$USERNAME
119+
cp /root/.zshrc /home/$USERNAME
120+
sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc
121+
chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc
122+
fi
123+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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: ./node-debian.sh <directory to install nvm> <node version to install (use "none" to skip)> <non-root user>
8+
9+
set -e
10+
11+
export NVM_DIR=${1:-"/usr/local/share/nvm"}
12+
export NODE_VERSION=${2:-"lts/*"}
13+
NONROOT_USER=${3:-"vscode"}
14+
15+
if [ "$(id -u)" -ne 0 ]; then
16+
echo 'Script must be run a root. Use sudo or set "USER root" before running the script.'
17+
exit 1
18+
fi
19+
20+
# Ensure apt is in non-interactive to avoid prompts
21+
export DEBIAN_FRONTEND=noninteractive
22+
23+
if [ "${NODE_VERSION}" = "none" ]; then
24+
export NODE_VERSION=
25+
fi
26+
27+
# Install NVM
28+
mkdir -p ${NVM_DIR}
29+
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 2>&1
30+
if [ "${NODE_VERSION}" != "" ]; then
31+
/bin/bash -c "source $NVM_DIR/nvm.sh && nvm alias default ${NODE_VERSION}" 2>&1
32+
fi
33+
34+
echo -e "export NVM_DIR=\"${NVM_DIR}\"\n\
35+
[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\"\n\
36+
[ -s \"\$NVM_DIR/bash_completion\" ] && \\. \"\$NVM_DIR/bash_completion\"" \
37+
| tee -a /home/${NONROOT_USER}/.bashrc /home/${NONROOT_USER}/.zshrc >> /root/.zshrc
38+
39+
echo -e "if [ \"\$(stat -c '%U' \$NVM_DIR)\" != \"${NONROOT_USER}\" ]; then\n\
40+
sudo chown -R ${NONROOT_USER}:root \$NVM_DIR\n\
41+
fi" | tee -a /root/.bashrc /root/.zshrc /home/${NONROOT_USER}/.bashrc >> /home/${NONROOT_USER}/.zshrc
42+
43+
chown ${NONROOT_USER}:${NONROOT_USER} /home/${NONROOT_USER}/.bashrc /home/${NONROOT_USER}/.zshrc
44+
chown -R ${NONROOT_USER}:root ${NVM_DIR}
45+
46+
# Install yarn
47+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 2>/dev/null
48+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
49+
apt-get update
50+
apt-get -y install --no-install-recommends yarn
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
README.md
22
test-project
33
definition-manifest.json
4+
.devcontainer/library-scripts/README.md
45
.vscode
56
.npmignore

0 commit comments

Comments
 (0)