-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract image pull to a separate service class
Extract logic to pull images from the updater class.
- Loading branch information
Philip Harrison
committed
Jul 26, 2021
1 parent
85169c2
commit 7ac744a
Showing
5 changed files
with
78 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import * as core from '@actions/core' | ||
| import Docker from 'dockerode' | ||
| import {Readable} from 'stream' | ||
|
|
||
| const endOfStream = async (docker: Docker, stream: Readable): Promise<void> => { | ||
| return new Promise((resolve, reject) => { | ||
| docker.modem.followProgress(stream, (err: Error) => | ||
| err ? reject(err) : resolve(undefined) | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| export const ImageService = { | ||
| /** Fetch the configured updater image, if it isn't already available. */ | ||
| async pullImage(imageName: string, force = false): Promise<void> { | ||
| const docker = new Docker() | ||
| try { | ||
| const image = await docker.getImage(imageName).inspect() | ||
| if (!force) { | ||
| core.info(`Resolved ${imageName} to existing ${image.Id}`) | ||
| return | ||
| } // else fallthrough to pull | ||
| } catch (e) { | ||
| if (!e.message.includes('no such image')) { | ||
| throw e | ||
| } // else fallthrough to pull | ||
| } | ||
|
|
||
| core.info(`Pulling image ${imageName}...`) | ||
| const auth = { | ||
| username: process.env.GITHUB_PKG_USER, | ||
| password: process.env.GITHUB_PKG_TOKEN | ||
| } | ||
| const stream = await docker.pull(imageName, {authconfig: auth}) | ||
| await endOfStream(docker, stream) | ||
| core.info(`Pulled image ${imageName}`) | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters