(fix) update Docker container scripts (#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>
This commit is contained in:
1
codex-cli/.dockerignore
Normal file
1
codex-cli/.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
@@ -4,22 +4,24 @@ ARG TZ
|
|||||||
ENV TZ="$TZ"
|
ENV TZ="$TZ"
|
||||||
|
|
||||||
# Install basic development tools and iptables/ipset
|
# Install basic development tools and iptables/ipset
|
||||||
RUN apt update && apt install -y less \
|
RUN apt update && apt install -y \
|
||||||
|
aggregate \
|
||||||
|
dnsutils \
|
||||||
|
fzf \
|
||||||
|
gh \
|
||||||
git \
|
git \
|
||||||
|
gnupg2 \
|
||||||
|
iproute2 \
|
||||||
|
ipset \
|
||||||
|
iptables \
|
||||||
|
jq \
|
||||||
|
less \
|
||||||
|
man-db \
|
||||||
procps \
|
procps \
|
||||||
sudo \
|
sudo \
|
||||||
fzf \
|
|
||||||
zsh \
|
|
||||||
man-db \
|
|
||||||
unzip \
|
unzip \
|
||||||
gnupg2 \
|
ripgrep \
|
||||||
gh \
|
zsh
|
||||||
iptables \
|
|
||||||
ipset \
|
|
||||||
iproute2 \
|
|
||||||
dnsutils \
|
|
||||||
aggregate \
|
|
||||||
jq
|
|
||||||
|
|
||||||
# Ensure default node user has access to /usr/local/share
|
# Ensure default node user has access to /usr/local/share
|
||||||
RUN mkdir -p /usr/local/share/npm-global && \
|
RUN mkdir -p /usr/local/share/npm-global && \
|
||||||
|
|||||||
@@ -1,3 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
docker build -t codex -f codex-cli/Dockerfile codex-cli
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(realpath "$(dirname "$0")")
|
||||||
|
trap "popd >> /dev/null" EXIT
|
||||||
|
pushd "$SCRIPT_DIR/.." >> /dev/null || {
|
||||||
|
echo "Error: Failed to change directory to $SCRIPT_DIR/.."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
rm -rf ./dist/openai-codex-*.tgz
|
||||||
|
npm pack --pack-destination ./dist
|
||||||
|
mv ./dist/openai-codex-*.tgz ./dist/codex.tgz
|
||||||
|
docker build -t codex -f "./Dockerfile" .
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./run_in_container.sh [--work_dir directory] "COMMAND"
|
# ./run_in_container.sh [--work_dir directory] "COMMAND"
|
||||||
@@ -8,7 +9,7 @@
|
|||||||
# ./run_in_container.sh "echo Hello, world!"
|
# ./run_in_container.sh "echo Hello, world!"
|
||||||
|
|
||||||
# Default the work directory to WORKSPACE_ROOT_DIR if not provided.
|
# Default the work directory to WORKSPACE_ROOT_DIR if not provided.
|
||||||
WORK_DIR="${WORKSPACE_ROOT_DIR}"
|
WORK_DIR="${WORKSPACE_ROOT_DIR:-$(pwd)}"
|
||||||
|
|
||||||
# Parse optional flag.
|
# Parse optional flag.
|
||||||
if [ "$1" = "--work_dir" ]; then
|
if [ "$1" = "--work_dir" ]; then
|
||||||
@@ -20,6 +21,8 @@ if [ "$1" = "--work_dir" ]; then
|
|||||||
shift 2
|
shift 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
WORK_DIR=$(realpath "$WORK_DIR")
|
||||||
|
|
||||||
# Ensure a command is provided.
|
# Ensure a command is provided.
|
||||||
if [ "$#" -eq 0 ]; then
|
if [ "$#" -eq 0 ]; then
|
||||||
echo "Usage: $0 [--work_dir directory] \"COMMAND\""
|
echo "Usage: $0 [--work_dir directory] \"COMMAND\""
|
||||||
@@ -33,14 +36,14 @@ if [ -z "$WORK_DIR" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove any existing container named 'codex'.
|
# Remove any existing container named 'codex'.
|
||||||
docker rm -f codex || true
|
docker rm -f codex 2>/dev/null || true
|
||||||
|
|
||||||
# Run the container with the specified directory mounted at the same path inside the container.
|
# Run the container with the specified directory mounted at the same path inside the container.
|
||||||
docker run --name codex -d \
|
docker run --name codex -d \
|
||||||
-e OPENAI_API_KEY \
|
-e OPENAI_API_KEY \
|
||||||
--cap-add=NET_ADMIN \
|
--cap-add=NET_ADMIN \
|
||||||
--cap-add=NET_RAW \
|
--cap-add=NET_RAW \
|
||||||
-v "$WORK_DIR:$WORK_DIR" \
|
-v "$WORK_DIR:/app$WORK_DIR" \
|
||||||
codex \
|
codex \
|
||||||
sleep infinity
|
sleep infinity
|
||||||
|
|
||||||
@@ -49,4 +52,9 @@ docker exec codex bash -c "sudo /usr/local/bin/init_firewall.sh"
|
|||||||
|
|
||||||
# Execute the provided command in the container, ensuring it runs in the work directory.
|
# Execute the provided command in the container, ensuring it runs in the work directory.
|
||||||
# We use a parameterized bash command to safely handle the command and directory.
|
# We use a parameterized bash command to safely handle the command and directory.
|
||||||
docker exec codex bash -c "cd \"$WORK_DIR\" && codex --dangerously-auto-approve-everything -q \"$@\""
|
|
||||||
|
quoted_args=""
|
||||||
|
for arg in "$@"; do
|
||||||
|
quoted_args+=" $(printf '%q' "$arg")"
|
||||||
|
done
|
||||||
|
docker exec -it codex bash -c "cd \"/app$WORK_DIR\" && codex --full-auto ${quoted_args}"
|
||||||
|
|||||||
Reference in New Issue
Block a user