Skip to content

Fix TDNF caching issues #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 70 additions & 70 deletions release/7-3/mariner2-arm64/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

FROM mcr.microsoft.com/cbl-mariner/base/core:2.0.20221222-arm64 AS installer-env

# Define Args for the needed to add the package
ARG PS_VERSION=7.3.1
ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-arm64.tar.gz
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE}
ARG PS_INSTALL_VERSION=7

# Define the folder we will be installing PowerShell to.
ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/${PS_INSTALL_VERSION}

# Create the install folder.
RUN mkdir -p ${PS_INSTALL_FOLDER}

ARG PS_PACKAGE_URL_BASE64

RUN --mount=type=cache,target=/var/cache/tdnf \
tdnf update -y \
&& tdnf install -y ca-certificates wget tar

RUN echo 'in task' \
&& if [ -n "${PS_PACKAGE_URL_BASE64}" ]; then \
echo 'using base64' \
&& export url=$(echo "${PS_PACKAGE_URL_BASE64}" | base64 --decode -); \
else \
echo 'using unencoded' \
&& export url="${PS_PACKAGE_URL}"; \
fi \
&& echo "url: $url" \
&& wget -O /tmp/powershell.tar.gz "$url" \
&& echo 'task done'

RUN ls -l /tmp/powershell.tar.gz

# Unzip the linux powershell.tar.gz
RUN tar zxf /tmp/powershell.tar.gz -C ${PS_INSTALL_FOLDER}

FROM mcr.microsoft.com/cbl-mariner/base/core:2.0.20221222-arm64 AS final-image

# Define Args and Env needed to create links
ARG PS_INSTALL_VERSION=7
ARG PS_VERSION=7.3.1

ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \
\
# Define ENVs for Localization/Globalization
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
# set a fixed location for the Module analysis cache
PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache \
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-arm64v7-Mariner-2

# Copy only the files we need from the previous stage
COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"]

RUN --mount=type=cache,target=/var/cache/tdnf,rw \
tdnf update -y \
&& tdnf install -y icu less openssh-clients ca-certificates dotnet-runtime-7.0 \
&& tdnf upgrade -y \
&& tdnf clean all

# Give all user execute permissions and remove write permissions for others
RUN chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \
# Create the pwsh symbolic link that points to powershell
&& ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh

# Use PowerShell as the default shell
# Use array to avoid Docker prepending /bin/sh -c
CMD [ "pwsh" ]
FROM --platform=linux/arm64 mcr.microsoft.com/cbl-mariner/base/core:2.0 AS installer-env

# Define Args for the needed to add the package
ARG PS_VERSION=7.3.1
ARG PS_PACKAGE=powershell-${PS_VERSION}-linux-arm64.tar.gz
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE}
ARG PS_INSTALL_VERSION=7

# Define the folder we will be installing PowerShell to.
ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/${PS_INSTALL_VERSION}

# Create the install folder.
RUN mkdir -p ${PS_INSTALL_FOLDER}

ARG PS_PACKAGE_URL_BASE64

RUN --mount=type=cache,target=/var/cache/tdnf \
tdnf update -y \
&& tdnf install -y ca-certificates wget tar

RUN echo 'in task' \
&& if [ -n "${PS_PACKAGE_URL_BASE64}" ]; then \
echo 'using base64' \
&& export url=$(echo "${PS_PACKAGE_URL_BASE64}" | base64 --decode -); \
else \
echo 'using unencoded' \
&& export url="${PS_PACKAGE_URL}"; \
fi \
&& echo "url: $url" \
&& wget -O /tmp/powershell.tar.gz "$url" \
&& echo 'task done'

RUN ls -l /tmp/powershell.tar.gz

# Unzip the linux powershell.tar.gz
RUN tar zxf /tmp/powershell.tar.gz -C ${PS_INSTALL_FOLDER}

FROM --platform=linux/arm64 mcr.microsoft.com/cbl-mariner/base/core:2.0 AS final-image

# Define Args and Env needed to create links
ARG PS_INSTALL_VERSION=7
ARG PS_VERSION=7.3.1

ENV PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \
\
# Define ENVs for Localization/Globalization
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
# set a fixed location for the Module analysis cache
PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache \
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-arm64v7-Mariner-2

# Copy only the files we need from the previous stage
COPY --from=installer-env ["/opt/microsoft/powershell", "/opt/microsoft/powershell"]

RUN --mount=type=cache,target=/var/cache/tdnf,rw \
tdnf update -y \
&& tdnf install -y icu less openssh-clients ca-certificates dotnet-runtime-7.0 \
&& tdnf upgrade -y \
&& tdnf clean all

# Give all user execute permissions and remove write permissions for others
RUN chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \
# Create the pwsh symbolic link that points to powershell
&& ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh

# Use PowerShell as the default shell
# Use array to avoid Docker prepending /bin/sh -c
CMD [ "pwsh" ]
4 changes: 2 additions & 2 deletions release/7-4/mariner2-arm64/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ FROM setup-tdnf-repa AS installer-env
# Download the Linux tar.gz and save it
ADD ${PS_PACKAGE_URL} /tmp/powershell.rpm

RUN --mount=type=cache,target=/var/cache/tdnf \
tdnf install -y \
# Don't use the cache mount since this image doesn't go into the final product and it causes issues with parralel operations with the next layer
RUN tdnf install -y \
wget \
awk \
tar \
Expand Down
5 changes: 3 additions & 2 deletions release/7-4/mariner2/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 AS setup-tdnf-repa

# Use the cache mount since this image does go into the final product
RUN --mount=type=cache,target=/var/cache/tdnf \
tdnf install -y mariner-repos-microsoft-preview \
&& tdnf makecache
Expand All @@ -20,8 +21,8 @@ FROM setup-tdnf-repa AS installer-env
# Download the Linux tar.gz and save it
ADD ${PS_PACKAGE_URL} /tmp/powershell.rpm

RUN --mount=type=cache,target=/var/cache/tdnf \
tdnf install -y \
# Don't use the cache mount since this image doesn't go into the final product and it causes issues with parralel operations with the next layer
RUN tdnf install -y \
wget \
awk \
tar \
Expand Down