diff --git a/actions/Dockerfile b/actions/Dockerfile new file mode 100644 index 00000000..d12d7f9a --- /dev/null +++ b/actions/Dockerfile @@ -0,0 +1,47 @@ +FROM golang:1.11.3-stretch + +# 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" +LABEL "com.github.actions.color"="blue" + +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 + +ADD entrypoint.sh /entrypoint.sh + +RUN mkdir -p /root/.docker && \ + echo {} > /root/.docker/config.json && \ + chmod u+x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/actions/README.md b/actions/README.md new file mode 100644 index 00000000..29ed114d --- /dev/null +++ b/actions/README.md @@ -0,0 +1,81 @@ +# Container Diff for Github Actions + +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: + +## Example 1: Run Container Diff + +Given an existing container on Docker Hub, we can run container diff +without doing any kind of build. + +``` +workflow "Run container-diff isolated" { + on = "push" + resolves = ["list"] +} + +action "Run container-diff" { + 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"] +} +``` + +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/actions/entrypoint.sh b/actions/entrypoint.sh new file mode 100644 index 00000000..e7b50a45 --- /dev/null +++ b/actions/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "$@" +/go/bin/container-diff ${@} diff --git a/test.sh b/test.sh index dd3d27cd..c1914803 100755 --- a/test.sh +++ b/test.sh @@ -35,7 +35,7 @@ fi # Ignore these paths in the following tests. -ignore="vendor\|out" +ignore="vendor\|out\|actions" # Check boilerplate echo "Checking boilerplate..."