Skip to content

Commit

Permalink
feat(docker): Add Rust component
Browse files Browse the repository at this point in the history
Signed-off-by: Helio Chissini de Castro <heliocastro@gmail.com>
  • Loading branch information
heliocastro committed Sep 3, 2023
1 parent a7e904e commit d1bb930
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/docker-ort-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
#
# 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

1 change: 1 addition & 0 deletions .ortversions/rust.versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUST_VERSION=1.72.0
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
"$@"
9 changes: 9 additions & 0 deletions scripts/docker_snippets/rust.snippet
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d1bb930

Please sign in to comment.