Skip to content

Commit 7d86f1b

Browse files
authored
🐛 Extract contents of directory (#4)
1 parent 0f83fca commit 7d86f1b

File tree

6 files changed

+103
-59
lines changed

6 files changed

+103
-59
lines changed

.github/tests/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine
2+
3+
RUN mkdir -p /files/x
4+
RUN mkdir -p /files/y
5+
6+
RUN echo "Hello, World 1! \$(date)" > /files/001.txt
7+
RUN echo "Hello, World 2! \$(date)" > /files/002.txt
8+
RUN echo "Hello, World 3! \$(date)" > /files/003.txt
9+
RUN echo "Hello, World 4! \$(date)" > /files/x/004.txt
10+
RUN echo "Hello, World 5! \$(date)" > /files/x/005.txt
11+
RUN echo "Hello, World 6! \$(date)" > /files/y/006.txt

.github/workflows/directory.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Test Directory Extraction
2+
3+
on: [push]
4+
5+
jobs:
6+
root-directory:
7+
runs-on: ubuntu-latest
8+
name: Extract Contents of Directory from Example Image
9+
steps:
10+
- uses: actions/checkout@v2
11+
- run: docker build -t example:${{ github.sha }} ./.github/tests
12+
- uses: ./
13+
id: extract
14+
with:
15+
image: example:${{ github.sha }}
16+
path: /files/.
17+
- run: test -e ${{ steps.extract.outputs.destination }}/001.txt || exit 1
18+
- run: test -e ${{ steps.extract.outputs.destination }}/002.txt || exit 1
19+
- run: test -e ${{ steps.extract.outputs.destination }}/003.txt || exit 1
20+
- run: test -e ${{ steps.extract.outputs.destination }}/x/004.txt || exit 1
21+
- run: test -e ${{ steps.extract.outputs.destination }}/x/005.txt || exit 1
22+
- run: test -e ${{ steps.extract.outputs.destination }}/y/006.txt || exit 1
23+
nested-directory:
24+
runs-on: ubuntu-latest
25+
name: Extract Nested Directory from Example Image
26+
steps:
27+
- uses: actions/checkout@v2
28+
- run: docker build -t example:${{ github.sha }} ./.github/tests
29+
- uses: ./
30+
id: extract
31+
with:
32+
image: example:${{ github.sha }}
33+
path: /files/x
34+
- run: test -e ${{ steps.extract.outputs.destination }}/x/004.txt || exit 1
35+
- run: test -e ${{ steps.extract.outputs.destination }}/x/005.txt || exit 1
36+
nested-directory-contents:
37+
runs-on: ubuntu-latest
38+
name: Extract Nested Contents of Directory from Example Image
39+
steps:
40+
- uses: actions/checkout@v2
41+
- run: docker build -t example:${{ github.sha }} ./.github/tests
42+
- uses: ./
43+
id: extract
44+
with:
45+
image: example:${{ github.sha }}
46+
path: /files/x/.
47+
- run: test -e ${{ steps.extract.outputs.destination }}/004.txt || exit 1
48+
- run: test -e ${{ steps.extract.outputs.destination }}/005.txt || exit 1

.github/workflows/file.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test File Extraction
2+
3+
on: [push]
4+
5+
jobs:
6+
root-file:
7+
runs-on: ubuntu-latest
8+
name: Extract Example File From Root of Built Image
9+
steps:
10+
- uses: actions/checkout@v2
11+
- run: docker build -t example:${{ github.sha }} ./.github/tests
12+
- uses: ./
13+
id: extract
14+
with:
15+
image: example:${{ github.sha }}
16+
path: /files/001.txt
17+
- run: test -e ${{ steps.extract.outputs.destination }}/001.txt || exit 1
18+
nested-file:
19+
runs-on: ubuntu-latest
20+
name: Extract Nexted Example File From Built Image
21+
steps:
22+
- uses: actions/checkout@v2
23+
- run: docker build -t example:${{ github.sha }} ./.github/tests
24+
- uses: ./
25+
id: extract
26+
with:
27+
image: example:${{ github.sha }}
28+
path: /files/y/006.txt
29+
- run: test -e ${{ steps.extract.outputs.destination }}/006.txt || exit 1

.github/workflows/test.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ A GitHub Action for extracting files from a Docker Image.
55
```yaml
66
- uses: shrink/actions-docker-extract@v1
77
with:
8-
image: 'docker.pkg.github.com/github/semantic/semantic'
9-
path: '/etc/motd'
8+
image: 'ghost:alpine'
9+
path: '/var/lib/ghost/current/core/built/assets/.'
1010
```
1111
1212
## Inputs
1313
1414
All inputs are required.
1515
16-
| ID | Description | Example |
17-
| --- | ----------- | ------- |
18-
| `image` | Docker Image to extract files from | `alpine` |
19-
| `path` | Path (from root) to a file or directory within Image | `/etc/motd` |
16+
| ID | Description | Examples |
17+
| --- | ----------- | -------- |
18+
| `image` | Docker Image to extract files from | `alpine` `docker.pkg.github.com/github/semantic/semantic` |
19+
| `path` | Path (from root) to a file or directory within Image | `files/example.txt` `files` `files/.` |
20+
21+
> :paperclip: To copy the **contents** of a directory the `path` must end with
22+
`/.` otherwise the directory itself will be copied. More information about the
23+
specific rules can be found via the [docker cp][docker-cp] documentation.
2024

2125
## Outputs
2226

2327
| ID | Description | Example |
2428
| --- | ----------- | ------- |
25-
| `destination` | Destination path containing the extracted file(s) | `.extracted-1598717412` |
29+
| `destination` | Destination path containing the extracted file(s) | `.extracted-1598717412/` |
2630

2731
## Examples
2832

@@ -46,7 +50,7 @@ jobs:
4650
- uses: shrink/actions-docker-extract@v1
4751
with:
4852
image: my-example-image
49-
path: /app
53+
path: /app/.
5054
- name: Upload Dist
5155
uses: actions/upload-artifact@v2
5256
with:
@@ -74,7 +78,7 @@ jobs:
7478
- uses: shrink/actions-docker-extract@v1
7579
with:
7680
image: ${{ github.repository }}/example-image:latest
77-
path: /app
81+
path: /app/.
7882
- name: Upload Dist
7983
uses: actions/upload-artifact@v2
8084
with:
@@ -84,3 +88,4 @@ jobs:
8488

8589
[build-push-action]: https://github.com/docker/build-push-action
8690
[login-action]: https://github.com/docker/login-action
91+
[docker-cp]: https://docs.docker.com/engine/reference/commandline/cp/#extended-description

src/extract.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ async function run() {
88
const destination = `.extracted-${Date.now()}`;
99
const create = `docker cp $(docker create ${image}):/${path} ${destination}`;
1010

11+
await exec.exec(`mkdir -p ${destination}`);
1112
await exec.exec(`/bin/bash -c "${create}"`, []);
1213

1314
core.setOutput('destination', destination);

0 commit comments

Comments
 (0)