1
0
Fork 0
mirror of https://github.com/docker/build-push-action.git synced 2025-05-06 21:49:33 +02:00

fix lint errors (#20)

This commit is contained in:
Aayush Shah 2024-11-18 10:59:50 -05:00 committed by GitHub
parent 0dd24abd97
commit 5d3ec55e86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,33 +22,29 @@ import * as context from './context';
import {promisify} from 'util';
import {exec} from 'child_process';
import * as TOML from '@iarna/toml';
import portfinder from 'portfinder';
const buildxVersion = 'v0.17.0';
const mountPoint = '/var/lib/buildkit';
const device = '/dev/vdb';
const execAsync = promisify(exec);
async function getBlacksmithAPIUrl(): Promise<AxiosInstance> {
let apiUrl = process.env.PETNAME?.includes('staging')
? 'https://stagingapi.blacksmith.sh'
: 'https://api.blacksmith.sh'
const apiUrl = process.env.PETNAME?.includes('staging') ? 'https://stagingapi.blacksmith.sh' : 'https://api.blacksmith.sh';
return axios.create({
baseURL: apiUrl,
headers: {
'Authorization': `Bearer ${process.env.BLACKSMITH_STICKYDISK_TOKEN}`,
Authorization: `Bearer ${process.env.BLACKSMITH_STICKYDISK_TOKEN}`,
'X-Github-Repo-Name': process.env.GITHUB_REPO_NAME || ''
}
});
}
async function getBlacksmithHttpClient(): Promise<AxiosInstance> {
let stickyDiskMgrUrl = 'http://192.168.127.1:5556';
const stickyDiskMgrUrl = 'http://192.168.127.1:5556';
return axios.create({
baseURL: stickyDiskMgrUrl,
headers: {
'Authorization': `Bearer ${process.env.BLACKSMITH_STICKYDISK_TOKEN}`,
Authorization: `Bearer ${process.env.BLACKSMITH_STICKYDISK_TOKEN}`,
'X-Github-Repo-Name': process.env.GITHUB_REPO_NAME || ''
}
});
@ -90,7 +86,7 @@ async function reportBuildFailed() {
}
}
async function postWithRetryToBlacksmithAPI(client: AxiosInstance, url: string, requestOptions: any, retryCondition: (error: AxiosError) => boolean): Promise<AxiosResponse> {
async function postWithRetryToBlacksmithAPI(client: AxiosInstance, url: string, requestOptions: unknown, retryCondition: (error: AxiosError) => boolean): Promise<AxiosResponse> {
const maxRetries = 5;
const retryDelay = 100;
@ -99,8 +95,8 @@ async function postWithRetryToBlacksmithAPI(client: AxiosInstance, url: string,
return await client.post(url, JSON.stringify(requestOptions), {
headers: {
...client.defaults.headers.common,
'Accept': 'application/json',
'Content-Type': 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
} catch (error) {
@ -163,7 +159,7 @@ async function getWithRetry(client: AxiosInstance, url: string, formData: FormDa
throw new Error('Max retries reached');
}
async function getStickyDisk(dockerfilePath: string, retryCondition: (error: AxiosError) => boolean, options?: { signal?: AbortSignal }): Promise<any> {
async function getStickyDisk(dockerfilePath: string, retryCondition: (error: AxiosError) => boolean, options?: {signal?: AbortSignal}): Promise<unknown> {
const client = await getBlacksmithHttpClient();
const formData = new FormData();
formData.append('stickyDiskKey', dockerfilePath);
@ -196,30 +192,30 @@ async function getDiskSize(device: string): Promise<number> {
async function writeBuildkitdTomlFile(parallelism: number): Promise<void> {
const diskSize = await getDiskSize(device);
const jsonConfig: TOML.JsonMap = {
"root": "/var/lib/buildkit",
"grpc": {
"address": ["unix:///run/buildkit/buildkitd.sock"]
root: '/var/lib/buildkit',
grpc: {
address: ['unix:///run/buildkit/buildkitd.sock']
},
"worker": {
"oci": {
"enabled": true,
"gc": true,
"gckeepstorage": diskSize.toString(),
"max-parallelism": parallelism,
"snapshotter": "overlayfs",
"gcpolicy": [
worker: {
oci: {
enabled: true,
gc: true,
gckeepstorage: diskSize.toString(),
'max-parallelism': parallelism,
snapshotter: 'overlayfs',
gcpolicy: [
{
"all": true,
"keepDuration": 1209600
all: true,
keepDuration: 1209600
},
{
"all": true,
"keepBytes": diskSize.toString()
all: true,
keepBytes: diskSize.toString()
}
]
},
"containerd": {
"enabled": false
containerd: {
enabled: false
}
}
};
@ -235,15 +231,14 @@ async function writeBuildkitdTomlFile(parallelism: number): Promise<void> {
}
}
async function startBuildkitd(parallelism: number): Promise<string> {
try {
await writeBuildkitdTomlFile(parallelism);
await execAsync('sudo mkdir -p /run/buildkit');
await execAsync('sudo chmod 755 /run/buildkit');
const addr = "unix:///run/buildkit/buildkitd.sock";
const addr = 'unix:///run/buildkit/buildkitd.sock';
const {stdout: startStdout, stderr: startStderr} = await execAsync(
`sudo nohup buildkitd --addr ${addr} --allow-insecure-entitlement security.insecure --config=buildkitd.toml --allow-insecure-entitlement network.host > buildkitd.log 2>&1 &`,
`sudo nohup buildkitd --addr ${addr} --allow-insecure-entitlement security.insecure --config=buildkitd.toml --allow-insecure-entitlement network.host > buildkitd.log 2>&1 &`
);
if (startStderr) {
@ -251,7 +246,7 @@ async function startBuildkitd(parallelism: number): Promise<string> {
}
core.debug(`buildkitd daemon started successfully ${startStdout}`);
const { stdout, stderr } = await execAsync(`pgrep -f buildkitd`);
const {stderr} = await execAsync(`pgrep -f buildkitd`);
if (stderr) {
throw new Error(`error finding buildkitd PID: ${stderr}`);
}
@ -298,7 +293,6 @@ async function reportBlacksmithBuilderFailed(stickydiskKey: string) {
return response.data;
}
// getRemoteBuilderAddr resolves the address to a remote Docker builder.
// If it is unable to do so because of a timeout or an error it returns null.
async function getRemoteBuilderAddr(inputs: context.Inputs, dockerfilePath: string): Promise<string | null> {
@ -325,7 +319,7 @@ async function getRemoteBuilderAddr(inputs: context.Inputs, dockerfilePath: stri
// Start buildkitd.
const parallelism = await getNumCPUs();
var buildkitdAddr = await startBuildkitd(parallelism);
const buildkitdAddr = await startBuildkitd(parallelism);
core.debug(`buildkitd daemon started at addr ${buildkitdAddr}`);
// Change permissions on the buildkitd socket to allow non-root access
const startTime = Date.now();
@ -421,7 +415,7 @@ actionsToolkit.run(
const dockerfilePath = context.getDockerfilePath(inputs);
if (!dockerfilePath) {
if (inputs.nofallback) {
await reportBlacksmithBuilderFailed("");
await reportBlacksmithBuilderFailed('');
throw Error('Failed to resolve dockerfile path, and fallback is disabled');
} else {
core.warning('Failed to resolve dockerfile path, and fallback is enabled. Falling back to a local build.');