Ability to parse args from Dockerfile

We should check if we have args in "FROM" and replace them:

ARG IMAGE=linuxkit/img
FROM ${IMAGE} as src

will be parsed as

FROM linuxkit/img as src

Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
This commit is contained in:
Petr Fedchenkov
2022-07-20 11:42:42 +03:00
parent 403e8f9353
commit 5763c4f4bc
7 changed files with 75 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
ARG IMAGE=alpine
ARG TAG=3.15
FROM ${IMAGE}:${TAG}
COPY foo /foo

View File

@@ -0,0 +1,5 @@
image: chained-build-with-args-image1-test-does-not-exist-anywhere-else-123456789 # this must be used as FROM in the chained image
network: true
arches:
- amd64
- arm64

View File

@@ -0,0 +1 @@
bar

View File

@@ -0,0 +1,7 @@
# those IMAGE and TAG *must* be updated when changing ../build1; just run `lkt pkg show-tag ../build1` and place it here
ARG IMAGE=linuxkit/chained-build-with-args-image1-test-does-not-exist-anywhere-else-123456789
ARG TAG=6a40ba0866b7ce18b3b13390bf88bfeb6ac0db4e
FROM ${IMAGE}:${TAG} as src
FROM alpine:3.15
COPY --from=src /foo /foo
RUN cat /foo

View File

@@ -0,0 +1,5 @@
image: chained-build-with-args-test-second
network: true
arches:
- amd64
- arm64

View File

@@ -0,0 +1,19 @@
#!/bin/sh
# SUMMARY: Check that chained builds support args
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
# Test code goes here
echo linuxkit is "$(which linuxkit)"
# build the first, use it to build the second
linuxkit pkg build --force ./build1
linuxkit pkg build --force ./build2
exit 0