Skip to content

Commit 4bd1c2d

Browse files
authored
Merge pull request #23 from satackey/fix_#20_windows_runner
Fix bug running on Windows (#20)
2 parents b69d586 + a26d576 commit 4bd1c2d

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

.github/workflows/release.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
pull_request:
88
delete:
99

10+
defaults:
11+
run:
12+
shell: bash
13+
1014
jobs:
1115
build:
1216
runs-on: ubuntu-latest
@@ -48,6 +52,10 @@ jobs:
4852
'test_project_scratch',
4953
'hello-world',
5054
],
55+
os: [
56+
'ubuntu-latest',
57+
'windows-latest',
58+
],
5159
include: [
5260
{
5361
inspect_image: 'test_project_scratch',
@@ -57,6 +65,14 @@ jobs:
5765
inspect_image: 'hello-world',
5866
prepare_command: ':',
5967
build_command: 'docker pull hello-world',
68+
}, {
69+
branch: process.env.GITHUB_REF.replace('refs/heads/', '')
70+
}
71+
],
72+
exclude: [
73+
{
74+
inspect_image: 'test_project_scratch',
75+
os: 'windows-latest',
6076
},
6177
],
6278
}
@@ -69,36 +85,32 @@ jobs:
6985
needs: build
7086
strategy:
7187
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
72-
runs-on: ubuntu-latest
88+
runs-on: ${{ matrix.os }}
7389

7490
steps:
7591
- uses: actions/checkout@v2
7692

7793
- run: ${{ matrix.prepare_command }}
7894

79-
- name: Extract
80-
id: extract
81-
run: |
82-
echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"
83-
8495
- name: Download action
8596
uses: actions/download-artifact@v2
8697
with:
8798
name: built
8899
path: action-dlc
89100

90101
- uses: ./action-dlc
91-
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
102+
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
92103
with:
93-
key: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
104+
key: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
94105

95106
- run: ${{ matrix.build_command }}
96107

97108
test_restoring:
98109
needs: [build, test_saving]
99110
strategy:
100111
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
101-
runs-on: ubuntu-latest
112+
runs-on: ${{ matrix.os }}
113+
102114
steps:
103115
- uses: actions/checkout@v2
104116

@@ -116,10 +128,10 @@ jobs:
116128
path: action-dlc
117129

118130
- uses: ./action-dlc
119-
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
131+
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
120132
with:
121-
key: never-restored-docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
122-
restore-keys: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
133+
key: never-restored-docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
134+
restore-keys: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
123135
skip-save: 'true'
124136

125137
- name: Show cached image info

