Skip to content

Commit 205e99d

Browse files
committed
Rework config lambda to inject Github environment vars into Keycloak Config CLI Fargate task. (#69)
* Rework config lambda to inject Github environment vars into Keycloak Config CLI Fargate task. * Fix comment
1 parent c4c4461 commit 205e99d

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.github/workflows/deploy.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ jobs:
7575
run: |
7676
echo "CONFIG_LAMBDA_ARN=$(jq -r '."veda-keycloak-${{ inputs.environment }}".ConfigLambdaArn' outputs.json)" >> $GITHUB_ENV
7777
78-
- name: Run Apply Config
78+
- name: Process environment variables
79+
id: process-env-vars
80+
run: |
81+
echo "CONFIG_VARS=$(echo '${{ toJSON(vars) }}' | jq -c .)" >> $GITHUB_ENV
82+
83+
- name: Apply Config
7984
run: npm run apply-config $CONFIG_LAMBDA_ARN
80-
env:
81-
GRAFANA_CLIENT_URL: ${{ vars.GRAFANA_CLIENT_URL }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ clients:
9595
```
9696

9797
> [!IMPORTANT]
98-
> For the above example, we also must ensure that Github Actions configuration step is updated to pass the `GRAFANA_CLIENT_URL` from Github Actions deployment environment into the step's environment (ie `env` statement).
98+
> For the above example, we also must ensure that `GRAFANA_CLIENT_URL` is set within the Github Environment's variables via the Github settings console.
9999

100100
</details>
101101

bin/apply-config.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ main()
3030
logs.forEach((l) => console.log(l));
3131
})
3232
.catch((error) => {
33-
console.error(`Error: ${error}`);
33+
console.error("Error:", error);
34+
console.error("Stack trace:", error.stack);
3435
exitCode = 1;
3536
})
3637
.finally(() => process.exit(exitCode));
@@ -65,7 +66,7 @@ async function invokeLambda(lambdaArn) {
6566
new InvokeCommand({
6667
FunctionName: lambdaArn,
6768
InvocationType: "RequestResponse",
68-
Payload: new TextEncoder().encode(JSON.stringify({})),
69+
Payload: new TextEncoder().encode(process.env.CONFIG_VARS),
6970
})
7071
);
7172
return JSON.parse(new TextDecoder().decode(response.Payload));

cdk/lib/KeycloakConfig.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ interface KeycloakConfigConstructProps {
1919

2020
type clientSecretTuple = Array<[string, secretsManager.ISecret]>;
2121

22+
/**
23+
* Responsible for creating infrastructure to apply configuration to a Keycloak instance.
24+
*/
2225
export class KeycloakConfig extends Construct {
2326
constructor(
2427
scope: Construct,
@@ -77,7 +80,9 @@ export class KeycloakConfig extends Construct {
7780
cpu: 256,
7881
memoryLimitMiB: 512,
7982
});
83+
const containerName = "ConfigContainer";
8084
configTaskDef.addContainer("ConfigContainer", {
85+
containerName,
8186
image: ecs.ContainerImage.fromAsset(props.configDir, {
8287
platform: ecrAssets.Platform.LINUX_AMD64,
8388
buildArgs: {
@@ -115,10 +120,19 @@ export class KeycloakConfig extends Construct {
115120
const ecsClient = new ECSClient({});
116121
117122
exports.handler = async function(event) {
123+
console.log('Received event:', event);
118124
const params = {
119125
cluster: '${props.cluster.clusterName}',
120126
taskDefinition: '${configTaskDef.taskDefinitionArn}',
121127
launchType: 'FARGATE',
128+
overrides: {
129+
containerOverrides: [
130+
{
131+
name: ${JSON.stringify(containerName)},
132+
environment: event,
133+
},
134+
],
135+
},
122136
networkConfiguration: {
123137
awsvpcConfiguration: {
124138
subnets: ${JSON.stringify(props.subnetIds)},

0 commit comments

Comments
 (0)