0

I am trying to use a Concourse pipeline to pull a git repo and then build/push a Docker image from the dockerfile in the git repo. The dockerfile has a COPY command in it to copy files from the repo into the image. Normally I'd mount a volume to be able to COPY those files in at build time, but not finding a way to do that in Concourse. Here's what I'm trying:

# pipeline.yml
resources:  
  - name: git-repo
    type: git
    source:
      uri: <the-git-url>
      branch: master
      private_key: ((source-git-ssh-key))
  - name: my-image
    type: docker-image
    source:
      repository: gcr.io/path_to_image
      username: _json_key
      password: ((gcp-credential))

jobs:
  ...
      - get: git-repo
        trigger: true
      - put: my-image
        params:
          build: git-repo/compose



# dockerfile located at git-repo/compose/Dockerfile
FROM ...
...
# git-repo/scripts/run-script.sh
COPY scripts/run-script.sh /
...

How can I make the file git-repo/scripts/run-script.sh available to be copied into my image at build time? Thank you.

ZaxR
  • 4,896
  • 4
  • 23
  • 42

2 Answers2

1

I'm not familiar with Concourse, but as a rule with Docker you can only COPY things into your image that are contained in your build context (that is, they are in the build directory or a subdirectory of the build directory). From you configuration file...

      - put: my-image
        params:
          build: git-repo/compose

It looks like your build context is git-repo/compose. Since the script you want to include is outside of that directory (git-repo/scripts/run-script.sh), it's not going to be available during the build process.

The solution is to reorganize your git-repo. For example, you could:

  • Move the scripts/ directory into your compose/ directory.
  • Move the Dockerfile out of compose/ and into the main git-repo directory.
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks for the info - I found there's a solution wihtout reorganizing the repo (which is outside my control). I'll post it shortly – ZaxR Nov 21 '19 at 14:54
0

Found a way. The build context is assumed to be the base dir (e.g. git-repo/compose in the example). As a result, the files I wanted to copy in were outside the directory I had available. If your Dockerfile isn't in the root dir, you need to specify it in the dockerfile param if you still want access to the rest of the same/higher-level files. Working example:

  - put: my-image
    params:
      build: git-repo
      dockerfile: git-repo/compose/Dockerfile
ZaxR
  • 4,896
  • 4
  • 23
  • 42
  • That is pretty much what I suggested (making the main `git-repo` directory your build context). It's good that don't have to move the Dockerfile, but otherwise this is the same solution. – larsks Nov 21 '19 at 15:30