|
44 | 44 | role-to-assume: arn:aws:iam::097635932419:role/github-actions-ecs-role |
45 | 45 | aws-region: ${{ env.AWS_REGION }} |
46 | 46 |
|
| 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 | +
|
47 | 63 | - name: Setup Terraform |
48 | 64 | uses: hashicorp/setup-terraform@v3 |
49 | 65 | with: |
|
61 | 77 | run: | |
62 | 78 | if aws ecr describe-repositories --repository-names "${{ env.ECR_REPOSITORY }}" --region "${{ env.AWS_REGION }}" >/dev/null 2>&1; then |
63 | 79 | 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." |
64 | 82 | fi |
65 | 83 |
|
66 | 84 | - name: Terraform apply (infra) |
@@ -147,44 +165,24 @@ jobs: |
147 | 165 | - name: Download full TaskDefinition JSON |
148 | 166 | if: ${{ inputs.mode == 'apply' }} |
149 | 167 | 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 |
154 | 169 |
|
155 | | - - name: Update image in TaskDefinition (minimal spec) |
| 170 | + - name: Update image in TaskDefinition |
156 | 171 | if: ${{ inputs.mode == 'apply' }} |
157 | 172 | env: |
158 | 173 | IMG: ${{ steps.ecr.outputs.ECR_URL }}:${{ steps.ecr.outputs.TAG }} |
159 | 174 | run: | |
160 | 175 | 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)) |
176 | 178 | ' taskdef.json > register.json |
177 | 179 | echo "Using image: $IMG" |
178 | | - jq -C . register.json |
179 | 180 |
|
180 | 181 | - name: Register new TaskDefinition |
181 | 182 | if: ${{ inputs.mode == 'apply' }} |
182 | 183 | id: register |
183 | 184 | 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) |
188 | 186 | echo "new=$NEW_TD" >> $GITHUB_OUTPUT |
189 | 187 |
|
190 | 188 | - name: Update Service & wait |
|
0 commit comments