Skip to content

Commit

Permalink
add rust and use COPY --link (#62)
Browse files Browse the repository at this point in the history
* add rust and use `COPY --link`

* fix linter issue
  • Loading branch information
mauwii authored Oct 13, 2023
1 parent 355eb2d commit 10c504f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"buildx",
"catthehacker",
"charmap",
"clippy",
"cmdline",
"codeowners",
"codeql",
Expand Down Expand Up @@ -115,11 +116,15 @@
"quickview",
"realpath",
"rubygems",
"rustc",
"rustfmt",
"rustup",
"sarif",
"semgrep",
"Sfrg",
"shellcheck",
"singlearch",
"skel",
"sphinxsearch",
"sshpass",
"startswith",
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ box with docker desktop).
When you do this from the main branch and already use the latest image, it will be replaced with
the one you just built.

If you are not using a mac silicon, just replace the platform `arm64` with `amd64`.

## mega-linter

To execute the mega-linter locally without the needs to install it, there are different options:
Expand Down
5 changes: 5 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ target "ubuntu" {
{
version = "22.04"
codename = "jammy"
CARGO_PACKAGES = "[\"bindgen-cli\",\"cbindgen\",\"cargo-audit\",\"cargo-outdated\"]"
DOTNET_CHANNEL = "LTS"
DOTNET_DEPS = "[\"libicu70\",\"libssl3\",\"libunwind8\",\"libgcc-s1\",\"liblttng-ust1\"]"
DOTNET_SDK_VERSION = "6.0.415"
Expand All @@ -92,6 +93,7 @@ target "ubuntu" {
{
version = "20.04"
codename = "focal"
CARGO_PACKAGES = "[\"--locked\",\"bindgen-cli\",\"cbindgen\",\"cargo-audit\",\"cargo-outdated\"]"
DOTNET_CHANNEL = "LTS"
DOTNET_DEPS = "[\"libicu66\",\"libssl1.1\"]"
DOTNET_SDK_VERSION = "6.0.415"
Expand All @@ -101,6 +103,8 @@ target "ubuntu" {
}
args = {
BICEP_VERSION = BICEP_VERSION
CARGO_HOME = "/etc/.skel/.cargo"
CARGO_PACKAGES = release.CARGO_PACKAGES
CODENAME = release.codename
DEPENDENCIES = DEPENDENCIES
DOTNET_CHANNEL = release.DOTNET_CHANNEL
Expand All @@ -115,6 +119,7 @@ target "ubuntu" {
POWERSHELL_MODULES = POWERSHELL_MODULES
POWERSHELL_VERSION = release.POWERSHELL_VERSION
PULUMI_VERSION = PULUMI_VERSION
RUSTUP_HOME = "/etc/.skel/.rustup"
TOOL_PATH_PWSH = "/usr/share/powershell"
}
name = "ubuntu-act-${release.codename}"
Expand Down
52 changes: 44 additions & 8 deletions linux/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN mkdir -p /tmp/go \
FROM base as pulumi
ARG TARGETARCH
SHELL [ "/bin/bash", "--login", "-e", "-o", "pipefail", "-c" ]
COPY --from=golang /usr/local/go /usr/local/go
COPY --link --from=golang /usr/local/go /usr/local/go
ENV PATH=/usr/local/go/bin:${PATH}
ARG PULUMI_VERSION=3.83.0
RUN curl -fsSL https://get.pulumi.com \
Expand All @@ -64,6 +64,31 @@ RUN export targetarch="${TARGETARCH}" \
&& mv ./bicep /usr/local/bin/bicep \
&& bicep --version

FROM base as rust
ARG TARGETARCH
SHELL [ "/bin/bash", "--login", "-e", "-o", "pipefail", "-c" ]
ARG RUSTUP_HOME=/etc/skel/.rustup
ARG CARGO_HOME=/etc/skel/.cargo
ENV PATH=${CARGO_HOME}/bin:${PATH}
ARG CARGO_PACKAGES
RUN apt-get -y update \
&& apt-get -y install --no-install-recommends \
jq \
&& curl -fsSL https://sh.rustup.rs | sh -s -- -y \
--default-toolchain=stable \
--profile=minimal \
--no-modify-path \
&& rustup --version \
&& cargo --version \
&& rustc --version \
&& rustup component add rustfmt clippy \
&& cargo_tools=() \
&& while IFS='' read -r pkg; do cargo_tools+=("$pkg"); done < <(printf "%s\n" "${CARGO_PACKAGES}" | jq -r '.[]') \
&& cargo install "${cargo_tools[@]}" \
&& apt-get clean \
&& rm -rf /etc/apt/sources.list.d/* \
&& rm -rf /var/lib/apt/lists/*

FROM base as act-base

# automatic buildx ARGs
Expand Down Expand Up @@ -292,7 +317,6 @@ RUN dotnet tool install \
&& ln -s "$(realpath --relative-to=/usr/local/bin "${TOOL_PATH_PWSH}")/pwsh" /usr/local/bin/pwsh \
&& chmod 755 "${TOOL_PATH_PWSH}/pwsh" \
&& [[ "$(pwsh --version)" =~ ${POWERSHELL_VERSION} ]]
# && pwsh -NonInteractive -Command "Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers" \

# kics-scan ignore-line
FROM act-powershell as act-powershell-modules
Expand Down Expand Up @@ -323,24 +347,36 @@ SHELL [ "/bin/bash", "--login", "-e", "-o", "pipefail", "-c" ]
WORKDIR /tmp

# add go
COPY --from=golang /usr/local/go /usr/local/go
COPY --link --from=golang /usr/local/go /usr/local/go
ENV PATH=/usr/local/go/bin:${PATH}
RUN sed "s|^PATH=|PATH=/usr/local/go/bin:|mg" -i /etc/environment

# add pulumi
COPY --from=pulumi /root/.pulumi/bin /usr/local/bin/
COPY --link --from=pulumi /root/.pulumi/bin /usr/local/bin/

# add bicep
COPY --from=bicep /usr/local/bin/bicep /usr/local/bin/bicep
COPY --link --from=bicep /usr/local/bin/bicep /usr/local/bin/bicep

# add rust
ARG CARGO_HOME=/etc/skel/.cargo
COPY --link --from=rust ${CARGO_HOME} ${CARGO_HOME}
ARG RUSTUP_HOME=/etc/skel/.rustup
COPY --link --from=rust ${RUSTUP_HOME} ${RUSTUP_HOME}
ENV PATH=${CARGO_HOME}/bin:${PATH} \
CARGO_HOME=${CARGO_HOME} \
RUSTUP_HOME=${RUSTUP_HOME}
RUN sed "s|^PATH=|PATH=${CARGO_HOME}/bin:|mg" -i /etc/environment \
&& echo "CARGO_HOME=${CARGO_HOME}" | tee -a /etc/environment \
&& echo "RUSTUP_HOME=${RUSTUP_HOME}" | tee -a /etc/environment

# add PowerShell
ARG TOOL_PATH_PWSH=/usr/share/powershell
COPY --from=act-powershell ${TOOL_PATH_PWSH} ${TOOL_PATH_PWSH}
COPY --link --from=act-powershell ${TOOL_PATH_PWSH} ${TOOL_PATH_PWSH}
RUN ln -s "$(realpath --relative-to=/usr/local/bin "${TOOL_PATH_PWSH}")/pwsh" /usr/local/bin/pwsh

# add PowerShell-modules
COPY --from=act-powershell-modules /usr/local/share/powershell /usr/local/share/powershell
COPY --from=act-powershell-az-modules /usr/local/share/powershell /usr/local/share/powershell
COPY --link --from=act-powershell-modules /usr/local/share/powershell /usr/local/share/powershell
COPY --link --from=act-powershell-az-modules /usr/local/share/powershell /usr/local/share/powershell

ARG RUNNER
USER ${RUNNER}
Expand Down

0 comments on commit 10c504f

Please sign in to comment.