mirror of
https://github.com/kitabisa/docker-slim-action.git
synced 2025-04-14 18:56:05 +00:00
build: compile sources
Signed-off-by: Dwi Siswanto <me@dw1.io>
This commit is contained in:
parent
1fe2ce2532
commit
f67be5d91a
3
dist/const.js
vendored
3
dist/const.js
vendored
@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TMP_DIR = exports.shell = exports.path = exports.os = exports.io = exports.https = exports.fs = exports.core = void 0;
|
||||
exports.TMP_DIR = exports.shell = exports.path = exports.os = exports.io = exports.https = exports.fs = exports.core = exports.cache = void 0;
|
||||
exports.cache = require('@actions/cache');
|
||||
exports.core = require('@actions/core');
|
||||
exports.fs = require('fs');
|
||||
exports.https = require('https');
|
||||
|
82
dist/index.js
vendored
82
dist/index.js
vendored
@ -52,7 +52,7 @@ function get_slim() {
|
||||
}
|
||||
}
|
||||
catch (_a) {
|
||||
throw new Error('ERROR! Could not retrieve the current Slim version number.');
|
||||
throw new Error(`ERROR! Could not get the Slim version ${VER}.`);
|
||||
}
|
||||
URL = `https://downloads.dockerslim.com/releases/${VER}`;
|
||||
// Get kernel name and machine architecture.
|
||||
@ -89,39 +89,61 @@ function get_slim() {
|
||||
}
|
||||
// Derive the filename
|
||||
FILENAME = `dist_${DIST}.${EXT}`;
|
||||
const file = const_1.fs.createWriteStream(const_1.path.join(const_1.TMP_DIR, FILENAME));
|
||||
yield new Promise((resolve, reject) => {
|
||||
const_1.https.get(`${URL}/${FILENAME}`, (response) => {
|
||||
response.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
resolve(file);
|
||||
// Get the bin from cache
|
||||
const cachePrefix = `slim-${VER}`;
|
||||
const cacheKey = `${cachePrefix}-${DIST}`;
|
||||
const cachePath = const_1.path.join('/tmp', cacheKey);
|
||||
try {
|
||||
const_1.core.debug('Restoring cache');
|
||||
const cacheResult = yield const_1.cache.restoreCache([cachePath], cacheKey, [`${cachePrefix}-`]);
|
||||
if (typeof cacheResult === 'undefined') {
|
||||
throw new Error(`ERROR! Cache miss: ${cacheKey} was not found in the cache.`);
|
||||
}
|
||||
const_1.core.debug(`${cacheKey} cache was restored.`);
|
||||
SLIM_PATH = cachePath;
|
||||
}
|
||||
catch (e) {
|
||||
const_1.core.error(e);
|
||||
const file = const_1.fs.createWriteStream(const_1.path.join(const_1.TMP_DIR, FILENAME));
|
||||
yield new Promise((resolve, reject) => {
|
||||
const_1.https.get(`${URL}/${FILENAME}`, (response) => {
|
||||
response.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
resolve(file);
|
||||
});
|
||||
}).on('error', (error) => {
|
||||
const_1.fs.unlinkSync(const_1.path.join(const_1.TMP_DIR, FILENAME));
|
||||
reject(error);
|
||||
});
|
||||
}).on('error', (error) => {
|
||||
const_1.fs.unlinkSync(const_1.path.join(const_1.TMP_DIR, FILENAME));
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
const_1.core.debug(`Unpacking ${const_1.path.join(const_1.TMP_DIR, FILENAME)}`);
|
||||
if (EXT === 'zip') {
|
||||
const extract = require('extract-zip');
|
||||
yield extract(const_1.path.join(const_1.TMP_DIR, FILENAME), {
|
||||
dir: const_1.TMP_DIR
|
||||
});
|
||||
const_1.core.debug(`Unpacking ${const_1.path.join(const_1.TMP_DIR, FILENAME)}`);
|
||||
if (EXT === 'zip') {
|
||||
const extract = require('extract-zip');
|
||||
yield extract(const_1.path.join(const_1.TMP_DIR, FILENAME), {
|
||||
dir: const_1.TMP_DIR
|
||||
});
|
||||
}
|
||||
else if (EXT === 'tar.gz') {
|
||||
const tar = require('tar');
|
||||
yield tar.x({
|
||||
file: const_1.path.join(const_1.TMP_DIR, FILENAME),
|
||||
cwd: const_1.TMP_DIR
|
||||
});
|
||||
}
|
||||
else {
|
||||
throw new Error('ERROR! Unexpected file extension.');
|
||||
}
|
||||
SLIM_PATH = const_1.path.join(const_1.TMP_DIR, `dist_${DIST}`);
|
||||
const_1.core.debug(`Copying ${SLIM_PATH} -> (${cachePath})`);
|
||||
yield const_1.io.cp(SLIM_PATH, cachePath, { recursive: true, force: true });
|
||||
const cacheId = yield const_1.cache.saveCache([cachePath], cacheKey);
|
||||
const_1.core.debug(`${cacheKey} cache saved (ID: ${cacheId})`);
|
||||
}
|
||||
else if (EXT === 'tar.gz') {
|
||||
const tar = require('tar');
|
||||
yield tar.x({
|
||||
file: const_1.path.join(const_1.TMP_DIR, FILENAME),
|
||||
cwd: const_1.TMP_DIR
|
||||
});
|
||||
finally {
|
||||
const_1.core.addPath(SLIM_PATH);
|
||||
const_1.core.info(`Using slim version ${VER}`);
|
||||
}
|
||||
else {
|
||||
throw new Error('ERROR! Unexpected file extension.');
|
||||
}
|
||||
SLIM_PATH = const_1.path.join(const_1.TMP_DIR, `dist_${DIST}`);
|
||||
const_1.core.addPath(SLIM_PATH);
|
||||
const_1.core.info(`Using slim version ${VER}`);
|
||||
});
|
||||
}
|
||||
function run() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user