launchrctl / launchr

Launchr is a CLI action runner that executes actions inside short-lived local containers.
Apache License 2.0
11 stars 2 forks source link

User uid gid works when passed to Dockerfile using ARG but not ENV #7

Closed davidferlay closed 10 months ago

davidferlay commented 10 months ago

Context

Observed

action.yaml:

action:
  title: Compare artifact
  description: Get expected artifact to compare current one and generate diff file
  arguments:
    - name: username
      title: Username
      description: The username to get comparison artifact with
    - name: password
      title: Username
      description: The password to get comparison artifact with
  options:
    - name: override
      title: Overriden comparison reference (branch or tag name)
  image: platform-actions-compare-artifact:latest
  build:
    context: ./
    args:
      USER_ID: {{.current_uid }}
      GROUP_ID: {{.current_gid}}
    tags:
      - platform-actions-compare-artifact:latest
      - platform-actions-compare-artifact:1.0.0
  command:
    - sh
    - /action/x.sh
    - "{{.username}}"
    - "{{.password}}"
    - "{{.override}}"

Dockerfile:

FROM alpine:3.18
WORKDIR /host
ARG USER_ID
ARG GROUP_ID
RUN echo ${USER_ID}
RUN echo ${GROUP_ID}
RUN adduser -D -u $USER_ID -g $GROUP_ID plasma || true
USER plasma

action.yaml:

action:
  title: Compare artifact
  description: Get expected artifact to compare current one and generate diff file
  arguments:
    - name: username
      title: Username
      description: The username to get comparison artifact with
    - name: password
      title: Username
      description: The password to get comparison artifact with
  options:
    - name: override
      title: Overriden comparison reference (branch or tag name)
  image: platform-actions-compare-artifact:latest
  build:
    context: ./
    env:
      USER_ID: {{.current_uid }}
      GROUP_ID: {{.current_gid}}
    tags:
      - platform-actions-compare-artifact:latest
      - platform-actions-compare-artifact:1.0.0
  command:
    - sh
    - /action/x.sh
    - "{{.username}}"
    - "{{.password}}"
    - "{{.override}}"

Dockerfile:

FROM alpine:3.18
WORKDIR /host
RUN echo ${USER_ID}
RUN echo ${GROUP_ID}
RUN adduser -D -u $USER_ID -g $GROUP_ID plasma || true
USER plasma

Expected

davidferlay commented 10 months ago

Fixed by moving env: outside of build:

cf https://github.com/launchrctl/launchr/blob/main/example/envvars/action.yaml