diff --git a/ .dockerignore b/ .dockerignore new file mode 100644 index 00000000..9994ccdb --- /dev/null +++ b/ .dockerignore @@ -0,0 +1,2 @@ +build/ +.cache \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..bac7d0c6 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,54 @@ +name: docker +on: + release: + types: [created] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + PLATFORMS: linux/amd64,darwin/arm64 + +jobs: + build-and-publish: + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2.5.0 + with: + platforms: ${{ env.PLATFORMS }} + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4.3.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # https://stackoverflow.com/questions/71157844/how-can-i-copy-git-directory-to-the-container-with-github-actions + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v4.0.0 + with: + push: true + context: . + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ env.PLATFORMS }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..13004ed5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ + +FROM debian:13 AS builder + +# Installs System Dependencies +RUN apt-get update && apt-get install -y \ + ninja-build cmake build-essential curl gcc-14 g++-14 git + +# Installs LLVM 20 +RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | tee /usr/share/keyrings/llvm-snapshot.gpg.key && \ + echo "deb [signed-by=/usr/share/keyrings/llvm-snapshot.gpg.key] http://apt.llvm.org/trixie/ llvm-toolchain-trixie main" >> /etc/apt/sources.list && \ + echo "deb [signed-by=/usr/share/keyrings/llvm-snapshot.gpg.key] http://apt.llvm.org/trixie/ llvm-toolchain-trixie-20 main" >> /etc/apt/sources.list && \ + apt-get update && apt-get install -y \ + clang-20 lld-20 +RUN ln -s /usr/bin/lld-20 /usr/bin/lld + +# Adds source code +COPY include /app/include +COPY cmake /app/cmake +COPY src /app/src +COPY tests /app/tests +COPY CMakeLists.txt /app/CMakeLists.txt +COPY scripts /app/scripts + +WORKDIR /app +# Initializes and installs dependencies +RUN cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang-20 -DCMAKE_CXX_COMPILER=clang++-20 -DCMAKE_BUILD_TYPE=Release -DCLICE_ENABLE_TEST=ON +# Builds clice +RUN cmake --build build -j && \ + cmake --install build --prefix=/opt/clice + +FROM debian:13 + +COPY --from=builder /opt/clice /opt/clice/ +COPY LICENSE /opt/clice/LICENSE +COPY README.md /opt/clice/README.md + +RUN ln -s /opt/clice/bin/clice /usr/local/bin/clice + +ENTRYPOINT ["clice"] diff --git a/docs/en/dev/build.md b/docs/en/dev/build.md index 07b0ecbf..e7bb2ed5 100644 --- a/docs/en/dev/build.md +++ b/docs/en/dev/build.md @@ -147,3 +147,36 @@ $ pytest -s --log-cli-level=INFO tests/integration \ --executable=./build/linux/x86_64/debug/clice \ --resource-dir=./build/linux/x86_64/debug/lib/clang/20/ ``` + +## Building Docker Image + +Use the following command to build docker image: + +```bash +$ docker build -t clice . +``` + +Run docker image by running the following command: + +```bash +$ docker run --rm -it clice --help +OVERVIEW: clice is a new generation of language server for C/C++ +... +``` + +The directory structure of the docker image is as follows: + +``` +/opt/clice +├── bin +│ ├── clice -> /usr/local/bin/clice +├── include +├── lib +├── LICENSE +├── README.md +``` + +Hint: launch clice in the docker container by running the following command: + +```bash +$ docker run --rm -it --entrypoint bash clice diff --git a/docs/zh/dev/build.md b/docs/zh/dev/build.md index d2a4dc45..e0218de0 100644 --- a/docs/zh/dev/build.md +++ b/docs/zh/dev/build.md @@ -146,3 +146,35 @@ $ pytest -s --log-cli-level=INFO tests/integration \ --executable=./build/linux/x86_64/debug/clice \ --resource-dir=./build/linux/x86_64/debug/lib/clang/20/ ``` +## Building Docker Image + +使用以下命令构建 docker 镜像: + +```bash +$ docker build -t clice . +``` + +运行 docker 镜像: + +```bash +$ docker run --rm -it clice --help +OVERVIEW: clice is a new generation of language server for C/C++ +... +``` + +docker 镜像的目录结构如下: + +``` +/opt/clice +├── bin +│ ├── clice -> /usr/local/bin/clice +├── include +├── lib +├── LICENSE +├── README.md +``` + +提示:可以使用以下命令进入 clice 容器: + +```bash +$ docker run --rm -it --entrypoint bash clice