src/ImageDetector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class ImageDetector {
55
async getExistingImages(): Promise<string[]> {
66
const existingSet = new Set<string>([])
77
const ids = (await exec.exec(`docker image ls -q`, [], { silent: true })).stdoutStr.split(`\n`).filter(id => id !== ``)
8-
const repotags = (await exec.exec(`sh -c "docker image ls --format '{{ .Repository }}:{{ .Tag }}' --filter 'dangling=false'"`, [], { silent: true })).stdoutStr.split(`\n`).filter(id => id !== ``);
8+
const repotags = (await exec.exec(`docker`, `image ls --format {{.Repository}}:{{.Tag}} --filter dangling=false`.split(' '), { silent: true })).stdoutStr.split(`\n`).filter(id => id !== ``);
99
core.debug(JSON.stringify({ log: "getExistingImages", ids, repotags }));
1010
([...ids, ...repotags]).forEach(image => existingSet.add(image))
1111
core.debug(JSON.stringify({ existingSet }))

src/LayerCache.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class LayerCache {
4949
}
5050

5151
private async saveImageAsUnpacked() {
52-
await this.exec('mkdir -p', [this.getSavedImageTarDir()], { silent: true })
53-
await this.exec(`sh -c`, [`docker save '${(await this.makeRepotagsDockerSaveArgReady(this.ids)).join(`' '`)}' | tar xf - -C ${this.getSavedImageTarDir()}`])
52+
await fs.mkdir(this.getSavedImageTarDir(), { recursive: true })
53+
await this.exec(`sh -c`, [`docker save '${(await this.makeRepotagsDockerSaveArgReady(this.ids)).join(`' '`)}' | tar xf - -C .`], { cwd: this.getSavedImageTarDir() })
5454
}
5555

5656
private async makeRepotagsDockerSaveArgReady(repotags: string[]): Promise<string[]> {
@@ -133,14 +133,15 @@ class LayerCache {
133133
}
134134
}
135135

136-
private async storeSingleLayerBy(id: string): Promise<number> {
137-
const path = this.genSingleLayerStorePath(id)
138-
const key = await this.generateSingleLayerSaveKey(id)
136+
private async storeSingleLayerBy(layerId: string): Promise<number> {
137+
const path = this.genSingleLayerStorePath(layerId)
138+
const key = await this.generateSingleLayerSaveKey(layerId)
139139

140-
core.info(`Start storing layer cache: ${key}`)
140+
core.info(`Start storing layer cache: ${JSON.stringify({ layerId, key })}`)
141141
const cacheId = await LayerCache.dismissError(cache.saveCache([path], key), LayerCache.ERROR_CACHE_ALREAD_EXISTS_STR, -1)
142-
core.info(`Stored layer cache, key: ${key}, id: ${cacheId}`)
142+
core.info(`Stored layer cache: ${JSON.stringify({ key, cacheId })}`)
143143

144+
core.debug(JSON.stringify({ log: `storeSingleLayerBy`, layerId, path, key, cacheId}))
144145
return cacheId
145146
}
146147

@@ -177,8 +178,9 @@ class LayerCache {
177178
}
178179

179180
private async restoreLayers(): Promise<boolean> {
180-
const pool = new PromisePool(this.concurrency)
181181

182+
183+
const pool = new PromisePool(this.concurrency)
182184
const tasks = (await this.getLayerIds()).map(
183185
layerId => pool.open(() => this.restoreSingleLayerBy(layerId))
184186
)
@@ -201,9 +203,14 @@ class LayerCache {
201203
}
202204

203205
private async restoreSingleLayerBy(id: string): Promise<string> {
204-
core.debug(JSON.stringify({ log: `restoreSingleLayerBy`, id }))
206+
const path = this.genSingleLayerStorePath(id)
207+
const key = await this.recoverSingleLayerKey(id)
208+
const dir = path.replace(/[^/\\]+$/, ``)
209+
210+
core.debug(JSON.stringify({ log: `restoreSingleLayerBy`, id, path, dir, key }))
205211

206-
const result = await cache.restoreCache([this.genSingleLayerStorePath(id)], await this.recoverSingleLayerKey(id))
212+
await fs.mkdir(dir, { recursive: true })
213+
const result = await cache.restoreCache([path], key)
207214

208215
if (result == null) {
209216
throw new Error(`${LayerCache.ERROR_LAYER_CACHE_NOT_FOUND_STR}: ${JSON.stringify({ id })}`)
@@ -243,7 +250,7 @@ class LayerCache {
243250
}
244251

245252
genSingleLayerStorePath(id: string) {
246-
return `${this.getLayerCachesDir()}/${id}/layer.tar`
253+
return path.resolve(`${this.getLayerCachesDir()}/${id}/layer.tar`)
247254
}
248255

249256
async generateRootHashFromManifest(): Promise<string> {

src/Tar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function assertManifests(x: unknown): asserts x is Manifests {
1616
export async function loadRawManifests(path: string) {
1717
return (await fs.readFile(`${path}/manifest.json`)).toString()
1818
}
19+
1920
export async function loadManifests(path: string) {
2021
const raw = await loadRawManifests(path)
2122
const manifests = JSON.parse(raw.toString())

0 commit comments

Comments
 (0)