Skip to content

Commit

Permalink
Fix Devcontainer build errors (#4647)
Browse files Browse the repository at this point in the history
Devcontainer Dockerfile has been updated to use Ubuntu 24.04 as the
base. Now devcontainer builds without errors. Tested with Podman on
Linux and Docker Desktop on Windows.

To avoid re-downloading and re-compiling whenever the container is
deleted, a named volume is mounted at /home/ubuntu/.cache.

Closes #4065
  • Loading branch information
nirmal-j-patel authored Dec 17, 2024
1 parent 2eb1c7c commit b69f97d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
16 changes: 15 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@
{
"name": "carbon-lang",
"build": {
"dockerfile": "../docker/ubuntu2204/base/Dockerfile"
"dockerfile": "../docker/ubuntu2404/base/Dockerfile"
},
"mounts": [
{
"source": "carbon-cache",
"target": "/home/ubuntu/.cache",
"type": "volume"
}
],
"containerUser": "ubuntu",
"remoteUser": "ubuntu",
// When using devcontainer with podman, you may see /workspace being owned
// by root. To work around this, uncomment the following lines
// "runArgs": [
// "--userns=keep-id"
// ],
"customizations": {
"vscode": {
"extensions": [
Expand Down
12 changes: 6 additions & 6 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ ubuntu:22.04
Building the base image is required.

```
docker build -t carbon-ubuntu2204-base ./ubuntu2204/base
docker build -t carbon-ubuntu2404-base ./ubuntu2404/base
```

Build image using git repository

```bash
docker build -t carbon-ubuntu2204 ./ubuntu2204/github
docker build -t carbon-ubuntu2404 ./ubuntu2404/github
```

Build image using copy instruction

```bash
docker build -f ./ubuntu2204/Dockerfile -t carbon-ubuntu2204 ..
docker build -f ./ubuntu2404/Dockerfile -t carbon-ubuntu2404 ..
```

Run image

```bash
docker run carbon-ubuntu2204
docker run carbon-ubuntu2404
```

Run image using specific file

```bash
docker run carbon-ubuntu2204 bazel run //explorer -- ./explorer/testdata/print/format_only.carbon
docker run carbon-ubuntu2404 bazel run //explorer -- ./explorer/testdata/print/format_only.carbon
```

### Using a mounted volume
Expand All @@ -51,5 +51,5 @@ cd ..
```

```bash
docker run -w "/carbon-lang" -v "${PWD}:/carbon-lang" "carbon-ubuntu2204-base" bazel run "//explorer" -- "./explorer/testdata/print/format_only.carbon"
docker run -w "/carbon-lang" -v "${PWD}:/carbon-lang" "carbon-ubuntu2404-base" bazel run "//explorer" -- "./explorer/testdata/print/format_only.carbon"
```
4 changes: 2 additions & 2 deletions docker/ubuntu2204/Dockerfile → docker/ubuntu2404/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

FROM carbon-ubuntu2204-base as carbon-ubuntu2204-build
FROM carbon-ubuntu2404-base as carbon-ubuntu2404-build

COPY . /carbon-lang
WORKDIR /carbon-lang

# Build
RUN bazel build //explorer

FROM carbon-ubuntu2204-build
FROM carbon-ubuntu2404-build

CMD ["bazel", "run", "//explorer", "--", "./explorer/testdata/print/format_only.carbon"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

FROM ubuntu:22.04 as carbon-ubuntu2204-base
FROM ubuntu:24.04 as carbon-ubuntu2404-base

# Install apt tools:
# git: Used by VS Code.
Expand All @@ -16,9 +16,11 @@ RUN apt-get update && \
gnupg \
golang \
python3-pip \
python3.9 \
python3 \
software-properties-common \
wget
wget \
nodejs \
npm

ENV PATH="/root/go/bin:${PATH}"

Expand All @@ -32,13 +34,16 @@ RUN go install github.com/bazelbuild/buildtools/[email protected]
# Install LLVM from apt.llvm.org.
RUN wget https://apt.llvm.org/llvm.sh
RUN chmod +x llvm.sh
RUN ./llvm.sh 15 all
RUN ./llvm.sh 18 all
RUN rm llvm.sh

# Add the lib dir to the PATH. This helps Bazel find clang and VS Code find
# clangd, without version suffixes.
ENV PATH="/usr/lib/llvm-15/bin:${PATH}"
ENV PATH="/usr/lib/llvm-18/bin:${PATH}"

# Update pip and install black and pre-commit.
RUN pip3 install -U pip
RUN pip3 install black pre-commit
RUN pip3 install black pre-commit --break-system-packages

# Create .cache directory with proper ownership. We will mount a named volume
# at this location to allow caching of bazel build files.
RUN mkdir /home/ubuntu/.cache && chown -R ubuntu:ubuntu /home/ubuntu/.cache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

FROM carbon-ubuntu2204-base as carbon-ubuntu2204-github-build
FROM carbon-ubuntu2404-base as carbon-ubuntu2404-github-build

# Clone git repository
RUN git clone https://github.com/carbon-language/carbon-lang
Expand All @@ -15,6 +15,6 @@ RUN pre-commit install
# Build
RUN bazel build //explorer

FROM carbon-ubuntu2204-github-build
FROM carbon-ubuntu2404-github-build

CMD ["bazel", "run", "//explorer", "--", "./explorer/testdata/print/format_only.carbon"]

0 comments on commit b69f97d

Please sign in to comment.