Skip to content

Commit b932a97

Browse files
committed
feat: initial commit
0 parents  commit b932a97

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Devfiles for PairSpaces
2+
3+
Use PairSpaces and work together with your team using Devfiles (see https://devfile.io).
4+
5+
## Usage
6+
7+
In your `devfile.yaml`:
8+
9+
```yaml
10+
schemaVersion: 2.2.0
11+
metadata:
12+
name: pairspaces-dev
13+
14+
components:
15+
- name: devenv
16+
container:
17+
image: node:18
18+
mountSources: true
19+
command: ["sleep"]
20+
args: ["infinity"]
21+
22+
commands:
23+
- id: install-pair
24+
exec:
25+
component: devenv
26+
commandLine: curl -fsSL https://raw.githubusercontent.com/pairspaces/devfiles/main/install.sh?a=b | bash
27+
group:
28+
kind: run
29+
30+
- id: start-supervisord
31+
exec:
32+
component: devenv
33+
commandLine: supervisord -c /etc/supervisor/supervisord.conf
34+
group:
35+
kind: run
36+
37+
- id: bootstrap
38+
exec:
39+
component: devenv
40+
commandLine: |
41+
while [ ! -x /opt/pair/pair ]; do sleep 1; done
42+
/opt/pair/pair spaces bootstrap "[OUTPUT from `pair spaces authorize` HERE]"
43+
workingDir: /projects
44+
group:
45+
kind: run
46+
isDefault: true
47+
48+
events:
49+
postStart:
50+
- install-pair
51+
- start-supervisord
52+
- bootstrap
53+
```
54+

install.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# --------------------------
5+
# Configuration
6+
# --------------------------
7+
PAIR_ENV="build"
8+
PAIR_VERSION="2.2.3-build"
9+
PORT="${VAR_PORT:-2222}"
10+
PAIR_CLI_URL="https://s3.amazonaws.com/downloads.pairspaces.com/cli/$PAIR_ENV/linux/amd64/pair_${PAIR_VERSION}"
11+
PAIR_CLI_PATH="/opt/pair/pair"
12+
SSHD_CONFIG_TARGET="/etc/ssh/ps_sshd_config"
13+
SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d"
14+
SUPERVISORD_MAIN_CONF="/etc/supervisor/supervisord.conf"
15+
TOKEN="${TOKEN:-CHANGE_ME}"
16+
17+
PKG_INSTALL=""
18+
PKG_UPDATE=""
19+
20+
# --------------------------
21+
# Detect package manager
22+
# --------------------------
23+
detect_package_manager() {
24+
if command -v apt-get >/dev/null 2>&1; then
25+
PKG_INSTALL="apt-get install -y --no-install-recommends"
26+
PKG_UPDATE="apt-get update"
27+
elif command -v apk >/dev/null 2>&1; then
28+
PKG_INSTALL="apk add --no-cache"
29+
PKG_UPDATE=":"
30+
elif command -v dnf >/dev/null 2>&1; then
31+
PKG_INSTALL="dnf install -y"
32+
PKG_UPDATE="dnf makecache"
33+
elif command -v yum >/dev/null 2>&1; then
34+
PKG_INSTALL="yum install -y"
35+
PKG_UPDATE="yum makecache"
36+
elif command -v pacman >/dev/null 2>&1; then
37+
PKG_INSTALL="pacman -Sy --noconfirm"
38+
PKG_UPDATE="pacman -Sy"
39+
else
40+
echo "Unsupported OS. Could not detect package manager."
41+
exit 1
42+
fi
43+
}
44+
45+
# --------------------------
46+
# Install system packages
47+
# --------------------------
48+
install_packages() {
49+
eval "$PKG_UPDATE"
50+
eval "$PKG_INSTALL curl bash openssh-server sudo ca-certificates iproute2 kmod supervisor"
51+
}
52+
53+
# --------------------------
54+
# Install Pair CLI
55+
# --------------------------
56+
install_pair_cli() {
57+
mkdir -p "$(dirname "$PAIR_CLI_PATH")"
58+
curl -fsSL "$PAIR_CLI_URL" -o "$PAIR_CLI_PATH"
59+
chmod +x "$PAIR_CLI_PATH"
60+
}
61+
62+
# --------------------------
63+
# Configure SSHD
64+
# --------------------------
65+
configure_sshd() {
66+
mkdir -p /var/run/sshd /etc/ssh
67+
68+
cat <<EOF > "$SSHD_CONFIG_TARGET"
69+
AuthorizedKeysCommand /opt/pair/pair verify %u %k %t
70+
AuthorizedKeysCommandUser root
71+
72+
Port ${PORT}
73+
74+
PasswordAuthentication no
75+
PermitEmptyPasswords no
76+
77+
Subsystem sftp /usr/libexec/openssh/sftp-server
78+
EOF
79+
80+
ssh-keygen -A || true
81+
}
82+
83+
# --------------------------
84+
# Configure supervisord
85+
# --------------------------
86+
configure_supervisord() {
87+
mkdir -p "$SUPERVISOR_CONF_DIR"
88+
89+
cat <<EOF > "${SUPERVISOR_CONF_DIR}/sshd.conf"
90+
[program:sshd]
91+
command=/usr/sbin/sshd -D -e -f $SSHD_CONFIG_TARGET
92+
autostart=true
93+
autorestart=true
94+
stderr_logfile=/var/log/sshd.err.log
95+
stdout_logfile=/var/log/sshd.out.log
96+
EOF
97+
98+
cat <<EOF > "$SUPERVISORD_MAIN_CONF"
99+
[supervisord]
100+
nodaemon=false
101+
user=root
102+
logfile=/var/log/supervisord.log
103+
pidfile=/var/run/supervisord.pid
104+
105+
[include]
106+
files = $SUPERVISOR_CONF_DIR/*.conf
107+
EOF
108+
}
109+
110+
main() {
111+
detect_package_manager
112+
install_packages
113+
install_pair_cli
114+
configure_sshd
115+
configure_supervisord
116+
}
117+
118+
main "$@"

0 commit comments

Comments
 (0)