From 690d7564321907b8ae013d11fd7393582876d59a Mon Sep 17 00:00:00 2001 From: Victor Sollerhed Date: Tue, 3 Oct 2023 14:26:52 +0200 Subject: [PATCH 1/3] Create GitHub action.yml As per docs: - https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions Signed-off-by: Victor Sollerhed --- action.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 00000000..15998629 --- /dev/null +++ b/action.yml @@ -0,0 +1,6 @@ +name: container-diff + +runs: + using: 'docker' + image: 'action/Dockerfile' + From f4bd67bcd3c92a0c2d3bf8d8cd4f2b257577b52d Mon Sep 17 00:00:00 2001 From: Victor Sollerhed Date: Tue, 3 Oct 2023 14:45:04 +0200 Subject: [PATCH 2/3] action.yml should input `argument` as arg to container-diff Signed-off-by: Victor Sollerhed --- action.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/action.yml b/action.yml index 15998629..62f483c6 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,14 @@ name: container-diff +inputs: + argument: + required: true + description: "String of arguments to pass to the container-diff command" + default: help + runs: using: 'docker' image: 'action/Dockerfile' + args: + - ${{ inputs.argument }} From d06e569c1f70e1fd138f9fd1e3244a2a24e5e0a3 Mon Sep 17 00:00:00 2001 From: vsoch Date: Tue, 10 Oct 2023 20:27:46 -0600 Subject: [PATCH 3/3] fix: add test for action and update readme Signed-off-by: vsoch --- .github/workflows/test-action.yaml | 24 ++++++++ actions/Dockerfile | 32 ++-------- actions/README.md | 99 +++++++++++------------------- action.yml => actions/action.yaml | 10 +-- actions/entrypoint.sh | 5 +- 5 files changed, 72 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/test-action.yaml rename action.yml => actions/action.yaml (58%) diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml new file mode 100644 index 00000000..2f29409f --- /dev/null +++ b/.github/workflows/test-action.yaml @@ -0,0 +1,24 @@ +name: Test container-diff Action + +on: + pull_request: [] + +jobs: + test-container-diff: + name: Test container-diff + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Add more test cases here as necessary + args: + - vanessa/salad --type=file --output=./data.json --json + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Run container-diff + uses: ./actions + with: + args: ${{ matrix.args }} + - name: View output + run: cat ./data.json diff --git a/actions/Dockerfile b/actions/Dockerfile index d12d7f9a..30e18368 100644 --- a/actions/Dockerfile +++ b/actions/Dockerfile @@ -1,25 +1,7 @@ -FROM golang:1.11.3-stretch +FROM debian:bookworm # docker build -f actions/Dockerfile -t googlecontainertools/container-diff . -RUN apt-get update && \ - apt-get install -y automake \ - libffi-dev \ - libxml2 \ - libxml2-dev \ - libxslt-dev \ - libxslt1-dev \ - git \ - gcc g++ \ - wget \ - locales - -RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ - locale-gen -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - LABEL "com.github.actions.name"="container-diff GitHub Action" LABEL "com.github.actions.description"="use Container-Diff in Github Actions Workflows" LABEL "com.github.actions.icon"="cloud" @@ -29,14 +11,10 @@ LABEL "repository"="https://www.github.com/GoogleContainerTools/container-diff" LABEL "homepage"="https://www.github.com/GoogleContainerTools/container-diff" LABEL "maintainer"="Google Inc." -# Install container-diff from master -RUN go get github.com/GoogleContainerTools/container-diff && \ - cd ${GOPATH}/src/github.com/GoogleContainerTools/container-diff && \ - go get && \ - make && \ - go install && \ - mkdir -p /code && \ - apt-get autoremove +# Install container-diff latest release +RUN apt-get update && apt-get install -y curl && \ + curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64 && \ + install container-diff-linux-amd64 /usr/local/bin/container-diff ADD entrypoint.sh /entrypoint.sh diff --git a/actions/README.md b/actions/README.md index 29ed114d..74eac4c3 100644 --- a/actions/README.md +++ b/actions/README.md @@ -4,78 +4,49 @@ This is a Github Action to allow you to run Container Diff in a [Github Actions](https://help.github.com/articles/about-github-actions/#about-github-actions) workflow. The intended use case is to build a Docker container from the repository, push it to Docker Hub, and then use container-diff to extract metadata for it that -you can use in other workflows (such as deploying to Github pages). In -the example below, we will show you how to build a container, push -to Docker Hub, and then container diff. Here is the entire workflow: +you can use in other workflows (such as deploying to Github pages). You can also run +container diff to extract metadata for a container you've just built locally in the action. -## Example 1: Run Container Diff +## 1. Action Parameters -Given an existing container on Docker Hub, we can run container diff -without doing any kind of build. +The action accepts the following parameters: -``` -workflow "Run container-diff isolated" { - on = "push" - resolves = ["list"] -} +| Name | Description | Type| Default | Required | +|------|-------------|-----|---------|----------| +| command | main command for container-diff | string | analyze | false | +| args | The full list of arguments to follow container-diff (see example below) | string | help | true | -action "Run container-diff" { - uses = "GoogleContainerTools/container-diff/actions@master" - args = ["analyze vanessa/salad --type=file --output=/github/workspace/data.json --json"] -} +See below for a simple example. Another interesting use case would be to generate metadata and upload +to an OCI registry using [OCI Registry As Storage](https://oras.land/). -action "list" { - needs = ["Run container-diff"] - uses = "actions/bin/sh@master" - runs = "ls" - args = ["/github/workspace"] -} +## 2. Run Container Diff + +Given an existing container on Docker Hub, we can run container diff +without doing any kind of build. + +```yaml +name: Run container-diff + +on: + pull_request: [] + +jobs: + container-diff: + name: Run container-diff + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Run container-diff + uses: GoogleContainerTools/container-diff/actions@master + with: + # Note this command is the default and does not need to be included + command: analyze + args: vanessa/salad --type=file --output=./data.json --json + - name: View output + run: cat ./data.json ``` In the above, we run container-diff to output apt and pip packages, history, and the filesystem for the container "vanessa/salad" that already exists on Docker Hub. We save the result to a data.json output file. The final step in the workflow (list) is a courtesy to show that the data.json file is generated. - -## Example 2: Build, Deploy, Run Container Diff - -This next example is slightly more complicated in that it will run container-diff -after a container is built and deployed from a Dockerfile present in the repository. - -``` -workflow "Run container-diff after deploy" { - on = "push" - resolves = ["Run container-diff"] -} - -action "build" { - uses = "actions/docker/cli@master" - args = "build -t vanessa/salad ." -} - -action "login" { - uses = "actions/docker/login@master" - secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] -} - -action "push" { - uses = "actions/docker/cli@master" - args = "push vanessa/salad" -} - -action "Run container-diff" { - needs = ["build", "login", "push"] - uses = "GoogleContainerTools/container-diff/actions@master" - args = ["analyze vanessa/salad --type=file --output=/github/workspace/data.json --json"] -} - -action "list" { - needs = ["Run container-diff"] - uses = "actions/bin/sh@master" - runs = "ls" - args = ["/github/workspace"] -} -``` - -The intended use case of the above would be to, whenever you update your -container, deploy its metadata to Github pages (or elsewhere). diff --git a/action.yml b/actions/action.yaml similarity index 58% rename from action.yml rename to actions/action.yaml index 62f483c6..4e497f30 100644 --- a/action.yml +++ b/actions/action.yaml @@ -1,14 +1,14 @@ name: container-diff inputs: - argument: + command: required: true + description: "Container diff command to use (defaults to analyze)" + default: analyze + args: description: "String of arguments to pass to the container-diff command" default: help runs: using: 'docker' - image: 'action/Dockerfile' - args: - - ${{ inputs.argument }} - + image: 'Dockerfile' diff --git a/actions/entrypoint.sh b/actions/entrypoint.sh index e7b50a45..a486bf44 100644 --- a/actions/entrypoint.sh +++ b/actions/entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/bash -echo "$@" -/go/bin/container-diff ${@} +command="${INPUT_COMMAND} ${INPUT_ARGS}" +echo "container-diff ${command}" +/usr/local/bin/container-diff ${command}