Skip to content

Commit bc4a30f

Browse files
committed
enables github codespaces
1 parent c0e6c4f commit bc4a30f

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

.devcontainer/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM rabbitmq:3.7-management
2+
3+
ENV NVM_DIR="/usr/local/share/nvm"
4+
ENV NVM_SYMLINK_CURRENT=true \
5+
PATH=${NVM_DIR}/current/bin:${PATH}
6+
COPY library-scripts/node-debian.sh /tmp/library-scripts/
7+
RUN apt-get update && bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}"

.devcontainer/devcontainer.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "RabbitMQ Tutorials",
3+
"dockerFile": "Dockerfile",
4+
"forwardPorts": [ 4369, 5671, 5672, 15691, 15692, 25672 ],
5+
6+
// Set *default* container specific settings.json values on container create.
7+
"settings": {
8+
"terminal.integrated.shell.linux": "/bin/bash"
9+
},
10+
11+
// Add the IDs of extensions you want installed when the container is created.
12+
"extensions": [],
13+
14+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
15+
// "remoteUser": "vscode"
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/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+
# File taken from https://github.com/microsoft/vscode-dev-containers/blob/master/containers/azure-static-web-apps/.devcontainer/library-scripts/node-debian.sh
8+
9+
# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user]
10+
11+
export NVM_DIR=${1:-"/usr/local/share/nvm"}
12+
export NODE_VERSION=${2:-"lts/*"}
13+
USERNAME=${3:-"vscode"}
14+
UPDATE_RC=${4:-"true"}
15+
16+
mkdir -p "/etc/zsh/"
17+
18+
set -e
19+
20+
if [ "$(id -u)" -ne 0 ]; then
21+
echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
22+
exit 1
23+
fi
24+
25+
# Treat a user name of "none" or non-existant user as root
26+
if [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
27+
USERNAME=root
28+
fi
29+
30+
if [ "${NODE_VERSION}" = "none" ]; then
31+
export NODE_VERSION=
32+
fi
33+
34+
# Ensure apt is in non-interactive to avoid prompts
35+
export DEBIAN_FRONTEND=noninteractive
36+
37+
# Install curl, apt-transport-https, tar, or gpg if missing
38+
if ! dpkg -s apt-transport-https curl ca-certificates tar > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then
39+
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
40+
apt-get update
41+
fi
42+
apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates tar gnupg2
43+
fi
44+
45+
# Install yarn
46+
if type yarn > /dev/null 2>&1; then
47+
echo "Yarn already installed."
48+
else
49+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT)
50+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
51+
apt-get update
52+
apt-get -y install --no-install-recommends yarn
53+
fi
54+
55+
# Install the specified node version if NVM directory already exists, then exit
56+
if [ -d "${NVM_DIR}" ]; then
57+
echo "NVM already installed."
58+
if [ "${NODE_VERSION}" != "" ]; then
59+
su ${USERNAME} -c "source $NVM_DIR/nvm.sh && nvm install ${NODE_VERSION} && nvm clear-cache"
60+
fi
61+
exit 0
62+
fi
63+
64+
65+
# Run NVM installer as non-root if needed
66+
mkdir -p ${NVM_DIR}
67+
chown ${USERNAME} ${NVM_DIR}
68+
su ${USERNAME} -c "$(cat << EOF
69+
set -e
70+
71+
# Do not update profile - we'll do this manually
72+
export PROFILE=/dev/null
73+
74+
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
75+
source ${NVM_DIR}/nvm.sh
76+
if [ "${NODE_VERSION}" != "" ]; then
77+
nvm alias default ${NODE_VERSION}
78+
fi
79+
nvm clear-cache
80+
EOF
81+
)" 2>&1
82+
83+
if [ "${UPDATE_RC}" = "true" ]; then
84+
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc with NVM scripts..."
85+
(cat <<EOF
86+
export NVM_DIR="${NVM_DIR}"
87+
sudoIf()
88+
{
89+
if [ "\$(id -u)" -ne 0 ]; then
90+
sudo "\$@"
91+
else
92+
"\$@"
93+
fi
94+
}
95+
if [ "\$(stat -c '%U' \$NVM_DIR)" != "${USERNAME}" ]; then
96+
if [ "\$(id -u)" -eq 0 ] || type sudo > /dev/null 2>&1; then
97+
echo "Fixing permissions of \"\$NVM_DIR\"..."
98+
sudoIf chown -R ${USERNAME}:root \$NVM_DIR
99+
else
100+
echo "Warning: NVM directory is not owned by ${USERNAME} and sudo is not installed. Unable to correct permissions."
101+
fi
102+
fi
103+
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
104+
[ -s "\$NVM_DIR/bash_completion" ] && . "\$NVM_DIR/bash_completion"
105+
EOF
106+
) | tee -a /etc/bash.bashrc >> /etc/zsh/zshrc
107+
fi
108+
109+
echo "Done!"

0 commit comments

Comments
 (0)