Skip to content

Commit

Permalink
feat: add pull-docker-image action
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Jan 19, 2023
1 parent 01613a1 commit 53a28b8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,36 @@ jobs using a registry.
- run: docker run ${{ steps.docker.outputs.tagged-image }}
```

#### pull-docker-image

[Source](pull-docker-image/action.yml)

Pulls and caches a docker image. Outputs the image name that was input to provide an easy way to not have to repeat the image name in the rest of your workflow.

##### Inputs

| Required | Name | Description | Example | Default |
|----------|-------------------|-----------------------------|--------------------|------------------|
| Yes | `image` | Image name | `my-name/my-image` ||
| No | `cache-directory` | Directory to store cache in | `/path/to/cache` | `/.docker-cache` |

##### Outputs

| Name | Description | Example |
|---------|-------------|--------------------|
| `image` | Image name | `my-name/my-image` |

##### Example

```yaml
- uses: myparcelnl/actions/pull-docker-image@v3
id: pull
with:
image: ghcr.io/myparcelnl/php-xd:7.4

- run: docker run ${{ steps.pull.outputs.image }}
```

### Releasing

#### semantic-release
Expand Down Expand Up @@ -421,7 +451,6 @@ Set up git credentials and authenticate as a [GitHub app].
| `git-name` | The name to use with git. | `my-app[bot]` |
| `git-email` | The email to use with git. | `my-app[bot]@users.noreply.github.com` |


#### rebase

[Source](rebase/action.yml)
Expand Down
40 changes: 40 additions & 0 deletions pull-docker-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Pull Docker image'
description: 'Pull Docker image from registry, or load it from cache.'

inputs:
image:
description: 'Image name'
required: true

cache-directory:
description: 'Directory to store cache in'
required: false
default: '/.docker-cache'

outputs:
image:
description: 'Image name'
value: ${{ inputs.image }}

runs:
using: composite
steps:
- uses: actions/cache@v3
id: docker-cache
with:
path: ${{ inputs.cache-directory }}
key: docker-cache-${{ runner.os }}

- name: 'Load cached Docker image'
if: steps.docker-cache.outputs.cache-hit == 'true'
shell: bash
run: |
docker load -i ${{ inputs.cache-directory }}/image.tar
- name: 'Pull Docker image'
if: steps.docker-cache.outputs.cache-hit != 'true'
shell: bash
run: |
docker pull ${{ inputs.image }}
mkdir -p ${{ inputs.cache-directory }}
docker save -o ${{ inputs.cache-directory }}/image.tar ${{ inputs.image }} }}

0 comments on commit 53a28b8

Please sign in to comment.