Skip to content

Fixed bugs on Windows (#20) #23

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 8 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
pull_request:
delete:

defaults:
run:
shell: bash

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -48,6 +52,10 @@ jobs:
'test_project_scratch',
'hello-world',
],
os: [
'ubuntu-latest',
'windows-latest',
],
include: [
{
inspect_image: 'test_project_scratch',
Expand All @@ -57,6 +65,14 @@ jobs:
inspect_image: 'hello-world',
prepare_command: ':',
build_command: 'docker pull hello-world',
}, {
branch: process.env.GITHUB_REF.replace('refs/heads/', '')
}
],
exclude: [
{
inspect_image: 'test_project_scratch',
os: 'windows-latest',
},
],
}
Expand All @@ -69,36 +85,32 @@ jobs:
needs: build
strategy:
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- run: ${{ matrix.prepare_command }}

- name: Extract
id: extract
run: |
echo "##[set-output name=branch;]${GITHUB_REF#refs/heads/}"

- name: Download action
uses: actions/download-artifact@v2
with:
name: built
path: action-dlc

- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
with:
key: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
key: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}

- run: ${{ matrix.build_command }}

test_restoring:
needs: [build, test_saving]
strategy:
matrix: ${{ fromJSON(needs.build.outputs.matrix) }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

Expand All @@ -116,10 +128,10 @@ jobs:
path: action-dlc

- uses: ./action-dlc
name: Run satackey/action-docker-layer-caching@${{ steps.extract.outputs.branch }}
name: Run satackey/action-docker-layer-caching@${{ matrix.branch }}
with:
key: never-restored-docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
key: never-restored-docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-{hash}
restore-keys: docker-layer-caching-${{ matrix.os }}-${{ matrix.inspect_image }}-sha:${{ github.sha }}-
skip-save: 'true'

- name: Show cached image info
Expand Down
2 changes: 1 addition & 1 deletion src/ImageDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class ImageDetector {
async getExistingImages(): Promise<string[]> {
const existingSet = new Set<string>([])
const ids = (await exec.exec(`docker image ls -q`, [], { silent: true })).stdoutStr.split(`\n`).filter(id => id !== ``)
const repotags = (await exec.exec(`sh -c "docker image ls --format '{{ .Repository }}:{{ .Tag }}' --filter 'dangling=false'"`, [], { silent: true })).stdoutStr.split(`\n`).filter(id => id !== ``);
const repotags = (await exec.exec(`docker`, `image ls --format {{.Repository}}:{{.Tag}} --filter dangling=false`.split(' '), { silent: true })).stdoutStr.split(`\n`).filter(id => id !== ``);
core.debug(JSON.stringify({ log: "getExistingImages", ids, repotags }));
([...ids, ...repotags]).forEach(image => existingSet.add(image))
core.debug(JSON.stringify({ existingSet }))
Expand Down
29 changes: 18 additions & 11 deletions src/LayerCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class LayerCache {
}

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

private async makeRepotagsDockerSaveArgReady(repotags: string[]): Promise<string[]> {
Expand Down Expand Up @@ -133,14 +133,15 @@ class LayerCache {
}
}

private async storeSingleLayerBy(id: string): Promise<number> {
const path = this.genSingleLayerStorePath(id)
const key = await this.generateSingleLayerSaveKey(id)
private async storeSingleLayerBy(layerId: string): Promise<number> {
const path = this.genSingleLayerStorePath(layerId)
const key = await this.generateSingleLayerSaveKey(layerId)

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

core.debug(JSON.stringify({ log: `storeSingleLayerBy`, layerId, path, key, cacheId}))
return cacheId
}

Expand Down Expand Up @@ -177,8 +178,9 @@ class LayerCache {
}

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


const pool = new PromisePool(this.concurrency)
const tasks = (await this.getLayerIds()).map(
layerId => pool.open(() => this.restoreSingleLayerBy(layerId))
)
Expand All @@ -201,9 +203,14 @@ class LayerCache {
}

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

core.debug(JSON.stringify({ log: `restoreSingleLayerBy`, id, path, dir, key }))

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

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

genSingleLayerStorePath(id: string) {
return `${this.getLayerCachesDir()}/${id}/layer.tar`
return path.resolve(`${this.getLayerCachesDir()}/${id}/layer.tar`)
}

async generateRootHashFromManifest(): Promise<string> {
Expand Down
1 change: 1 addition & 0 deletions src/Tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function assertManifests(x: unknown): asserts x is Manifests {
export async function loadRawManifests(path: string) {
return (await fs.readFile(`${path}/manifest.json`)).toString()
}

export async function loadManifests(path: string) {
const raw = await loadRawManifests(path)
const manifests = JSON.parse(raw.toString())
Expand Down