Skip to content

Commit 57f7900

Browse files
authored
feat: Initial Version of vscode DevContainer (#3217)
initial version of devcontainer --------- Signed-off-by: Dave Lee <[email protected]>
1 parent 5bb2321 commit 57f7900

File tree

9 files changed

+169
-27
lines changed

9 files changed

+169
-27
lines changed

.devcontainer/devcontainer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.schema.json",
3+
"name": "LocalAI",
4+
"workspaceFolder": "/workspace",
5+
"dockerComposeFile": [ "./docker-compose-devcontainer.yml" ],
6+
"service": "api",
7+
"shutdownAction": "stopCompose",
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"golang.go",
12+
"ms-vscode.makefile-tools",
13+
"ms-azuretools.vscode-docker",
14+
"ms-python.python",
15+
"ms-python.debugpy",
16+
"wayou.vscode-todo-highlight",
17+
"waderyan.gitblame"
18+
]
19+
}
20+
},
21+
"forwardPorts": [8080, 3000],
22+
"postStartCommand": "make prepare && cp /build/backend-assets /workdir/backend-assets"
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
services:
2+
api:
3+
build:
4+
context: ..
5+
dockerfile: Dockerfile
6+
target: devcontainer
7+
args:
8+
- FFMPEG=true
9+
- IMAGE_TYPE=extras
10+
- GO_TAGS=stablediffusion p2p tts
11+
env_file:
12+
- ../.env
13+
ports:
14+
- 8080:8080
15+
volumes:
16+
- ..:/workspace:cached
17+
command: /bin/sh -c "while sleep 1000; do :; done"
18+
cap_add:
19+
- SYS_PTRACE
20+
security_opt:
21+
- seccomp:unconfined
22+
prometheus:
23+
image: prom/prometheus
24+
container_name: prometheus
25+
command:
26+
- '--config.file=/etc/prometheus/prometheus.yml'
27+
ports:
28+
- 9090:9090
29+
restart: unless-stopped
30+
volumes:
31+
- ./prometheus:/etc/prometheus
32+
- prom_data:/prometheus
33+
grafana:
34+
image: grafana/grafana
35+
container_name: grafana
36+
ports:
37+
- 3000:3000
38+
restart: unless-stopped
39+
environment:
40+
- GF_SECURITY_ADMIN_USER=admin
41+
- GF_SECURITY_ADMIN_PASSWORD=grafana
42+
volumes:
43+
- ./grafana:/etc/grafana/provisioning/datasources
44+
volumes:
45+
prom_data:

.devcontainer/grafana/datasource.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
apiVersion: 1
3+
4+
datasources:
5+
- name: Prometheus
6+
type: prometheus
7+
url: http://prometheus:9090
8+
isDefault: true
9+
access: proxy
10+
editable: true
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
global:
2+
scrape_interval: 15s
3+
scrape_timeout: 10s
4+
evaluation_interval: 15s
5+
alerting:
6+
alertmanagers:
7+
- static_configs:
8+
- targets: []
9+
scheme: http
10+
timeout: 10s
11+
api_version: v1
12+
scrape_configs:
13+
- job_name: prometheus
14+
honor_timestamps: true
15+
scrape_interval: 15s
16+
scrape_timeout: 10s
17+
metrics_path: /metrics
18+
scheme: http
19+
static_configs:
20+
- targets:
21+
- localhost:9090

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
.github
33
.vscode
4+
.devcontainer
45
models
56
examples/chatbot-ui/models
67
examples/rwkv/models

.env

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
### Enable to run parallel requests
8080
# LOCALAI_PARALLEL_REQUESTS=true
8181

82+
# Enable to allow p2p mode
83+
# LOCALAI_P2P=true
84+
8285
### Watchdog settings
8386
###
8487
# Enables watchdog to kill backends that are inactive for too much time

