wbrydak
wbrydak

Reputation: 11

Using envsubst with Dockerfile via Process Substitution breaks the build

I'm running into an issue whenever I'm trying to build my Docker image using the wrapper script that I've put in place to allow for in place ENV substitution with host environment variables.

Whenever I exceute my script I'm getting the error:

[+] Building 0.1s (2/2) FINISHED                                                                                                                                                                                                                                                      
 => [internal] load build definition from 63                                                                                                                                                                                                                                     0.1s
 => => transferring dockerfile: 47B                                                                                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                0.1s
 => => transferring context: 2B                                                                                                                                                                                                                                                  0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount2556703017/pipe:[1080734]: no such file or directory
Unable to find image 'my-image:latest' locally
docker: Error response from daemon: pull access denied for gotk-st24-test, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

Here's the wrapper script

#!/bin/env bash
# Make sure you have the appropriate token in your ENV variables on a machine that you're running this script on.
DOCKER_BUILDKIT=1 docker build --no-cache  -f <(envsubst < ./Dockerfile) -t "my-image" .
docker run -d -t my-image $1

And here's the Dockerfile:

FROM fluxcd/fluxctl:1.24.3 as builder

ARG ARCH=linux/amd64
ARG KUBECTL_VER=1.22.2
ARG GH_CLI_VER=2.2.0

RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
    -o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl

RUN curl -sL https://github.com/cli/cli/releases/download/v${GH_CLI_VER}/gh_${GH_CLI_VER}_linux_amd64.tar.gz \
    | tar xvz -C /tmp && mv /tmp/gh_${GH_CLI_VER}_linux_amd64/bin/gh /usr/local/bin/ && chmod +x /usr/local/bin/gh && \
    rm -rf /tmp/gh_*

FROM k8s.gcr.io/git-sync/git-sync:v3.3.5 as gitsync

FROM alpine:3.14 as gtk-cli

RUN apk update && apk add coreutils git
ENV GITHUB_TOKEN=$GITHUB_TOKEN

COPY --from=builder --chmod=755 /usr/local/bin/kubectl /usr/local/bin/
COPY --from=builder --chmod=755 /usr/local/bin/fluxctl /usr/local/bin/
COPY --from=builder --chmod=755 /usr/local/bin/gh /usr/local/bin/
COPY --from=gitsync --chmod=755 /git-sync /usr/local/bin/
COPY --chmod=755 ./ssh-entrypoint.sh /ssh-entrypoint.sh
COPY --chmod=755 ./docker-entrypoint.sh /docker-entrypoint.sh

RUN kubectl version --client=true && fluxctl version && gh version
WORKDIR /
ENTRYPOINT [ "/docker-entrypoint.sh" ]

I'd really appreciate some help here.

Thank you all in advance!

Upvotes: 0

Views: 1881

Answers (0)

Related Questions