Skip to content

Commit 3c86ff5

Browse files
committed
Add wake/sleep Lambda + workflows
1 parent b0e317e commit 3c86ff5

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

.github/workflows/cd.yml

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ jobs:
4444
role-to-assume: arn:aws:iam::097635932419:role/github-actions-ecs-role
4545
aws-region: ${{ env.AWS_REGION }}
4646

47+
- name: Package Lambda zips
48+
run: |
49+
set -e
50+
mkdir -p infra
51+
if [ -f wake/lambda_function.py ]; then
52+
(cd wake && zip -r ../infra/wake.zip lambda_function.py >/dev/null)
53+
else
54+
echo "wake/lambda_function.py not found, skipping wake.zip"
55+
fi
56+
if [ -f autosleep/auto_sleep.py ]; then
57+
(cd autosleep && zip -r ../infra/sleep.zip auto_sleep.py >/dev/null)
58+
else
59+
echo "autosleep/auto_sleep.py not found, skipping sleep.zip"
60+
fi
61+
ls -l infra/*.zip || true
62+
4763
- name: Setup Terraform
4864
uses: hashicorp/setup-terraform@v3
4965
with:
@@ -61,6 +77,8 @@ jobs:
6177
run: |
6278
if aws ecr describe-repositories --repository-names "${{ env.ECR_REPOSITORY }}" --region "${{ env.AWS_REGION }}" >/dev/null 2>&1; then
6379
terraform state show aws_ecr_repository.this >/dev/null 2>&1 || terraform import aws_ecr_repository.this "${{ env.ECR_REPOSITORY }}"
80+
else
81+
echo "ECR not found — Terraform will create it."
6482
fi
6583
6684
- name: Terraform apply (infra)
@@ -147,44 +165,24 @@ jobs:
147165
- name: Download full TaskDefinition JSON
148166
if: ${{ inputs.mode == 'apply' }}
149167
run: |
150-
aws ecs describe-task-definition \
151-
--task-definition "${{ steps.svc.outputs.td }}" \
152-
--region "${{ env.AWS_REGION }}" \
153-
--query "taskDefinition" > taskdef.json
168+
aws ecs describe-task-definition --task-definition "${{ steps.svc.outputs.td }}" --region "${{ env.AWS_REGION }}" --query "taskDefinition" > taskdef.json
154169
155-
- name: Update image in TaskDefinition (minimal spec)
170+
- name: Update image in TaskDefinition
156171
if: ${{ inputs.mode == 'apply' }}
157172
env:
158173
IMG: ${{ steps.ecr.outputs.ECR_URL }}:${{ steps.ecr.outputs.TAG }}
159174
run: |
160175
jq --arg IMG "$IMG" '
161-
{
162-
family: .family,
163-
taskRoleArn: .taskRoleArn,
164-
executionRoleArn: .executionRoleArn,
165-
networkMode: .networkMode,
166-
containerDefinitions: (
167-
.containerDefinitions
168-
| map(if .name=="app" then (.image=$IMG) else . end)
169-
),
170-
volumes: (.volumes // []),
171-
requiresCompatibilities: .requiresCompatibilities,
172-
cpu: .cpu,
173-
memory: .memory,
174-
runtimePlatform: .runtimePlatform
175-
}
176+
del(.revision,.status,.taskDefinitionArn,.requiresAttributes,.compatibilities,.registeredBy,.registeredAt,.deregisteredAt)
177+
| .containerDefinitions = (.containerDefinitions | map(if .name=="app" then .image=$IMG else . end))
176178
' taskdef.json > register.json
177179
echo "Using image: $IMG"
178-
jq -C . register.json
179180
180181
- name: Register new TaskDefinition
181182
if: ${{ inputs.mode == 'apply' }}
182183
id: register
183184
run: |
184-
NEW_TD=$(aws ecs register-task-definition \
185-
--region "${{ env.AWS_REGION }}" \
186-
--cli-input-json file://register.json \
187-
--query "taskDefinition.taskDefinitionArn" --output text)
185+
NEW_TD=$(aws ecs register-task-definition --region "${{ env.AWS_REGION }}" --cli-input-json file://register.json --query "taskDefinition.taskDefinitionArn" --output text)
188186
echo "new=$NEW_TD" >> $GITHUB_OUTPUT
189187
190188
- name: Update Service & wait

0 commit comments

Comments
 (0)