'How to prevent GitHub actions from always rebuilding my Dockerfile
I have an action.yml file and a Dockerfile in repository A like this:
Repository A
action.yml
[...]
runs:
using: 'docker'
image: 'Dockerfile'
[...]
Dockerfile
FROM hello-world
# do something
Now in repository B, I use the action and the Dockerfile:
Repository B
.github/workflows/hello.yml
name: hello
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: username/repoa@master
My point of using the Dockerfile in repository A is, among other things:
- that the GitHub action log is not cluttered with preparation steps which have no relation to the action in repository B
- so that it only builds when username/repoa is updated, not when username/repob is updated, because the Dockerfile didn't change.
However in practice, GitHub will happily rebuild the Dockerfile everytime I commit to username/repob and clutter the GitHub action logs with it.
How can I tell GitHub to only build the Dockerfile when repository A is updated and keep it out of the action logs?
Solution 1:[1]
Github Workflows create a new machine to run a job, this means that when Github Actions build your image, you need to store this image in a registry or something and use this stored image to create another step.
You need to improve your action.yml to build and store the image and create another action2.yml to say what to do with your container.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fguisso |
