From d1bb93033001683594bf8ae99e5587800d6c4e93 Mon Sep 17 00:00:00 2001 From: Helio Chissini de Castro Date: Sun, 3 Sep 2023 18:16:40 +0200 Subject: [PATCH] feat(docker): Add Rust component Signed-off-by: Helio Chissini de Castro --- .github/workflows/docker-ort-rust.yml | 87 +++++++++++++++++++++++++++ .ortversions/rust.versions | 1 + Dockerfile | 9 +-- scripts/docker_build.sh | 11 ++++ scripts/docker_snippets/rust.snippet | 9 +++ 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker-ort-rust.yml create mode 100644 .ortversions/rust.versions create mode 100644 scripts/docker_snippets/rust.snippet diff --git a/.github/workflows/docker-ort-rust.yml b/.github/workflows/docker-ort-rust.yml new file mode 100644 index 0000000000000..83f55dcda52b5 --- /dev/null +++ b/.github/workflows/docker-ort-rust.yml @@ -0,0 +1,87 @@ +# Copyright (C) 2023 The ORT Project Authors (see ) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# License-Filename: LICENSE + +name: Ort Docker Rust Container + +on: + workflow_run: + workflows: ["Ort Docker Base Image"] + workflow_dispatch: + push: + paths: + - '.ortversions/rust.versions' + - '.github/workflows/docker-ort-base.yml' + +env: + REGISTRY: ghcr.io + +permissions: write-all + +jobs: + build: + name: Build ORT Rust Image + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + + steps: + - name: Checkout main repository + uses: actions/checkout@v3 + + - name: Set environment variables + run: | + cat .ortversions/rust.versions >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract components metadata (tags, labels) for base image + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ github.repository }}/rust + tags: | + type=raw,value=${{ env.RUST_VERSION }} + + + - name: Build ORT Rust container + uses: docker/build-push-action@v4 + with: + context: . + target: rust + push: true + load: false + build-args: | + RUST_VERSION=${{ env.RUST_VERSION }} + tags: | + ${{ steps.meta.outputs.tags }} + ${{ env.REGISTRY }}/${{ github.repository }}/rust:latest + labels: ${{ steps.meta.outputs.labels }} + build-contexts: | + ort-base-image=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/base:latest + cache-from: type=gha,scope=ortrust + cache-to: type=gha,scope=ortrust,mode=max + diff --git a/.ortversions/rust.versions b/.ortversions/rust.versions new file mode 100644 index 0000000000000..4dca8f89f6020 --- /dev/null +++ b/.ortversions/rust.versions @@ -0,0 +1 @@ +RUST_VERSION=1.72.0 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 990772c816ecc..33e3cd2b3c0c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -233,10 +233,11 @@ COPY --from=rubybuild /opt/rbenv /opt/rbenv # RUST - Build as a separate component FROM ort-base-image AS rustbuild -ARG RUST_HOME=/opt/rust -ARG CARGO_HOME=$RUST_HOME/cargo -ARG RUSTUP_HOME=$RUST_HOME/rustup -ARG RUST_VERSION=1.64.0 +ARG RUST_VERSION=1.72.0 + +ENV RUST_HOME=/opt/rust +ENV CARGO_HOME=$RUST_HOME/cargo +ENV RUSTUP_HOME=$RUST_HOME/rustup RUN curl -ksSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION FROM scratch AS rust diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh index 5e6c3e4126b91..32ea31b6cf832 100755 --- a/scripts/docker_build.sh +++ b/scripts/docker_build.sh @@ -94,3 +94,14 @@ image_build run ort "$GIT_REVISION" \ --build-context "nodejs=docker-image://${DOCKER_IMAGE_ROOT}/nodejs:latest" \ --tag "ghcr.io/vwdfive/ort:latest" "$@" + +[ -z "$ALL_LANGUAGES" ] && exit 0 + +# Build adjacent language containers + +# Rust +# shellcheck disable=SC1091 +. .ortversions/rust.versions +image_build rust rust "$RUST_VERSION" \ + --build-arg RUST_VERSION="$RUST_VERSION" \ + "$@" diff --git a/scripts/docker_snippets/rust.snippet b/scripts/docker_snippets/rust.snippet new file mode 100644 index 0000000000000..27204c6163225 --- /dev/null +++ b/scripts/docker_snippets/rust.snippet @@ -0,0 +1,9 @@ +# Rust +ENV RUST_HOME=/opt/rust +ENV CARGO_HOME=$RUST_HOME/cargo +ENV RUSTUP_HOME=$RUST_HOME/rustup +ENV PATH=$PATH:$CARGO_HOME/bin:$RUSTUP_HOME/bin +COPY --from=ghcr.io/oss-review-toolkit/rust --chown=$USER:$USER $RUST_HOME $RUST_HOME +RUN chmod o+rwx $CARGO_HOME + +RUN syft $RUST_HOME -o spdx-json --file /usr/share/doc/ort/ort-rust.spdx.json \ No newline at end of file