Skip to content

Commit

Permalink
Update step version
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Oct 26, 2024
1 parent 3ffea1f commit 9796cc6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
Expand Down
11 changes: 6 additions & 5 deletions bin/apply-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {

let exitCode = null;

const ecs = new ECSClient({});

main()
.then((logs) => {
console.log(`Task output:\n${"-".repeat(100)}`);
Expand All @@ -32,14 +34,13 @@ main()
async function main() {
const [, , lambdaArn] = process.argv;
const { taskArn, clusterArn } = await invokeLambda(lambdaArn);
const ecs = new ECSClient({});
const task = await pollEcsTask(ecs, taskArn, clusterArn);
const task = await pollEcsTask(taskArn, clusterArn);
exitCode = task.containers[0]?.exitCode ?? null;
if (exitCode === null)
throw new Error("Could not retrieve exit code from the ECS task.");

const { logGroup, logStreamPrefix, region, containerName } =
await getLogConfig(ecs, task.taskDefinitionArn);
await getLogConfig(task.taskDefinitionArn);
const taskId = taskArn.split("/").pop();
const logStreamName = `${logStreamPrefix}/${containerName}/${taskId}`;
return fetchCloudWatchLogs(logGroup, logStreamName, region);
Expand All @@ -57,7 +58,7 @@ async function invokeLambda(lambdaArn) {
return JSON.parse(new TextDecoder().decode(response.Payload));
}

async function pollEcsTask(ecs, taskArn, clusterArn) {
async function pollEcsTask(taskArn, clusterArn) {
while (true) {
const { tasks } = await ecs.send(
new DescribeTasksCommand({ cluster: clusterArn, tasks: [taskArn] })
Expand All @@ -70,7 +71,7 @@ async function pollEcsTask(ecs, taskArn, clusterArn) {
}
}

async function getLogConfig(ecs, taskDefinitionArn) {
async function getLogConfig(taskDefinitionArn) {
const { taskDefinition } = await ecs.send(
new DescribeTaskDefinitionCommand({ taskDefinition: taskDefinitionArn })
);
Expand Down
1 change: 1 addition & 0 deletions deploy/lib/KeycloakConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class KeycloakConfig extends Construct {
},
});

// Helper to simplify triggering the ECS task
const applyConfigLambda = new lambda.Function(this, "ApplyConfigLambda", {
code: lambda.Code.fromInline(`
const { ECSClient, RunTaskCommand } = require('@aws-sdk/client-ecs');
Expand Down

0 comments on commit 9796cc6

Please sign in to comment.