Skip to content
  •  
  •  
  •  
24 changes: 24 additions & 0 deletions .github/workflows/test-action.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dockerfile used to build a build step that builds container-diff in CI.
FROM golang:1.14
FROM golang:1.21
RUN apt-get update && apt-get install make
WORKDIR /workspace
32 changes: 5 additions & 27 deletions actions/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand Down
99 changes: 35 additions & 64 deletions actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
14 changes: 14 additions & 0 deletions actions/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: container-diff

inputs:
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: 'Dockerfile'
5 changes: 3 additions & 2 deletions actions/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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}
4 changes: 1 addition & 3 deletions differs/pip_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti
}
if config.Config.Env != nil {
paths := getPythonPaths(config.Config.Env)
for _, p := range paths {
pythonPaths = append(pythonPaths, p)
}
pythonPaths = append(pythonPaths, paths...)
}
pythonVersions, err := getPythonVersion(path)
if err != nil {
Expand Down
35 changes: 27 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
module github.com/GoogleContainerTools/container-diff

go 1.15
go 1.21

replace golang.org/x/sys => golang.org/x/sys v0.0.0-20190830141801-acfa387b8d69

require (
code.cloudfoundry.org/bytefmt v0.0.0-20180906201452-2aa6f33b730c
github.com/docker/distribution v0.0.0-20200319173657-742aab907b54 // indirect
github.com/docker/docker v1.4.2-0.20190219180918-740349757396
github.com/fsouza/go-dockerclient v1.3.6
github.com/gogo/protobuf v1.2.1 // indirect
github.com/google/go-containerregistry v0.0.0-20190214194807-bada66e31e55
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/morikuni/aec v1.0.0 // indirect
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/pkg/errors v0.8.1
github.com/pkg/profile v1.2.1
github.com/pmezard/go-difflib v1.0.0
github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
)

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.11 // indirect
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 // indirect
github.com/docker/distribution v0.0.0-20200319173657-742aab907b54 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/grpc v1.28.1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)
Loading