Skip to content

Commit 9a8a249

Browse files
authored
feat: devcontainer part 3 (#3318)
* stash initial fixes, attempt to open branch inside container Signed-off-by: Dave Lee <[email protected]> * add yq, from inside DC Signed-off-by: Dave Lee <[email protected]> * stash progress, rebuild container Signed-off-by: Dave Lee <[email protected]> * snap Signed-off-by: Dave Lee <[email protected]> * split builder into builder-sd, will speed up devcontainer build times and potentially help caching in other situations. Signed-off-by: Dave Lee <[email protected]> * fix yq Signed-off-by: Dave Lee <[email protected]> * fix paths Signed-off-by: Dave Lee <[email protected]> * fix paths - new folder to bypass the .dockerignore which _should_ exclude the other files Signed-off-by: Dave Lee <[email protected]> * fix Signed-off-by: Dave Lee <[email protected]> * fix ] Signed-off-by: Dave Lee <[email protected]> --------- Signed-off-by: Dave Lee <[email protected]>
1 parent dfa1835 commit 9a8a249

File tree

7 files changed

+82
-9
lines changed

7 files changed

+82
-9
lines changed

.devcontainer-scripts/postcreate.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
cd /workspace
4+
5+
# Get the files into the volume without a bind mount
6+
if [ ! -d ".git" ]; then
7+
git clone https://github.com/mudler/LocalAI.git .
8+
else
9+
git fetch
10+
fi
11+
12+
echo "Standard Post-Create script completed."
13+
14+
if [ -f "/devcontainer-customization/postcreate.sh" ]; then
15+
echo "Launching customization postcreate.sh"
16+
bash "/devcontainer-customization/postcreate.sh"
17+
fi

.devcontainer-scripts/poststart.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
cd /workspace
4+
5+
# Grab the pre-stashed backend assets to avoid build issues
6+
cp -r /build/backend-assets /workspace/backend-assets
7+
8+
# Ensures generated source files are present upon load
9+
make prepare
10+
11+
echo "Standard Post-Start script completed."
12+
13+
if [ -f "/devcontainer-customization/poststart.sh" ]; then
14+
echo "Launching customization poststart.sh"
15+
bash "/devcontainer-customization/poststart.sh"
16+
fi

.devcontainer/customization/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Place any additional resources your environment requires in this directory
2+
3+
Script hooks are currently called for:
4+
`postcreate.sh` and `poststart.sh`
5+
6+
If files with those names exist here, they will be called at the end of the normal script.
7+
8+
This is a good place to set things like `git config --global user.name` are set - and to handle any other files that are mounted via this directory.
9+
10+
An example of a useful script might be:
11+
12+
```
13+
#!/bin/bash
14+
gcn=$(git config --global user.name)
15+
if [ -z "$gcn" ]; then
16+
git config --global user.name YOUR.NAME
17+
git config --global user.email YOUR.EMAIL
18+
git remote add PREFIX FORK_URL
19+
fi
20+
```

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
}
2020
},
2121
"forwardPorts": [8080, 3000],
22-
"postCreateCommand": "git clone https://github.com/mudler/LocalAI.git .",
23-
"postStartCommand": "make prepare && cp -r /build/backend-assets /workspace/backend-assets"
22+
"postCreateCommand": "bash /.devcontainer-scripts/postcreate.sh",
23+
"postStartCommand": "bash /.devcontainer-scripts/poststart.sh"
2424
}

.devcontainer/docker-compose-devcontainer.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ services:
1414
- 8080:8080
1515
volumes:
1616
- localai_workspace:/workspace
17+
- ../models:/host-models
18+
- ./customization:/devcontainer-customization
1719
command: /bin/sh -c "while sleep 1000; do :; done"
1820
cap_add:
1921
- SYS_PTRACE

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ docs/static/gallery.html
5454

5555
# backend virtual environments
5656
**/venv
57+
58+
# per-developer customization files for the development container
59+
.devcontainer/customization/*

Dockerfile

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ EOT
260260
###################################
261261
###################################
262262

263-
# The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
264-
# Adjustments to the build process should likely be made here.
265-
FROM builder-base AS builder
263+
# This first portion of builder holds the layers specifically used to build backend-assets/grpc/stablediffusion
264+
# In most cases, builder is the image you should be using - however, this can save build time if one just needs to copy backend-assets/grpc/stablediffusion and nothing else.
265+
FROM builder-base AS builder-sd
266266

267267
COPY . .
268268
COPY .git .
@@ -273,6 +273,13 @@ RUN make prepare
273273
# stablediffusion does not tolerate a newer version of abseil, build it first
274274
RUN GRPC_BACKENDS=backend-assets/grpc/stablediffusion make build
275275

276+
###################################
277+
###################################
278+
279+
# The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
280+
# Adjustments to the build process should likely be made here.
281+
FROM builder-sd AS builder
282+
276283
# Install the pre-built GRPC
277284
COPY --from=grpc /opt/grpc /usr/local
278285

@@ -299,9 +306,9 @@ ARG FFMPEG
299306

300307
COPY --from=grpc /opt/grpc /usr/local
301308

302-
# This is somewhat of a dirty hack as this dev machine has issues with stablediffusion... but it should also speed up devcontainers?
303-
# localai/localai:latest-aio-cpu
304-
COPY --from=builder /build/backend-assets/grpc/stablediffusion /build/backend-assets/grpc/stablediffusion
309+
COPY --from=builder-sd /build/backend-assets/grpc/stablediffusion /build/backend-assets/grpc/stablediffusion
310+
311+
COPY .devcontainer-scripts /.devcontainer-scripts
305312

306313
# Add FFmpeg
307314
RUN if [ "${FFMPEG}" = "true" ]; then \
@@ -312,8 +319,16 @@ RUN if [ "${FFMPEG}" = "true" ]; then \
312319
rm -rf /var/lib/apt/lists/* \
313320
; fi
314321

322+
RUN apt-get update && \
323+
apt-get install -y --no-install-recommends \
324+
ssh less && \
325+
apt-get clean && \
326+
rm -rf /var/lib/apt/lists/*
327+
315328
RUN go install github.com/go-delve/delve/cmd/dlv@latest
316329

330+
RUN go install github.com/mikefarah/yq/v4@latest
331+
317332
###################################
318333
###################################
319334

@@ -367,7 +382,7 @@ COPY --from=builder /build/local-ai ./
367382
COPY --from=builder /build/sources/go-piper/piper-phonemize/pi/lib/* /usr/lib/
368383

369384
# do not let stablediffusion rebuild (requires an older version of absl)
370-
COPY --from=builder /build/backend-assets/grpc/stablediffusion ./backend-assets/grpc/stablediffusion
385+
COPY --from=builder-sd /build/backend-assets/grpc/stablediffusion ./backend-assets/grpc/stablediffusion
371386

372387
# Change the shell to bash so we can use [[ tests below
373388
SHELL ["/bin/bash", "-c"]

0 commit comments

Comments
 (0)