Skip to content

Commit dcc72aa

Browse files
committedJul 6, 2022
feat: add support for building and running the cli in a docker container
1 parent 65bcf70 commit dcc72aa

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed
 

‎Dockerfile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM ubuntu:latest
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV PATH=/usr/local/CodeFlare/bin:$PATH
5+
6+
# TODO hard-coded arch
7+
ADD dist/electron/CodeFlare-linux-x64 /usr/local/CodeFlare
8+
9+
# Note, the `codeflare ...` commands are not strictly necessary. We do
10+
# them here only to save some time installing these prereqs on every
11+
# run.
12+
RUN apt update && apt -y install python3 python3-pip \
13+
&& apt -y clean && rm -rf /var/lib/apt/lists/* \
14+
&& codeflare util/jq \
15+
&& codeflare util/websocat \
16+
&& codeflare s3/install/cli \
17+
&& codeflare ml/ray/install/cli \
18+
&& codeflare kubernetes/kubectl \
19+
&& codeflare kubernetes/helm3 \
20+
&& adduser --disabled-password --gecos '' codeflare && adduser codeflare sudo && adduser root sudo && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
21+
&& touch /home/codeflare/.codeflare
22+
23+
ENTRYPOINT ["codeflare"]
24+
WORKDIR /home/codeflare
25+
USER codeflare
26+
27+
28+
29+
30+
# in case we want to use the published production versions at some point...
31+
#RUN export FILE=CodeFlare-linux-$([ "$(uname -m)" = "x86_64" ] && echo x64 || echo arm64) \
32+
# && apt update && apt -y install bash \
33+
# && curl -LO https://github.com/project-codeflare/codeflare-cli/releases/latest/download/$FILE.zip \
34+
# && unzip $FILE.zip \
35+
# && apt -y remove curl unzip && apt -y clean && rm -rf /var/lib/apt/lists/* \
36+
# && rm $FILE.zip \
37+
# && mv $FILE /usr/local/CodeFlare
38+

‎README.md

+35
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ brew tap project-codeflare/codeflare-cli https://github.com/project-codeflare/co
1717
brew install codeflare
1818
```
1919

20+
## Development
21+
22+
For codeflare-cli developers:
23+
24+
```shell
25+
git clone https://github.com/project-codeflare/codeflare-cli
26+
cd codeflare-cli
27+
npm ci
28+
npm run watch
29+
```
30+
31+
Now you may use `./bin/codeflare` to launch your local clone. The
32+
watcher will recompile things when you make changes to TypeScript or
33+
SCSS source files.
34+
35+
### Docker
36+
37+
If you want to build a Docker image, this command will build a
38+
production client (which takes around 30 seconds), and then build the
39+
Docker image (which takes another few minutes).
40+
41+
```shell
42+
npm run build:docker
43+
```
44+
45+
If you want to skip the first step, and only test building the Docker
46+
image, use `build:docker0`.
47+
48+
To test your image, try `./bin/codeflare -d`. If you want to debug the
49+
image itself, use `npm run docker:debug` which will get you a shell
50+
into a running container.
51+
52+
Limitations: the Docker build scripts are currently hard-wired to
53+
x86. PRs welcome to leverage `docker buildx` to build for ARM, etc.
54+
2055
## License
2156

2257
CodeFlare CLI is an open-source project with an [Apache 2.0 license](LICENSE).

‎bin/codeflare

+10-1
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,22 @@ fi
110110
# check if the user wants us to run the graphical version (currently
111111
# indicated by the -u option)
112112
do_cli=1
113-
while getopts "nVus:" opt
113+
use_docker=0
114+
while getopts "dnVus:" opt
114115
do
115116
case $opt in
117+
d) use_docker=1; continue;;
116118
u) do_cli=0; continue;;
117119
s) GUIDEBOOK_STORE=$OPTARG; continue;;
118120
*) EXTRAPREFIX="$EXTRAPREFIX -$opt"; continue;;
119121
esac
120122
done
121123
shift $((OPTIND-1))
122124

125+
if [ $use_docker = 1 ]; then
126+
exec docker run -it --entrypoint ${ENTRYPOINT-codeflare} --rm -v /tmp:/tmp -v ~/.aws:/home/codeflare/.aws -v ~/.bluemix:/home/codeflare/.bluemix -v ~/.kube:/home/codeflare/.kube -e KUBECONFIG=$(echo $KUBECONFIG | sed "s/$USER/codeflare/g" | sed 's/Users/home/g') projectcodeflare/codeflare-cli
127+
fi
128+
123129
if ([ $do_cli = 1 ] && [ $# = 0 ]) || ([ $# = 1 ] && [ "$1" != "version" ]); then
124130
# use the "guide" command if none was given
125131
EXTRAPREFIX="$EXTRAPREFIX guide"
@@ -164,5 +170,8 @@ if [ ! -f ~/.codeflare ] && [ $(uname) = Linux ]; then
164170
fi
165171
fi
166172

173+
# helps with ctrl+c when running in a docker container
174+
trap 'pkill -P $$; exit 1;' TERM INT
175+
167176
# otherwise, we launch the UI version
168177
"$NODE" "$HEADLESS"/codeflare.min.js -- $EXTRAPREFIX $*

‎package.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"pty:nodejs": "npm run pty:rebuild node",
2020
"prepare": "cross-env husky install",
2121
"preprod": "npm run mirror",
22+
"build:docker0": "docker build -t projectcodeflare/codeflare-cli .",
23+
"build:docker": "NO_INSTALLER=true npm run build:electron:linux:amd64 && npm run build:docker0",
24+
"docker:debug": "ENTRYPOINT=bash ./bin/codeflare -d",
2225
"build:electron:mac:amd64": "npm run preprod && KUI_HEADLESS_WEBPACK=true KUI_LAUNCHER=$PWD/bin/codeflare PLATFORM=mac ARCH=x64 kui-build-electron",
2326
"build:electron:mac:arm64": "npm run preprod && KUI_HEADLESS_WEBPACK=true KUI_LAUNCHER=$PWD/bin/codeflare PLATFORM=mac ARCH=arm64 kui-build-electron",
2427
"build:electron:osx:amd64": "npm run preprod && KUI_HEADLESS_WEBPACK=true KUI_LAUNCHER=$PWD/bin/codeflare npm run build:electron:mac:amd64",

0 commit comments

Comments
 (0)
Please sign in to comment.