-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (62 loc) · 2.25 KB
/
index.js
File metadata and controls
70 lines (62 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const core = require("@actions/core");
const { getAuthToken } = require("./aws");
const { dockerLogin, dockerBuild, dockerPush, dockerTag } = require("./docker");
// most @actions toolkit packages have async methods
async function run() {
try {
const inputImageName = core.getInput("image-name");
const inputImageTag = core.getInput("image-tag");
const inputDockerfilePath = core.getInput("dockerfile-path", {
required: false,
});
const inputContextPath = core.getInput("context-path", { required: false });
const inputPush = core.getBooleanInput("push", { required: false });
const inputRegion = core.getInput("ecr-region", { required: false });
const inputLatest = core.getBooleanInput("latest", { required: false });
const args = core.getInput("args", { required: false });
let argsArray = [];
if (args) {
argsArray = args.split(",");
}
if (inputPush) {
const { username, password, registryUri } = await getAuthToken(
inputRegion
);
await dockerLogin(username, password, registryUri, false);
// Build with registry name in front
const imageName = `${registryUri}/${inputImageName}`;
const imageFullname = `${imageName}:${inputImageTag}`;
await dockerBuild(
imageFullname,
inputDockerfilePath,
inputContextPath,
argsArray
);
await dockerPush(imageName, inputImageTag);
if (inputLatest) {
await dockerTag(imageName, inputImageTag, "latest");
await dockerPush(imageName, "latest");
}
core.setOutput("registry", registryUri);
core.setOutput("image-name", imageName);
core.setOutput("image-tag", inputImageTag);
core.setOutput("image-fullname", imageFullname);
} else {
// Build without registry name in front
const imageName = `${inputImageName}`;
const imageFullname = `${imageName}:${inputImageTag}`;
await dockerBuild(
imageFullname,
inputDockerfilePath,
inputContextPath,
argsArray
);
core.setOutput("image-name", imageName);
core.setOutput("image-tag", inputImageTag);
core.setOutput("image-fullname", imageFullname);
}
} catch (error) {
core.setFailed(error.message);
}
}
run();