Skip to content

Commit

Permalink
✨ Add feature for building an image without pushing it to a registry
Browse files Browse the repository at this point in the history
  • Loading branch information
elgohr committed Aug 29, 2020
1 parent 94e33a1 commit cc40c79
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 39 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
cache: ${{ github.event_name != 'schedule' }}
```

### no_push
Use `no_push` when you want to build an image, but not push it to a registry.

```yaml
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
no_push: ${{ github.event_name == 'push' }}
```

### Tags

This action supports multiple options that tags are handled.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ inputs:
tag_semver:
description: 'Push semver docker tags. e.g. image:1.2.3, image:1.2, image:1'
required: false
no_push:
description: 'Set no_push to true if you want to prevent the action from pushing to a registry (default: false)'
required: false
outputs:
tag:
description: 'Is the tag, which was pushed'
Expand Down
11 changes: 10 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ main() {
useSnapshot
fi

build

if usesBoolean "${INPUT_NO_PUSH}"; then
docker logout
exit 0
fi

push

echo "::set-output name=tag::${FIRST_TAG}"
Expand Down Expand Up @@ -160,13 +167,15 @@ useSnapshot() {
echo "::set-output name=snapshot-tag::${SNAPSHOT_TAG}"
}

push() {
build() {
local BUILD_TAGS=""
for TAG in ${TAGS}; do
BUILD_TAGS="${BUILD_TAGS}-t ${INPUT_NAME}:${TAG} "
done
docker build ${INPUT_BUILDOPTIONS} ${BUILDPARAMS} ${BUILD_TAGS} ${CONTEXT}
}

push() {
for TAG in ${TAGS}; do
docker push "${INPUT_NAME}:${TAG}"
done
Expand Down
Loading

0 comments on commit cc40c79

Please sign in to comment.