Skip to content

Commit

Permalink
feat: Add option for skip pushing if the digest hasn't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
aexvir committed Jun 19, 2020
1 parent c076596 commit 3b9302e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
FROM alpine as certs

RUN apk --update add ca-certificates

FROM gcr.io/kaniko-project/executor:debug

SHELL ["/busybox/sh", "-c"]

RUN mkdir -p /usr/local/bin && \
wget -O /usr/local/bin/jq \
https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && \
chmod +x /usr/local/bin/jq && \
wget -O /usr/local/bin/reg \
https://github.com/genuinetools/reg/releases/download/v0.16.1/reg-linux-386 && \
chmod +x /usr/local/bin/reg

COPY entrypoint.sh /
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

ENTRYPOINT ["/entrypoint.sh"]

Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ the most used values. So, technically there is a single required argument
## Optional Arguments
| variable | description | required | default |
|------------------|----------------------------------------------------------|----------|-----------------------------|
| registry | Docker registry where the image will be pushed | false | docker.io |
| username | Username used for authentication to the Docker registry | false | $GITHUB_ACTOR |
| password | Password used for authentication to the Docker registry | false | |
| tag | Image tag | false | latest |
| cache | Enables build cache | false | false |
| cache_ttl | How long the cache should be considered valid | false | |
| cache_registry | Docker registry meant to be used as cache | false | |
| cache_directory | Filesystem path meant to be used as cache | false | |
| build_file | Dockerfile filename | false | Dockerfile |
| extra_args | Additional arguments to be passed to the kaniko executor | false | |
| strip_tag_prefix | Prefix to be stripped from the tag | false | |
| variable | description | required | default |
|-----------------------|-----------------------------------------------------------------|----------|-----------------|
| registry | Docker registry where the image will be pushed | false | docker.io |
| username | Username used for authentication to the Docker registry | false | $GITHUB_ACTOR |
| password | Password used for authentication to the Docker registry | false | |
| tag | Image tag | false | latest |
| cache | Enables build cache | false | false |
| cache_ttl | How long the cache should be considered valid | false | |
| cache_registry | Docker registry meant to be used as cache | false | |
| cache_directory | Filesystem path meant to be used as cache | false | |
| build_file | Dockerfile filename | false | Dockerfile |
| extra_args | Additional arguments to be passed to the kaniko executor | false | |
| strip_tag_prefix | Prefix to be stripped from the tag | false | |
| skip_unchanged_digest | Avoids pushing the image if the build generated the same digest | false | |
**Here is where it gets specific, as the optional arguments become required depending on the registry targeted**
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ inputs:
extra_args:
description: "Additional arguments to be passed to the kaniko executor"
required: false
skip_unchanged_digest:
description: "Avoids pushing the image if the build generated the same digest"
required: false
runs:
using: "docker"
image: "Dockerfile"
24 changes: 21 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ export CACHE=$CACHE${INPUT_CACHE_REGISTRY:+" --cache-repo=$INPUT_CACHE_REGISTRY"
export CACHE=$CACHE${INPUT_CACHE_DIRECTORY:+" --cache-dir=$INPUT_CACHE_DIRECTORY"}
export CONTEXT="--context $GITHUB_WORKSPACE"
export DOCKERFILE="--dockerfile ${INPUT_BUILD_FILE:-Dockerfile}"
export DESTINATION="--destination $IMAGE"
export DESTINATION="--no-push"

export ARGS="$CACHE $CONTEXT $DOCKERFILE $DESTINATION $INPUT_EXTRA_ARGS"
echo $ARGS

cat <<EOF >/kaniko/.docker/config.json
{
Expand All @@ -61,4 +60,23 @@ cat <<EOF >/kaniko/.docker/config.json
}
EOF

/kaniko/executor $ARGS
/kaniko/executor --digest-file digest --reproducible $ARGS

export DIGEST=$(cat digest)
export REMOTE=$(reg digest "$IMAGE" | tail -1)

if [ ! -z $INPUT_SKIP_UNCHANGED_DIGEST ]; then
if [ "$DIGEST" == "$REMOTE" ]; then
echo "Digest hasn't changed, skipping, $DIGEST"
exit 0
fi
fi

export DESTINATION="--destination $IMAGE"
export ARGS="$CACHE $CONTEXT $DOCKERFILE $DESTINATION $INPUT_EXTRA_ARGS"

echo "Pushing image..."

/kaniko/executor --reproducible $ARGS >/dev/null 2>&1

echo "Done 🎉️"

0 comments on commit 3b9302e

Please sign in to comment.