Refactor Docker config
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									ac03ceb5e6
								
							
						
					
					
						commit
						f7cac3b071
					
				
							
								
								
									
										4
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							| @ -22,7 +22,7 @@ jobs: | ||||
|         name: Checkout | ||||
|         uses: actions/checkout@v2.3.1 | ||||
|       - | ||||
|         name: Build | ||||
|         name: Build and push | ||||
|         uses: ./ | ||||
|         with: | ||||
|           context: ./test | ||||
| @ -68,7 +68,7 @@ jobs: | ||||
|           context: ./test | ||||
|           file: ./test/Dockerfile-${{ matrix.dockerfile }} | ||||
|           builder: ${{ steps.buildx.outputs.builder }} | ||||
|           platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x | ||||
|           platforms: linux/amd64,linux/arm64,linux/386 | ||||
|           #push: true | ||||
|           tags: | | ||||
|             localhost:5000/name/app:latest | ||||
|  | ||||
							
								
								
									
										37
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										37
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							| @ -1114,7 +1114,7 @@ run(); | ||||
| /***/ }), | ||||
| 
 | ||||
| /***/ 231: | ||||
| /***/ (function(__unusedmodule, exports) { | ||||
| /***/ (function(__unusedmodule, exports, __webpack_require__) { | ||||
| 
 | ||||
| "use strict"; | ||||
| 
 | ||||
| @ -1127,8 +1127,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge | ||||
|         step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||||
|     }); | ||||
| }; | ||||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| exports.parseImage = void 0; | ||||
| exports.parseImage = exports.config = void 0; | ||||
| const path_1 = __importDefault(__webpack_require__(622)); | ||||
| const os_1 = __importDefault(__webpack_require__(87)); | ||||
| const fs_1 = __importDefault(__webpack_require__(747)); | ||||
| function config() { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         const dockerHome = process.env.DOCKER_CONFIG || path_1.default.join(os_1.default.homedir(), '.docker'); | ||||
|         const file = path_1.default.join(dockerHome, 'config.json'); | ||||
|         if (!fs_1.default.existsSync(file)) { | ||||
|             return; | ||||
|         } | ||||
|         return JSON.parse(fs_1.default.readFileSync(file, { encoding: 'utf-8' })); | ||||
|     }); | ||||
| } | ||||
| exports.config = config; | ||||
| exports.parseImage = (image) => __awaiter(void 0, void 0, void 0, function* () { | ||||
|     const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/); | ||||
|     if (!match) { | ||||
| @ -1895,14 +1912,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge | ||||
|         step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||||
|     }); | ||||
| }; | ||||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| exports.use = exports.isInstalled = exports.isAvailable = void 0; | ||||
| const fs_1 = __importDefault(__webpack_require__(747)); | ||||
| const path_1 = __importDefault(__webpack_require__(622)); | ||||
| const os_1 = __importDefault(__webpack_require__(87)); | ||||
| const docker = __importStar(__webpack_require__(231)); | ||||
| const exec = __importStar(__webpack_require__(807)); | ||||
| function isAvailable() { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
| @ -1918,13 +1930,8 @@ exports.isAvailable = isAvailable; | ||||
| function isInstalled() { | ||||
|     var _a; | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         const dockerHome = process.env.DOCKER_CONFIG || path_1.default.join(os_1.default.homedir(), '.docker'); | ||||
|         const dockerCfgFile = path_1.default.join(dockerHome, 'config.json'); | ||||
|         if (!fs_1.default.existsSync(dockerCfgFile)) { | ||||
|             return false; | ||||
|         } | ||||
|         const dockerCfg = JSON.parse(fs_1.default.readFileSync(dockerCfgFile, { encoding: 'utf-8' })); | ||||
|         return ((_a = dockerCfg.aliases) === null || _a === void 0 ? void 0 : _a.builder) == 'buildx'; | ||||
|         const dockerCfg = yield docker.config(); | ||||
|         return ((_a = dockerCfg === null || dockerCfg === void 0 ? void 0 : dockerCfg.aliases) === null || _a === void 0 ? void 0 : _a.builder) == 'buildx'; | ||||
|     }); | ||||
| } | ||||
| exports.isInstalled = isInstalled; | ||||
|  | ||||
| @ -1,17 +1,6 @@ | ||||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| import os from 'os'; | ||||
| import * as docker from './docker'; | ||||
| import * as exec from './exec'; | ||||
| 
 | ||||
| interface DockerConfig { | ||||
|   credsStore?: string; | ||||
|   experimental?: string; | ||||
|   stackOrchestrator?: string; | ||||
|   aliases?: { | ||||
|     builder?: string; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| export async function isAvailable(): Promise<Boolean> { | ||||
|   return await exec.exec(`docker`, ['buildx'], true).then(res => { | ||||
|     if (res.stderr != '' && !res.success) { | ||||
| @ -22,15 +11,8 @@ export async function isAvailable(): Promise<Boolean> { | ||||
| } | ||||
| 
 | ||||
| export async function isInstalled(): Promise<Boolean> { | ||||
|   const dockerHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker'); | ||||
| 
 | ||||
|   const dockerCfgFile: string = path.join(dockerHome, 'config.json'); | ||||
|   if (!fs.existsSync(dockerCfgFile)) { | ||||
|     return false; | ||||
|   } | ||||
| 
 | ||||
|   const dockerCfg: DockerConfig = JSON.parse(fs.readFileSync(dockerCfgFile, {encoding: 'utf-8'})); | ||||
|   return dockerCfg.aliases?.builder == 'buildx'; | ||||
|   const dockerCfg = await docker.config(); | ||||
|   return dockerCfg?.aliases?.builder == 'buildx'; | ||||
| } | ||||
| 
 | ||||
| export async function use(builder: string): Promise<void> { | ||||
|  | ||||
| @ -1,3 +1,16 @@ | ||||
| import path from 'path'; | ||||
| import os from 'os'; | ||||
| import fs from 'fs'; | ||||
| 
 | ||||
| export interface Config { | ||||
|   credsStore?: string; | ||||
|   experimental?: string; | ||||
|   stackOrchestrator?: string; | ||||
|   aliases?: { | ||||
|     builder?: string; | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| export interface Image { | ||||
|   registry?: string; | ||||
|   namespace?: string; | ||||
| @ -5,6 +18,17 @@ export interface Image { | ||||
|   tag?: string; | ||||
| } | ||||
| 
 | ||||
| export async function config(): Promise<Config | undefined> { | ||||
|   const dockerHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker'); | ||||
| 
 | ||||
|   const file: string = path.join(dockerHome, 'config.json'); | ||||
|   if (!fs.existsSync(file)) { | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   return JSON.parse(fs.readFileSync(file, {encoding: 'utf-8'})) as Config; | ||||
| } | ||||
| 
 | ||||
| export const parseImage = async (image: string): Promise<Image | undefined> => { | ||||
|   const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/); | ||||
|   if (!match) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 CrazyMax
						CrazyMax