.vscode/launch.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"configurations": [
44
{
55
"name": "Python: Current File",
6-
"type": "python",
6+
"type": "debugpy",
77
"request": "launch",
88
"program": "${file}",
99
"console": "integratedTerminal",
1010
"justMyCode": false,
11-
"cwd": "${workspaceFolder}/examples/langchain-chroma",
11+
"cwd": "${fileDirname}",
1212
"env": {
1313
"OPENAI_API_BASE": "http://localhost:8080/v1",
1414
"OPENAI_API_KEY": "abc"
@@ -19,15 +19,16 @@
1919
"type": "go",
2020
"request": "launch",
2121
"mode": "debug",
22-
"program": "${workspaceFolder}/main.go",
23-
"args": [
24-
"api"
25-
],
22+
"program": "${workspaceRoot}",
23+
"args": [],
2624
"env": {
27-
"C_INCLUDE_PATH": "${workspaceFolder}/go-llama:${workspaceFolder}/go-stable-diffusion/:${workspaceFolder}/gpt4all/gpt4all-bindings/golang/:${workspaceFolder}/go-gpt2:${workspaceFolder}/go-rwkv:${workspaceFolder}/whisper.cpp:${workspaceFolder}/go-bert:${workspaceFolder}/bloomz",
28-
"LIBRARY_PATH": "${workspaceFolder}/go-llama:${workspaceFolder}/go-stable-diffusion/:${workspaceFolder}/gpt4all/gpt4all-bindings/golang/:${workspaceFolder}/go-gpt2:${workspaceFolder}/go-rwkv:${workspaceFolder}/whisper.cpp:${workspaceFolder}/go-bert:${workspaceFolder}/bloomz",
29-
"DEBUG": "true"
30-
}
25+
"LOCALAI_LOG_LEVEL": "debug",
26+
"LOCALAI_P2P": "true",
27+
"LOCALAI_FEDERATED": "true"
28+
},
29+
"buildFlags": ["-tags", "stablediffusion p2p tts", "-v"],
30+
"envFile": "${workspaceFolder}/.env",
31+
"cwd": "${workspaceRoot}"
3132
}
3233
]
3334
}

Dockerfile

+55-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FROM ${BASE_IMAGE} AS requirements-core
88

99
USER root
1010

11-
ARG GO_VERSION=1.22.5
11+
ARG GO_VERSION=1.22.6
1212
ARG TARGETARCH
1313
ARG TARGETVARIANT
1414

@@ -30,7 +30,7 @@ RUN apt-get update && \
3030

3131
# Install Go
3232
RUN curl -L -s https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz | tar -C /usr/local -xz
33-
ENV PATH $PATH:/root/go/bin:/usr/local/go/bin
33+
ENV PATH=$PATH:/root/go/bin:/usr/local/go/bin
3434

