-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
114 lines (103 loc) · 3.6 KB
/
Dockerfile
File metadata and controls
114 lines (103 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
FROM debian:13.3-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
ubuntu-keyring \
curl \
git \
bash \
ripgrep \
less \
jq \
tzdata \
build-essential \
npm \
node.js \
nano \
docker.cli \
ssh \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends \
python3-venv \
xclip\
xsel
ARG USERNAME=dev
ARG UID=1000
ARG GID=1000
ENV UID=${UID}
ENV GID=${GID}
RUN \
# Check if the GID already exists, if not create it
if ! getent group ${GID} >/dev/null; then \
groupadd -g ${GID} ${USERNAME}; \
else \
# If GID exists but with different name, use existing group
EXISTING_GROUP=$(getent group ${GID} | cut -d: -f1); \
echo "Using existing group: ${EXISTING_GROUP} (${GID})"; \
fi && \
# Check if the UID already exists, if not create the user
if ! getent passwd ${UID} >/dev/null; then \
useradd -m -u ${UID} -g ${GID} -s /bin/bash ${USERNAME}; \
else \
# If UID exists, check if it's the user we want
EXISTING_USER=$(getent passwd ${UID} | cut -d: -f1); \
if [ "${EXISTING_USER}" != "${USERNAME}" ]; then \
echo "User ${EXISTING_USER} already exists with UID ${UID}"; \
# Rename the existing user if it's 'ubuntu' and we want 'dev'
if [ "${EXISTING_USER}" = "ubuntu" ] && [ "${USERNAME}" = "dev" ]; then \
usermod -l ${USERNAME} ${EXISTING_USER}; \
groupmod -n ${USERNAME} ${EXISTING_USER} 2>/dev/null || true; \
usermod -d /home/${USERNAME} -m ${USERNAME} 2>/dev/null || true; \
fi; \
fi; \
fi
# ========================================
# Docker client support for running project tests from inside opencode
# ========================================
ARG DOCKER_GID=999
RUN \
if [ "${DOCKER_GID}" != "999" ]; then \
if ! getent group docker >/dev/null; then \
groupadd -g ${DOCKER_GID} docker; \
fi && \
usermod -aG docker ${USERNAME}; \
fi
# ========================================
# Install OpenCode from GitHub releases
# Automatically detects platform (amd64/arm64) and downloads the appropriate binary
# ========================================
ARG TARGETARCH
ARG OPENCODE_VERSION=latest
RUN ARCH="${TARGETARCH}" && \
if [ -z "${ARCH}" ]; then \
if command -v dpkg >/dev/null 2>&1; then \
ARCH=$(dpkg --print-architecture); \
else \
ARCH=$(uname -m); \
fi; \
fi && \
case "${ARCH}" in \
amd64|x86_64) ARCH="x64" ;; \
arm64|aarch64) ARCH="arm64" ;; \
esac && \
if [ -z "${ARCH}" ]; then \
echo "Unsupported architecture for OpenCode download" >&2; \
exit 1; \
fi && \
# Construct download URL based on version
if [ "${OPENCODE_VERSION}" = "latest" ]; then \
DOWNLOAD_URL="https://github.com/anomalyco/opencode/releases/latest/download/opencode-linux-${ARCH}.tar.gz"; \
else \
DOWNLOAD_URL="https://github.com/anomalyco/opencode/releases/download/v${OPENCODE_VERSION}/opencode-linux-${ARCH}.tar.gz"; \
fi && \
echo "Downloading OpenCode from: ${DOWNLOAD_URL}" && \
# Download and install
curl -fsSL "${DOWNLOAD_URL}" -o /tmp/opencode.tar.gz && \
tar -xzf /tmp/opencode.tar.gz -C /usr/local/bin && \
chmod 0755 /usr/local/bin/opencode && \
rm /tmp/opencode.tar.gz && \
# Verify installation
opencode --version
USER ${USERNAME}
RUN mkdir -p /home/${USERNAME}/.config/opencode/
RUN mkdir -p /home/${USERNAME}/.local/share/
WORKDIR /workspace