|
| 1 | +# Container Diff for Github Actions |
| 2 | + |
| 3 | +This is a Github Action to allow you to run Container Diff in a |
| 4 | +[Github Actions](https://help.github.com/articles/about-github-actions/#about-github-actions) |
| 5 | +workflow. The intended use case is to build a Docker container from the repository, |
| 6 | +push it to Docker Hub, and then use container-diff to extract metadata for it that |
| 7 | +you can use in other workflows (such as deploying to Github pages). In |
| 8 | +the example below, we will show you how to build a container, push |
| 9 | +to Docker Hub, and then container diff. Here is the entire workflow: |
| 10 | + |
| 11 | +## Example 1: Run Container Diff |
| 12 | + |
| 13 | +Given an existing container on Docker Hub, we can run container diff |
| 14 | +without doing any kind of build. |
| 15 | + |
| 16 | +``` |
| 17 | +workflow "Run container-diff isolated" { |
| 18 | + on = "push" |
| 19 | + resolves = ["list"] |
| 20 | +} |
| 21 | +
|
| 22 | +action "Run container-diff" { |
| 23 | + uses = "GoogleContainerTools/container-diff/actions@master" |
| 24 | + args = ["analyze vanessa/salad --type=file --output=/github/workspace/data.json --json"] |
| 25 | +} |
| 26 | +
|
| 27 | +action "list" { |
| 28 | + needs = ["Run container-diff"] |
| 29 | + uses = "actions/bin/sh@master" |
| 30 | + runs = "ls" |
| 31 | + args = ["/github/workspace"] |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +In the above, we run container-diff to output apt and pip packages, history, |
| 36 | +and the filesystem for the container "vanessa/salad" that already exists on |
| 37 | +Docker Hub. We save the result to a data.json output file. The final step in |
| 38 | +the workflow (list) is a courtesy to show that the data.json file is generated. |
| 39 | + |
| 40 | +## Example 2: Build, Deploy, Run Container Diff |
| 41 | + |
| 42 | +This next example is slightly more complicated in that it will run container-diff |
| 43 | +after a container is built and deployed from a Dockerfile present in the repository. |
| 44 | + |
| 45 | +``` |
| 46 | +workflow "Run container-diff after deploy" { |
| 47 | + on = "push" |
| 48 | + resolves = ["Run container-diff"] |
| 49 | +} |
| 50 | +
|
| 51 | +action "build" { |
| 52 | + uses = "actions/docker/cli@master" |
| 53 | + args = "build -t vanessa/salad ." |
| 54 | +} |
| 55 | +
|
| 56 | +action "login" { |
| 57 | + uses = "actions/docker/login@master" |
| 58 | + secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] |
| 59 | +} |
| 60 | +
|
| 61 | +action "push" { |
| 62 | + uses = "actions/docker/cli@master" |
| 63 | + args = "push vanessa/salad" |
| 64 | +} |
| 65 | +
|
| 66 | +action "Run container-diff" { |
| 67 | + needs = ["build", "login", "push"] |
| 68 | + uses = "GoogleContainerTools/container-diff/actions@master" |
| 69 | + args = ["analyze vanessa/salad --type=file --output=/github/workspace/data.json --json"] |
| 70 | +} |
| 71 | +
|
| 72 | +action "list" { |
| 73 | + needs = ["Run container-diff"] |
| 74 | + uses = "actions/bin/sh@master" |
| 75 | + runs = "ls" |
| 76 | + args = ["/github/workspace"] |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +The intended use case of the above would be to, whenever you update your |
| 81 | +container, deploy its metadata to Github pages (or elsewhere). |
0 commit comments