Skip to content

Commit

Permalink
use dagger connect
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Oct 15, 2023
1 parent b50b694 commit dbcae16
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 115 deletions.
9 changes: 0 additions & 9 deletions example/.fluentci/src/dagger/dagger.ts

This file was deleted.

217 changes: 111 additions & 106 deletions example/.fluentci/src/dagger/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { client } from "./dagger.ts";
import { connect } from "../../deps.ts";
import { filterObjectByPrefix, withEnvs } from "./lib.ts";

export enum Job {
Expand All @@ -21,58 +21,59 @@ export const init = async (
tfVersion?: string,
googleApplicationCredentials?: string
) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

if (googleApplicationCredentials) {
envs.GOOGLE_APPLICATION_CREDENTIALS = googleApplicationCredentials;
}

const baseCtr = withEnvs(
client
.pipeline(Job.init)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withExec(["ls", "-ltra", ".", ".terraform"], { skipEntrypoint: true })
.withExec(["version"])
.withExec(["init"])
.withExec(["ls", "-ltra", ".", ".terraform"], { skipEntrypoint: true });

await ctr.stdout();

await connect(async (client) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

if (googleApplicationCredentials) {
envs.GOOGLE_APPLICATION_CREDENTIALS = googleApplicationCredentials;
}

const baseCtr = withEnvs(
client
.pipeline(Job.init)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withExec(["ls", "-ltra", ".", ".terraform"], { skipEntrypoint: true })
.withExec(["version"])
.withExec(["init"]);

await ctr.stdout();
});
return "Initialized";
};

export const validate = async (src = ".", tfVersion?: string) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

const baseCtr = withEnvs(
client
.pipeline(Job.validate)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withDirectory("/app", context, {
exclude,
})
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withWorkdir("/app")
.withExec(["ls", "-ltra", ".", ".terraform"], { skipEntrypoint: true })
.withExec(["version"])
.withExec(["validate"]);

await ctr.stdout();
await connect(async (client) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

const baseCtr = withEnvs(
client
.pipeline(Job.validate)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withDirectory("/app", context, {
exclude,
})
.withWorkdir("/app")
.withExec(["version"])
.withExec(["validate"]);

await ctr.stdout();
});

return "Configuration validated";
};
Expand All @@ -82,32 +83,34 @@ export const plan = async (
tfVersion?: string,
googleApplicationCredentials?: string
) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

if (googleApplicationCredentials) {
envs.GOOGLE_APPLICATION_CREDENTIALS = googleApplicationCredentials;
}

const baseCtr = withEnvs(
client
.pipeline(Job.plan)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withMountedCache("/app/plan", client.cacheVolume("tfplan"))
.withDirectory("/app", context, {
exclude,
})
.withWorkdir("/app")
.withExec(["version"])
.withExec(["plan", "-out=/app/plan/plan.tfplan"]);

await ctr.stdout();
await connect(async (client) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

if (googleApplicationCredentials) {
envs.GOOGLE_APPLICATION_CREDENTIALS = googleApplicationCredentials;
}

const baseCtr = withEnvs(
client
.pipeline(Job.plan)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withMountedCache("/app/plan", client.cacheVolume("tfplan"))
.withDirectory("/app", context, {
exclude,
})
.withWorkdir("/app")
.withExec(["version"])
.withExec(["plan", "-out=/app/plan/plan.tfplan"]);

await ctr.stdout();
});
return "Plan generated";
};

Expand All @@ -116,38 +119,40 @@ export const apply = async (
tfVersion?: string,
googleApplicationCredentials?: string
) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

if (googleApplicationCredentials) {
envs.GOOGLE_APPLICATION_CREDENTIALS = googleApplicationCredentials;
}

const baseCtr = withEnvs(
client
.pipeline(Job.apply)
await connect(async (client) => {
const context = client.host().directory(src);
const TF_VERSION = tfVersion || Deno.env.get("TF_VERSION") || "latest";

if (googleApplicationCredentials) {
envs.GOOGLE_APPLICATION_CREDENTIALS = googleApplicationCredentials;
}

const baseCtr = withEnvs(
client
.pipeline(Job.apply)
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withMountedCache("/app/plan", client.cacheVolume("tfplan"))
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withExec(["version"])
.withExec(["apply", "-auto-approve", "/app/plan/plan.tfplan"]);

await ctr.stdout();

await client
.pipeline("clear_plan")
.container()
.from(`hashicorp/terraform:${TF_VERSION}`),
envs
);

const ctr = baseCtr
.withMountedCache("/app/.terraform", client.cacheVolume("terraform"))
.withMountedCache("/app/plan", client.cacheVolume("tfplan"))
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withExec(["version"])
.withExec(["apply", "-auto-approve", "/app/plan/plan.tfplan"]);

await ctr.stdout();

await client
.pipeline("clear_plan")
.container()
.from("alpine")
.withMountedCache("/app/plan", client.cacheVolume("tfplan"))
.withExec(["sh", "-c", "rm -rf /app/plan/*"])
.stdout();
.from("alpine")
.withMountedCache("/app/plan", client.cacheVolume("tfplan"))
.withExec(["sh", "-c", "rm -rf /app/plan/*"])
.stdout();
});

return "Changes applied";
};
Expand Down

0 comments on commit dbcae16

Please sign in to comment.