Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 6d827eb

Browse files
authored
Merge pull request #286 from vsoch/add/github-actions
Adding Github Action to run Container Diff
2 parents 616e266 + e642442 commit 6d827eb

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

actions/Dockerfile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM golang:1.11.3-stretch
2+
3+
# docker build -f actions/Dockerfile -t googlecontainertools/container-diff .
4+
5+
RUN apt-get update && \
6+
apt-get install -y automake \
7+
libffi-dev \
8+
libxml2 \
9+
libxml2-dev \
10+
libxslt-dev \
11+
libxslt1-dev \
12+
git \
13+
gcc g++ \
14+
wget \
15+
locales
16+
17+
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
18+
locale-gen
19+
ENV LANG en_US.UTF-8
20+
ENV LANGUAGE en_US:en
21+
ENV LC_ALL en_US.UTF-8
22+
23+
LABEL "com.github.actions.name"="container-diff GitHub Action"
24+
LABEL "com.github.actions.description"="use Container-Diff in Github Actions Workflows"
25+
LABEL "com.github.actions.icon"="cloud"
26+
LABEL "com.github.actions.color"="blue"
27+
28+
LABEL "repository"="https://www.github.com/GoogleContainerTools/container-diff"
29+
LABEL "homepage"="https://www.github.com/GoogleContainerTools/container-diff"
30+
LABEL "maintainer"="Google Inc."
31+
32+
# Install container-diff from master
33+
RUN go get github.com/GoogleContainerTools/container-diff && \
34+
cd ${GOPATH}/src/github.com/GoogleContainerTools/container-diff && \
35+
go get && \
36+
make && \
37+
go install && \
38+
mkdir -p /code && \
39+
apt-get autoremove
40+
41+
ADD entrypoint.sh /entrypoint.sh
42+
43+
RUN mkdir -p /root/.docker && \
44+
echo {} > /root/.docker/config.json && \
45+
chmod u+x /entrypoint.sh
46+
47+
ENTRYPOINT ["/entrypoint.sh"]

actions/README.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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).

actions/entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
echo "$@"
4+
/go/bin/container-diff ${@}

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fi
3535

3636

3737
# Ignore these paths in the following tests.
38-
ignore="vendor\|out"
38+
ignore="vendor\|out\|actions"
3939

4040
# Check boilerplate
4141
echo "Checking boilerplate..."

0 commit comments

Comments
 (0)