Skip to content

Commit b6846ce

Browse files
eburke-openaiKyle Kosic
andauthored
(fix) update Docker container scripts (openai#47)
* Fix Docker container scripts Signed-off-by:: Eric Burke <eburke@openai.com> * Build codex TGZ * fix run_in_container --------- Co-authored-by: Kyle Kosic <kylekosic@openai.com>
1 parent 24e86da commit b6846ce

4 files changed

Lines changed: 42 additions & 18 deletions

File tree

codex-cli/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

codex-cli/Dockerfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ ARG TZ
44
ENV TZ="$TZ"
55

66
# Install basic development tools and iptables/ipset
7-
RUN apt update && apt install -y less \
7+
RUN apt update && apt install -y \
8+
aggregate \
9+
dnsutils \
10+
fzf \
11+
gh \
812
git \
13+
gnupg2 \
14+
iproute2 \
15+
ipset \
16+
iptables \
17+
jq \
18+
less \
19+
man-db \
920
procps \
1021
sudo \
11-
fzf \
12-
zsh \
13-
man-db \
1422
unzip \
15-
gnupg2 \
16-
gh \
17-
iptables \
18-
ipset \
19-
iproute2 \
20-
dnsutils \
21-
aggregate \
22-
jq
23+
ripgrep \
24+
zsh
2325

2426
# Ensure default node user has access to /usr/local/share
2527
RUN mkdir -p /usr/local/share/npm-global && \
@@ -44,4 +46,4 @@ USER root
4446
RUN chmod +x /usr/local/bin/init_firewall.sh && \
4547
echo "node ALL=(root) NOPASSWD: /usr/local/bin/init_firewall.sh" > /etc/sudoers.d/node-firewall && \
4648
chmod 0440 /etc/sudoers.d/node-firewall
47-
USER node
49+
USER node
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
#!/bin/bash
22

3-
docker build -t codex -f codex-cli/Dockerfile codex-cli
3+
set -euo pipefail
4+
5+
SCRIPT_DIR=$(realpath "$(dirname "$0")")
6+
trap "popd >> /dev/null" EXIT
7+
pushd "$SCRIPT_DIR/.." >> /dev/null || {
8+
echo "Error: Failed to change directory to $SCRIPT_DIR/.."
9+
exit 1
10+
}
11+
npm install
12+
npm run build
13+
rm -rf ./dist/openai-codex-*.tgz
14+
npm pack --pack-destination ./dist
15+
mv ./dist/openai-codex-*.tgz ./dist/codex.tgz
16+
docker build -t codex -f "./Dockerfile" .

codex-cli/scripts/run_in_container.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
# Usage:
45
# ./run_in_container.sh [--work_dir directory] "COMMAND"
@@ -8,7 +9,7 @@
89
# ./run_in_container.sh "echo Hello, world!"
910

1011
# Default the work directory to WORKSPACE_ROOT_DIR if not provided.
11-
WORK_DIR="${WORKSPACE_ROOT_DIR}"
12+
WORK_DIR="${WORKSPACE_ROOT_DIR:-$(pwd)}"
1213

1314
# Parse optional flag.
1415
if [ "$1" = "--work_dir" ]; then
@@ -20,6 +21,8 @@ if [ "$1" = "--work_dir" ]; then
2021
shift 2
2122
fi
2223

24+
WORK_DIR=$(realpath "$WORK_DIR")
25+
2326
# Ensure a command is provided.
2427
if [ "$#" -eq 0 ]; then
2528
echo "Usage: $0 [--work_dir directory] \"COMMAND\""
@@ -33,14 +36,14 @@ if [ -z "$WORK_DIR" ]; then
3336
fi
3437

3538
# Remove any existing container named 'codex'.
36-
docker rm -f codex || true
39+
docker rm -f codex 2>/dev/null || true
3740

3841
# Run the container with the specified directory mounted at the same path inside the container.
3942
docker run --name codex -d \
4043
-e OPENAI_API_KEY \
4144
--cap-add=NET_ADMIN \
4245
--cap-add=NET_RAW \
43-
-v "$WORK_DIR:$WORK_DIR" \
46+
-v "$WORK_DIR:/app$WORK_DIR" \
4447
codex \
4548
sleep infinity
4649

@@ -49,4 +52,9 @@ docker exec codex bash -c "sudo /usr/local/bin/init_firewall.sh"
4952

5053
# Execute the provided command in the container, ensuring it runs in the work directory.
5154
# We use a parameterized bash command to safely handle the command and directory.
52-
docker exec codex bash -c "cd \"$WORK_DIR\" && codex --dangerously-auto-approve-everything -q \"$@\""
55+
56+
quoted_args=""
57+
for arg in "$@"; do
58+
quoted_args+=" $(printf '%q' "$arg")"
59+
done
60+
docker exec -it codex bash -c "cd \"/app$WORK_DIR\" && codex --full-auto ${quoted_args}"

0 commit comments

Comments
 (0)