Skip to content
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

Exposed ARG not persisted while assigned to ENV #3359

Open
AlexanderB1290 opened this issue Nov 5, 2024 · 0 comments
Open

Exposed ARG not persisted while assigned to ENV #3359

AlexanderB1290 opened this issue Nov 5, 2024 · 0 comments

Comments

@AlexanderB1290
Copy link

AlexanderB1290 commented Nov 5, 2024

Actual behavior
Exposing and assigning TARGET* arguments to environment variables don't persist and are not part of scope while building an image.

Expected behavior
Exposing variables using ARG and than save them into ENV should persist during building. For example the following definition:

ARG TARGETOS
ENV TARGETOS=${TARGETOS}

Should resolve to the following output inside the image:

>echo "$TARGETOS"
linux

To Reproduce
Steps to reproduce the behavior:

  1. Expose build arguments related to target platform: TARGETOS, TARGETARCH, TARGETVARIANT in Dockerfile.
  2. Assign the arguments to environment variables with the same name using ENV.
ARG TARGETOS
ARG TARGETARCH
ENV TARGETOS=${TARGETOS} \
        TARGETARCH=${TARGETARCH}
  1. Use the defined environment variables inside a script or RUN directive.

Additional Information

  • Dockerfile
FROM pscoe-docker-dev-virtual.emea1.packages.broadcom.com/python:3.12-slim-bookworm AS ship

SHELL ["/bin/bash", "-c"]

### Expose Target Arguments
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
### Add Environemnt variables for Taget OS, Arch, Platform
ENV TARGETPLATFORM=${TARGETPLATFORM} \
   TARGETOS=${TARGETOS} \
   TARGETARCH=${TARGETARCH} \
   TARGETVARIANT=${TARGETVARIANT} \
   DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 \
   LC_ALL=C.UTF-8 \
   LANG=C.UTF-8
   
ADD install/*.sh ./
RUN chmod 755 ./*.sh \
   && apt update -y && apt install -y wget \
   && . /etc/os-release \
   && wget -O pwsh-prod.deb -q https://packages.microsoft.com/config/$ID/$VERSION_ID/packages-microsoft-prod.deb \
   && dpkg -i pwsh-prod.deb \
   && rm pwsh-prod.deb \
   && apt update -y && apt upgrade -y \
   && apt clean autoclean && apt autoremove -y

RUN ./install-all.sh
  • Build Context
    The following files are using during build of the image:
#!/bin/bash

# install/install-all.sh

SKIP_MSG="Skip installation of OVF tool."
echo "Target\n - OS: $TARGETOS\n - ARCH: $TARGETARCH\n - VARIANT: $TARGETVARIANT"

### -------------------------- Install PowerShell ------------------------------------------------------------------ ###
echo "Install PowerShell"
PWSH_VER="7.4.6"
PWSH_INSTALL="/opt/microsoft/powershell"

ARCH_SUFFIX="$TARGETARCH"
if [[ "$ARCH_SUFFIX" == *"amd"* && "$ARCH_SUFFIX" == *"64"* ]]; then
	ARCH_SUFFIX="x64"
fi

wget -O ./pwsh.tar.gz "https://github.com/PowerShell/PowerShell/releases/download/v$PWSH_VER/powershell-$PWSH_VER-$TARGETOS-$ARCH_SUFFIX.tar.gz" \
	&& mkdir -pv "$PWSH_INSTALL" \
	&& tar -zxvf ./pwsh.tar.gz -C "$PWSH_INSTALL" \
	&& chmod a+x "$PWSH_INSTALL"/pwsh \
	&& ln -s "$PWSH_INSTALL"/pwsh /usr/bin/pwsh \
	&& rm -rf ./pwsh.tar.gz

/usr/bin/pwsh -Command "Install-Module -Name VMware.PowerCLI -Force -Confirm:\$false -Scope AllUsers" | exit 1
/usr/bin/pwsh -Command "Install-Module -Name PSLogging -Force -Confirm:\$false -Scope AllUsers" | exit 1
/usr/bin/pwsh -Command "Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCEIP \$false -InvalidCertificateAction Ignore -DefaultVIServerMode Single -Confirm:\$false" | exit 1

### -------------------------- Install OVF Tool -------------------------------------------------------------------- ###
echo "Install OVF Tool"

OVFTOOL_BN="24031167"
OVFTOOL_VER="4.6.3"

OS_SHORT="$TARGETOS"
case "$TARGETOS" in
	*lin*) OS_SHORT="lin";;
	*win*) OS_SHORT="win";;
	*) echo "Unsupported OS: $TARGETOS. $SKIP_MSG" && exit 0;;
esac

ARCH_SHORT="$TARGETARCH"
case "$TARGETARCH" in
	*386*) ARCH_SHORT="i386";;
	*x86_*|*x64*|*amd*) ARCH_SHORT="x86_64";;
	*) echo "Unsupported architecture: $TARGETARCH. $SKIP_MSG" && exit 0;;
esac
  • Kaniko Image (fully qualified with digest)
    Image: gcr.io/kaniko-project/executor:v1.23.2-debug
# Command
/kaniko/executor --cleanup --insecure --skip-tls-verify \
--cache=true --cache-dir=/cache --context . \
--destination awx-runner:latest --no-push

Running the install script as part of the dockefile generates the following output:

INFO[0153] RUN ./install-all.sh                         
INFO[0153] Cmd: /bin/bash                               
INFO[0153] Args: [-c ./install-all.sh]                  
INFO[0153] Running: [/bin/bash -c ./install-all.sh]     
Target\n - OS: \n - ARCH: \n - VARIANT: 
Install PowerShell
--2024-11-05 13:30:25--  https://github.com/PowerShell/PowerShell/releases/download/v7.4.6/powershell-7.4.6--.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2024-11-05 13:30:25 ERROR 404: Not Found.
./install-all.sh: line 40: /usr/bin/pwsh: No such file or directory
./install-all.sh: line 41: /usr/bin/pwsh: No such file or directory
./install-all.sh: line 42: /usr/bin/pwsh: No such file or directory

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
Please check if the build works in docker but not in kaniko
Please check if this error is seen when you use --cache flag
Please check if your dockerfile is a multistage dockerfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant