question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

build-arg not support multiline variable

See original GitHub issue

Troubleshooting

I need to save a multiline variable to a file. But the result is a file with only one line. secrets.DEPLOY_KEY - multiline variable.

      - name: Build SCM container image
        uses: docker/build-push-action@v2
        with:
          push: true
          build-args: |
            VAULT_PASSWORD=${{ secrets.ANSIBLE_VAULT_PASSWORD }}
            PRIVATE_KEY=${{ secrets.DEPLOY_KEY }}

Dockerfile:

ARG VAULT_PASSWORD
ARG PRIVATE_KEY
ENV PASSWORD $VAULT_PASSWORD
ENV KEY $PRIVATE_KEY
...
RUN echo "$PASSWORD" > /etc/vault.txt && \
    chmod 0600 /etc/vault.txt
RUN echo "$KEY" > /root/.ssh/id_rsa && \
    chmod 0600 /root/.ssh/id_rsa

image

Expected behaviour

cat /root/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
...
...

Actual behaviour

cat /root/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----

One line only.

PS

Working version if done manually: https://github.com/concourse/docker-image-resource/issues/79#issuecomment-259812953

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
crazy-maxcommented, Jun 3, 2021

@k0st1an Like secrets, you need to place the key-value pair between quotes:

      - name: Build SCM container image
        uses: docker/build-push-action@v2
        with:
          push: true
          build-args: |
            "VAULT_PASSWORD=${{ secrets.ANSIBLE_VAULT_PASSWORD }}"
            "PRIVATE_KEY=${{ secrets.DEPLOY_KEY }}"
0reactions
mindflayercommented, Jun 3, 2021

Can you give me a link to your repo pls?

Nevermind, it was a false alarm and I am sorry for polluting the thread. Two problems at the same time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set Multiline Environment Variable with Dockerfile
I was able to get this working by passing the multiline environment variable as a build arg to docker build. Dockerfile
Read more >
Multiple lines variable in Build and Release
Some tasks have the textboxes that support multiple line content, such as Delete task, but multiple lines variable is not supported, it's better...
Read more >
Dockerfile reference - Docker Documentation
Environment variables are supported by the following list of instructions in the Dockerfile : ADD; COPY; ENV; EXPOSE; FROM; LABEL; STOPSIGNAL ...
Read more >
Using multiline strings in GitLab YML file
Using multiline strings in GitLab YML file. Sometimes your script is too long and it doesn't fit on one line:
Read more >
Add different condition in Dockerfile [5 Methods] | GoLinuxCloud
This means that the variable is accessible only while creating the docker image and NOT accessible for the docker container. Variable ENV: This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found