🐛 Extract contents of directory (#4)

This commit is contained in:
Samuel Ryan 2020-09-06 18:47:06 +01:00 committed by GitHub
parent 0f83fca17f
commit 7d86f1b9ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 59 deletions

11
.github/tests/Dockerfile vendored Normal file
View file

@ -0,0 +1,11 @@
FROM alpine
RUN mkdir -p /files/x
RUN mkdir -p /files/y
RUN echo "Hello, World 1! \$(date)" > /files/001.txt
RUN echo "Hello, World 2! \$(date)" > /files/002.txt
RUN echo "Hello, World 3! \$(date)" > /files/003.txt
RUN echo "Hello, World 4! \$(date)" > /files/x/004.txt
RUN echo "Hello, World 5! \$(date)" > /files/x/005.txt
RUN echo "Hello, World 6! \$(date)" > /files/y/006.txt

48
.github/workflows/directory.yml vendored Normal file
View file

@ -0,0 +1,48 @@
name: Test Directory Extraction
on: [push]
jobs:
root-directory:
runs-on: ubuntu-latest
name: Extract Contents of Directory from Example Image
steps:
- uses: actions/checkout@v2
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
with:
image: example:${{ github.sha }}
path: /files/.
- run: test -e ${{ steps.extract.outputs.destination }}/001.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/002.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/003.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/x/004.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/x/005.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/y/006.txt || exit 1
nested-directory:
runs-on: ubuntu-latest
name: Extract Nested Directory from Example Image
steps:
- uses: actions/checkout@v2
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
with:
image: example:${{ github.sha }}
path: /files/x
- run: test -e ${{ steps.extract.outputs.destination }}/x/004.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/x/005.txt || exit 1
nested-directory-contents:
runs-on: ubuntu-latest
name: Extract Nested Contents of Directory from Example Image
steps:
- uses: actions/checkout@v2
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
with:
image: example:${{ github.sha }}
path: /files/x/.
- run: test -e ${{ steps.extract.outputs.destination }}/004.txt || exit 1
- run: test -e ${{ steps.extract.outputs.destination }}/005.txt || exit 1

29
.github/workflows/file.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Test File Extraction
on: [push]
jobs:
root-file:
runs-on: ubuntu-latest
name: Extract Example File From Root of Built Image
steps:
- uses: actions/checkout@v2
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
with:
image: example:${{ github.sha }}
path: /files/001.txt
- run: test -e ${{ steps.extract.outputs.destination }}/001.txt || exit 1
nested-file:
runs-on: ubuntu-latest
name: Extract Nexted Example File From Built Image
steps:
- uses: actions/checkout@v2
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
with:
image: example:${{ github.sha }}
path: /files/y/006.txt
- run: test -e ${{ steps.extract.outputs.destination }}/006.txt || exit 1

View file

@ -1,50 +0,0 @@
name: Test Extraction Action
on: [push]
jobs:
extract-motd:
runs-on: ubuntu-latest
name: Extract MOTD From Alpine
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Extract
id: extract
uses: ./
with:
image: 'alpine'
path: '/etc/motd'
- name: Upload Extracted MOTD
uses: actions/upload-artifact@v2
with:
path: ${{ steps.extract.outputs.destination }}/motd
name: alpine-motd
example:
runs-on: ubuntu-latest
name: Extract Example From Built Image
steps:
- uses: actions/checkout@v2
- name: Create Example Dockerfile
run: |
cat <<-DOCKERFILE > Dockerfile
FROM alpine
RUN mkdir -p /app
RUN echo "Hello, World! \$(date)" > /app/example
DOCKERFILE
- name: Build Docker Image
uses: docker/build-push-action@v1
with:
repository: example
tags: ${{ github.sha }}
push: false
- uses: ./
id: extract
with:
image: example:${{ github.sha }}
path: /app
- name: Upload Dist
uses: actions/upload-artifact@v2
with:
path: ${{ steps.extract.outputs.destination }}
name: dist

View file

@ -5,24 +5,28 @@ A GitHub Action for extracting files from a Docker Image.
```yaml
- uses: shrink/actions-docker-extract@v1
with:
image: 'docker.pkg.github.com/github/semantic/semantic'
path: '/etc/motd'
image: 'ghost:alpine'
path: '/var/lib/ghost/current/core/built/assets/.'
```
## Inputs
All inputs are required.
| ID | Description | Example |
| --- | ----------- | ------- |
| `image` | Docker Image to extract files from | `alpine` |
| `path` | Path (from root) to a file or directory within Image | `/etc/motd` |
| ID | Description | Examples |
| --- | ----------- | -------- |
| `image` | Docker Image to extract files from | `alpine` `docker.pkg.github.com/github/semantic/semantic` |
| `path` | Path (from root) to a file or directory within Image | `files/example.txt` `files` `files/.` |
> :paperclip: To copy the **contents** of a directory the `path` must end with
`/.` otherwise the directory itself will be copied. More information about the
specific rules can be found via the [docker cp][docker-cp] documentation.
## Outputs
| ID | Description | Example |
| --- | ----------- | ------- |
| `destination` | Destination path containing the extracted file(s) | `.extracted-1598717412` |
| `destination` | Destination path containing the extracted file(s) | `.extracted-1598717412/` |
## Examples
@ -46,7 +50,7 @@ jobs:
- uses: shrink/actions-docker-extract@v1
with:
image: my-example-image
path: /app
path: /app/.
- name: Upload Dist
uses: actions/upload-artifact@v2
with:
@ -74,7 +78,7 @@ jobs:
- uses: shrink/actions-docker-extract@v1
with:
image: ${{ github.repository }}/example-image:latest
path: /app
path: /app/.
- name: Upload Dist
uses: actions/upload-artifact@v2
with:
@ -84,3 +88,4 @@ jobs:
[build-push-action]: https://github.com/docker/build-push-action
[login-action]: https://github.com/docker/login-action
[docker-cp]: https://docs.docker.com/engine/reference/commandline/cp/#extended-description

View file

@ -8,6 +8,7 @@ async function run() {
const destination = `.extracted-${Date.now()}`;
const create = `docker cp $(docker create ${image}):/${path} ${destination}`;
await exec.exec(`mkdir -p ${destination}`);
await exec.exec(`/bin/bash -c "${create}"`, []);
core.setOutput('destination', destination);