summaryrefslogtreecommitdiff
path: root/worker/scripts/build_image
diff options
context:
space:
mode:
Diffstat (limited to 'worker/scripts/build_image')
-rwxr-xr-xworker/scripts/build_image86
1 files changed, 55 insertions, 31 deletions
diff --git a/worker/scripts/build_image b/worker/scripts/build_image
index 7107224..07c07c9 100755
--- a/worker/scripts/build_image
+++ b/worker/scripts/build_image
@@ -5,6 +5,7 @@ import {
BitwardenSession,
getRequiredEnv,
getStdout,
+ loggerWithPrefix,
type LoginItem,
} from "@liz-ci/utils";
@@ -19,29 +20,38 @@ const args: BuildDockerImageJobProps = {
buildTarget: getRequiredEnv("buildTarget"),
};
-const bitwardenSession = new BitwardenSession();
-const { username: registryUsername, password: registryPassword } =
- (await bitwardenSession.getItem<LoginItem>(args.registry))?.login ?? {};
-if (!(registryUsername && registryPassword)) {
- throw new Error("where's the login info bruh");
-}
-
-await getStdout(
- [
- "docker",
- "login",
- "--username",
- registryUsername,
- "--password",
- registryPassword,
- args.registry,
- ],
+const logger = loggerWithPrefix(() =>
+ `[${
+ new Date().toISOString()
+ }] [build_image.${args.repository}.${args.imageTag}]`
);
-const tag =
- `${args.registry}/${args.namespace}/${args.repository}:${args.imageTag}`;
-await getStdout(
- [
+const run = async () => {
+ logger.log("Starting Docker image build job");
+
+ const bitwardenSession = new BitwardenSession();
+ const { username: registryUsername, password: registryPassword } =
+ (await bitwardenSession.getItem<LoginItem>(args.registry))?.login ?? {};
+ if (!(registryUsername && registryPassword)) {
+ throw new Error("where's the login info bruh");
+ }
+
+ logger.log(`Logging in to Docker registry: ${args.registry}`);
+ await getStdout(
+ [
+ "docker",
+ "login",
+ "--username",
+ registryUsername,
+ "--password",
+ registryPassword,
+ args.registry,
+ ],
+ );
+
+ const tag =
+ `${args.registry}/${args.namespace}/${args.repository}:${args.imageTag}`;
+ const buildCmd = [
"docker",
"build",
"--target",
@@ -51,17 +61,31 @@ await getStdout(
"-f",
`${args.dockerfile}`,
`${args.context}`,
- ],
- {
- clearEnv: true,
- env: {},
- },
-);
+ ];
+
+ logger.log(`building`, tag, buildCmd);
+ await getStdout(
+ buildCmd,
+ {
+ clearEnv: true,
+ env: {},
+ },
+ );
-await getStdout(
- [
+ const pushCmd = [
"docker",
"push",
tag,
- ],
-);
+ ];
+ logger.log(`pushing`, pushCmd);
+ await getStdout(pushCmd);
+};
+
+if (import.meta.main) {
+ try {
+ await run();
+ } catch (e) {
+ logger.error("womp womp D:", e);
+ throw e;
+ }
+}