Skip to content

Commit 8af2f6b

Browse files
committed
devcontainer working with ssh and custom uid
1 parent aeff741 commit 8af2f6b

File tree

5 files changed

+64
-39
lines changed

5 files changed

+64
-39
lines changed

Dockerfile

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive
44

55
# Install build dependencies
66
RUN apt-get update && apt-get install -y --no-install-recommends \
7-
git curl sbcl make unzip ca-certificates \
7+
git curl sbcl make unzip ca-certificates \
88
libsqlite3-dev libssl-dev gawk freetds-dev jq \
99
&& rm -rf /var/lib/apt/lists/*
1010

@@ -21,36 +21,32 @@ RUN \
2121
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
2222
apt update && \
2323
apt install -y less man-db sudo vim jq python-is-python3 python3-virtualenv \
24-
locales postgresql-client-16 openssh-server
24+
locales postgresql-client-16 openssh-server tini supervisor
2525

26+
# setup env
2627
RUN \
2728
touch /.dockerenv && \
2829
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
2930
locale-gen en_US.UTF-8 && \
3031
update-locale ANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8
3132

32-
# Ensure default `node` user has access to `sudo`
33-
ARG USERNAME=node
34-
RUN \
35-
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
36-
&& chmod 0440 /etc/sudoers.d/$USERNAME
37-
38-
# install ops and plugins
39-
USER node
40-
RUN \
41-
curl -sL https://raw.githubusercontent.com/apache/openserverless-cli/refs/heads/main/install.sh | bash
33+
# pgloader, uv, opencode, concurrently, ops
34+
COPY --from=pgloader-builder /build/pgloader/build/bin/pgloader /usr/bin/pgloader
4235
RUN \
4336
curl -LsSf https://astral.sh/uv/install.sh | sh
44-
45-
ENV PATH="/home/node/.local/bin:${PATH}"
46-
4737
RUN \
48-
ops -update
38+
npm install -g concurrently opencode-ai
4939
RUN \
50-
git clone https://github.com/apache/openserverless-devcontainer /home/node/.ops/openserverless-devcontainer ;\
51-
ln -sf /home/node/.ops/devcontaine/olaris-tk /home/node/olaris-tk
52-
53-
COPY --from=pgloader-builder /build/pgloader/build/bin/pgloader /usr/bin/pgloader
54-
ADD start-ssh.sh /start-ssh.sh
55-
56-
CMD ["/start-ssh.sh"]
40+
curl -sL https://raw.githubusercontent.com/apache/openserverless-cli/refs/heads/main/install.sh | bash \
41+
&& mv ~/.local/bin/ops /usr/local/bin/ops
42+
43+
# remove node
44+
RUN userdel node ; rm -Rvf /home/node
45+
ENV HOME=/home
46+
ENV OPS_BRANCH=main
47+
ADD start.sh /start.sh
48+
49+
ENTRYPOINT ["tini", "--"]
50+
CMD ["/start.sh"]
51+
RUN mkdir /workspace
52+
WORKDIR /workspace

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
# DevContainer
2+
3+
The devcontainer uses
4+
5+
`/home` as home director
6+
`/workspace` as worspace folder
7+
8+
you need to create an user doc

Taskfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ vars:
88
sh: git tag --sort=-creatordate | head -n 1 || "latest"
99

1010
tasks:
11+
default: task --list-all
1112

1213
show: "echo {{.NAME}}:{{.TAG}}"
1314

@@ -18,6 +19,11 @@ tasks:
1819

1920
build:
2021
- docker build -t "{{.NAME}}:{{.TAG}}" . --load
22+
- task: show
23+
24+
clean:
25+
- docker rm -f ssh-devcontainer || true
26+
- docker images | awk '/<none>|devcontainer/{print $3}' | xargs docker rmi -f || true
2127

2228
build-and-tag:
2329
- task: image-tag

start-ssh.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

start.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
#setup sshd
4+
mkdir -p /run/sshd
5+
ssh-keygen -A
6+
7+
export PORT1=${SSH_PORT:-2222}
8+
export PORT2=${OPENCODE_PORT:-2223}
9+
10+
# setup user
11+
export HOME=/home
12+
if test -n "$USERID"
13+
then
14+
useradd -u "$USERID" -d /home -o -U user -s /bin/bash
15+
ops -update
16+
git clone https://github.com/apache/openserverless-devcontainer $HOME/.ops/openserverless-devcontainer
17+
ln -sf $HOME/.ops/openserverless-devcontainer/olaris-tk $HOME/.ops/olaris-tk
18+
19+
if test -n "$SSHKEY"
20+
then
21+
mkdir -p $HOME/.ssh
22+
echo "$SSHKEY" >>$HOME/.ssh/authorized_keys
23+
chmod 600 ~/.ssh/authorized_keys
24+
fi
25+
chown -Rvf "$USERID" /home
26+
fi
27+
cd /workspace
28+
echo Starting ssh in port $PORT1 and opencode in $PORT2 for user $USERID
29+
concurrently \
30+
"sudo /usr/sbin/sshd -p $PORT1 -D" \
31+
"opencode serve -p $PORT2 --hostname 0.0.0.0"
32+

0 commit comments

Comments
 (0)