Parcourir la source

Add ubuntu:22.04 docker images (#1618)

Ubuntu 22.04 base image and examples using github, a copy instruction and volumes.

I was using this to run examples on a windows machine since it is more comfortable than switching OS or using the WSL subsystem directly.
If this is something that other people would like to have  I can add other versions of ubuntu and other linux distributions.
Nico Z il y a 3 ans
Parent
commit
4ea3e1951b

+ 1 - 1
.devcontainer/devcontainer.json

@@ -1,7 +1,7 @@
 {
 {
   "name": "carbon-lang",
   "name": "carbon-lang",
   "build": {
   "build": {
-    "dockerfile": "Dockerfile",
+    "dockerfile": "../docker/ubuntu2204/base/Dockerfile",
     "args": {
     "args": {
       "TAG": "3.5.6"
       "TAG": "3.5.6"
     }
     }

+ 55 - 0
docker/README.md

@@ -0,0 +1,55 @@
+# Docker
+
+<!--
+Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+Exceptions. See /LICENSE for license information.
+SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+-->
+
+ubuntu:22.04
+
+## Build and run image
+
+### Build
+
+Building the base image is required.
+
+```
+docker build -t carbon-ubuntu2204-base ./ubuntu2204/base
+```
+
+Build image using git repository
+
+```bash
+docker build -t carbon-ubuntu2004 ./ubuntu2204/github
+```
+
+Build image using copy instruction
+
+```bash
+docker build -f ./ubuntu2204/Dockerfile -t carbon-ubuntu2004 ..
+```
+
+Run image
+
+```bash
+docker run carbon-ubuntu2004
+```
+
+Run image using specific file
+
+```bash
+docker run carbon-ubuntu2004 bazel run //explorer -- ./explorer/testdata/print/format_only.carbon
+```
+
+### Using a mounted volume
+
+Run from the repository root for PWD.
+
+```
+cd ..
+```
+
+```bash
+docker run -w "/carbon-lang" -v "${PWD}:/carbon-lang" "carbon-ubuntu2004-base" bazel run "//explorer" -- "./explorer/testdata/print/format_only.carbon"
+```

+ 15 - 0
docker/ubuntu2204/Dockerfile

@@ -0,0 +1,15 @@
+# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+# Exceptions. See /LICENSE for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM carbon-ubuntu2204-base as carbon-ubuntu2204-build
+
+COPY . /carbon-lang
+WORKDIR /carbon-lang
+
+# Build
+RUN bazel build //explorer
+
+FROM carbon-ubuntu2204-build
+
+CMD ["bazel", "run", "//explorer", "--", "./explorer/testdata/print/format_only.carbon"]

+ 4 - 1
.devcontainer/Dockerfile → docker/ubuntu2204/base/Dockerfile

@@ -2,7 +2,7 @@
 # Exceptions. See /LICENSE for license information.
 # Exceptions. See /LICENSE for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 
-FROM ubuntu:22.04
+FROM ubuntu:22.04 as carbon-ubuntu2204-base
 
 
 # Install apt tools:
 # Install apt tools:
 #   git: Used by VS Code.
 #   git: Used by VS Code.
@@ -21,9 +21,11 @@ RUN apt-get update && \
   wget
   wget
 
 
 ENV PATH="/root/go/bin:${PATH}"
 ENV PATH="/root/go/bin:${PATH}"
+
 # Bazelisk is used for Carbon builds.
 # Bazelisk is used for Carbon builds.
 RUN go install github.com/bazelbuild/bazelisk@v1.14.0
 RUN go install github.com/bazelbuild/bazelisk@v1.14.0
 RUN ln -s /root/go/bin/bazelisk /root/go/bin/bazel
 RUN ln -s /root/go/bin/bazelisk /root/go/bin/bazel
+
 # Buildifier is used by the Bazel VS Code extension.
 # Buildifier is used by the Bazel VS Code extension.
 RUN go install github.com/bazelbuild/buildtools/buildifier@5.1.0
 RUN go install github.com/bazelbuild/buildtools/buildifier@5.1.0
 
 
@@ -32,6 +34,7 @@ RUN wget https://apt.llvm.org/llvm.sh
 RUN chmod +x llvm.sh
 RUN chmod +x llvm.sh
 RUN ./llvm.sh 15 all
 RUN ./llvm.sh 15 all
 RUN rm llvm.sh
 RUN rm llvm.sh
+
 # Add the lib dir to the PATH. This helps Bazel find clang and VS Code find
 # Add the lib dir to the PATH. This helps Bazel find clang and VS Code find
 # clangd, without version suffixes.
 # clangd, without version suffixes.
 ENV PATH="/usr/lib/llvm-15/bin:${PATH}"
 ENV PATH="/usr/lib/llvm-15/bin:${PATH}"

+ 20 - 0
docker/ubuntu2204/github/Dockerfile

@@ -0,0 +1,20 @@
+# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+# Exceptions. See /LICENSE for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+FROM carbon-ubuntu2204-base as carbon-ubuntu2204-github-build
+
+# Clone git repository
+RUN git clone https://github.com/carbon-language/carbon-lang
+
+WORKDIR /carbon-lang
+
+# Setup pre-commit
+RUN pre-commit install
+
+# Build
+RUN bazel build //explorer
+
+FROM carbon-ubuntu2204-github-build
+
+CMD ["bazel", "run", "//explorer", "--", "./explorer/testdata/print/format_only.carbon"]

+ 1 - 1
docs/project/contribution_tools.md

@@ -191,7 +191,7 @@ considering if they fit your workflow.
         -   After following the
         -   After following the
             [installation instructions](https://code.visualstudio.com/docs/remote/containers#_installation),
             [installation instructions](https://code.visualstudio.com/docs/remote/containers#_installation),
             you should be prompted to use Carbon's
             you should be prompted to use Carbon's
-            [devcontainer](/.devcontainer/Dockerfile) with "Reopen in
+            [devcontainer](/.devcontainer/devcontainer.json) with "Reopen in
             container".
             container".
 
 
 ### Manually building Clang and LLVM (not recommended)
 ### Manually building Clang and LLVM (not recommended)