How to prevent Dockerfile caching git clone

后端 未结 7 599
忘了有多久
忘了有多久 2020-11-30 08:19

I have a Dockerfile trying to package and deploy a web app to a container. The code of app fetches from git repository during Docker image building. Here\'s the Dockerfile s

7条回答
  •  感情败类
    2020-11-30 09:10

    Another workaround:

    If you use GitHub (or gitlab or bitbucket too most likely) you can ADD the GitHub API's representation of your repo to a dummy location.

    ADD https://api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH version.json
    RUN git clone -b $BRANCH https://github.com/$USER/$REPO.git $GIT_HOME/
    

    The API call will return different results when the head changes, invalidating the docker cache.

    If you're dealing with private repos you can use github's x-oauth-basic authentication scheme with a personal access token like so:

    ADD https://$ACCESS_TOKEN:x-oauth-basic@api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH version.json
    

    (thx @captnolimar for a suggested edit to clarify authentication)

提交回复
热议问题