3535
# Install grpc compilers
3636
RUN go install google.golang.org/protobuf/cmd/[email protected] && \
@@ -39,15 +39,18 @@ RUN go install google.golang.org/protobuf/cmd/[email protected] && \
3939
COPY --chmod=644 custom-ca-certs/* /usr/local/share/ca-certificates/
4040
RUN update-ca-certificates
4141

42+
RUN test -n "$TARGETARCH" \
43+
|| (echo 'warn: missing $TARGETARCH, either set this `ARG` manually, or run using `docker buildkit`')
44+
4245
# Use the variables in subsequent instructions
4346
RUN echo "Target Architecture: $TARGETARCH"
4447
RUN echo "Target Variant: $TARGETVARIANT"
4548

4649
# Cuda
47-
ENV PATH /usr/local/cuda/bin:${PATH}
50+
ENV PATH=/usr/local/cuda/bin:${PATH}
4851

4952
# HipBLAS requirements
50-
ENV PATH /opt/rocm/bin:${PATH}
53+
ENV PATH=/opt/rocm/bin:${PATH}
5154

5255
# OpenBLAS requirements and stable diffusion
5356
RUN apt-get update && \
@@ -62,9 +65,6 @@ RUN ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2
6265

6366
WORKDIR /build
6467

65-
RUN test -n "$TARGETARCH" \
66-
|| (echo 'warn: missing $TARGETARCH, either set this `ARG` manually, or run using `docker buildkit`')
67-
6868
###################################
6969
###################################
7070

@@ -217,28 +217,27 @@ RUN git clone --recurse-submodules --jobs 4 -b ${GRPC_VERSION} --depth 1 --shall
217217
###################################
218218
###################################
219219

220-
# The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
221-
# Adjustments to the build process should likely be made here.
222-
FROM requirements-drivers AS builder
220+
# The builder-base target has the arguments, variables, and copies shared between full builder images and the uncompiled devcontainer
221+
222+
FROM requirements-drivers AS builder-base
223223

224224
ARG GO_TAGS="stablediffusion tts p2p"
225225
ARG GRPC_BACKENDS
226226
ARG MAKEFLAGS
227+
ARG LD_FLAGS="-s -w"
227228

228229
ENV GRPC_BACKENDS=${GRPC_BACKENDS}
229230
ENV GO_TAGS=${GO_TAGS}
230231
ENV MAKEFLAGS=${MAKEFLAGS}
231232
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
232233
ENV NVIDIA_REQUIRE_CUDA="cuda>=${CUDA_MAJOR_VERSION}.0"
233234
ENV NVIDIA_VISIBLE_DEVICES=all
235+
ENV LD_FLAGS=${LD_FLAGS}
234236

235-
WORKDIR /build
237+
RUN echo "GO_TAGS: $GO_TAGS" && echo "TARGETARCH: $TARGETARCH"
236238

237-
COPY . .
238-
COPY .git .
239-
RUN echo "GO_TAGS: $GO_TAGS"
239+
WORKDIR /build
240240

241-
RUN make prepare
242241

243242
# We need protoc installed, and the version in 22.04 is too old. We will create one as part installing the GRPC build below
244243
# but that will also being in a newer version of absl which stablediffusion cannot compile with. This version of protoc is only
@@ -256,6 +255,20 @@ RUN <<EOT bash
256255
fi
257256
EOT
258257

258+
259+
###################################
260+
###################################
261+
262+
# The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
263+
# Adjustments to the build process should likely be made here.
264+
FROM builder-base AS builder
265+
266+
COPY . .
267+
COPY .git .
268+
269+
RUN make prepare
270+
271+
259272
# stablediffusion does not tolerate a newer version of abseil, build it first
260273
RUN GRPC_BACKENDS=backend-assets/grpc/stablediffusion make build
261274

@@ -276,6 +289,33 @@ RUN if [ ! -d "/build/sources/go-piper/piper-phonemize/pi/lib/" ]; then \
276289
###################################
277290
###################################
278291

292+
# The devcontainer target is not used on CI. It is a target for developers to use locally -
293+
# rather than copying files it mounts them locally and leaves building to the developer
294+
295+
FROM builder-base AS devcontainer
296+
297+
ARG FFMPEG
298+
299+
COPY --from=grpc /opt/grpc /usr/local
300+
301+
# This is somewhat of a dirty hack as this dev machine has issues with stablediffusion... but it should also speed up devcontainers?
302+
# localai/localai:latest-aio-cpu
303+
COPY --from=builder /build/backend-assets/grpc/stablediffusion /build/backend-assets/grpc/stablediffusion
304+
305+
# Add FFmpeg
306+
RUN if [ "${FFMPEG}" = "true" ]; then \
307+
apt-get update && \
308+
apt-get install -y --no-install-recommends \
309+
ffmpeg && \
310+
apt-get clean && \
311+
rm -rf /var/lib/apt/lists/* \
312+
; fi
313+
314+
RUN go install github.com/go-delve/delve/cmd/dlv@latest
315+
316+
###################################
317+
###################################
318+
279319
# This is the final target. The result of this target will be the image uploaded to the registry.
280320
# If you cannot find a more suitable place for an addition, this layer is a suitable place for it.
281321
FROM requirements-drivers

docker-compose.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.6'
2-
31
services:
42
api:
53
# See https://localai.io/basics/getting_started/#container-images for

0 commit comments

Comments
 (0)