diff --git a/.github/workflows/deploy-lampi-siirtaja.yml b/.github/workflows/deploy-lampi-siirtaja.yml new file mode 100644 index 0000000..d929974 --- /dev/null +++ b/.github/workflows/deploy-lampi-siirtaja.yml @@ -0,0 +1,102 @@ +name: Deploy Lampi-siirtäjä + +on: + workflow_call: + inputs: + image-tag: + description: 'Image tag deployed (example: ga-21).' + required: true + type: string + environment: + type: string + required: true + description: 'Environment which to deploy to (testi/tuotanto)' + workflow_dispatch: + inputs: + image-tag: + description: 'Image tag deployed (example: ga-21).' + required: true + type: string + environment: + type: choice + description: 'Environment which to deploy to' + options: + - testi + - tuotanto + +permissions: + id-token: write + contents: read + +jobs: + deploy: + name: Deploy Lampi-siirtäjä from ECR to ECS + runs-on: ubuntu-latest + + steps: + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Configure AWS credentials + if: ${{ inputs.environment == 'testi' }} + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_OVARA_TESTI_ROLE_ARN }} + role-session-name: testi-lampi-siirtaja-deploy + aws-region: eu-west-1 + + - name: Configure AWS credentials + if: ${{ inputs.environment == 'tuotanto' }} + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_OVARA_TUOTANTO_ROLE_ARN }} + role-session-name: tuotanto-lampi-siirtaja-deploy + aws-region: eu-west-1 + + - name: Configure ENV parameters + if: ${{ inputs.environment == 'testi' }} + run: | + echo "FAMILY_PREFIX=testiEcsStacktestiovaralampisiirtajaScheduledTaskDef" >> $GITHUB_ENV + echo "ECS_CLUSTER_NAME=testi-ecs-cluster" >> $GITHUB_ENV + echo "SCHEDULED_TASK_RULE_PREFIX=testi-lampiSiirtajaScheduledFargateTaskRule" >> $GITHUB_ENV + + - name: Configure ENV parameters + if: ${{ inputs.environment == 'tuotanto' }} + run: | + echo "FAMILY_PREFIX=tuotantoEcsStacktestiovaralampisiirtajaScheduledTaskDef" >> $GITHUB_ENV + echo "ECS_CLUSTER_NAME=tuotanto-ecs-cluster" >> $GITHUB_ENV + echo "SCHEDULED_TASK_RULE_PREFIX=tuotanto-lampiSiirtajaScheduledFargateTaskRule" >> $GITHUB_ENV + + - name: Download task definition + run: | + aws ecs describe-task-definition --task-definition `aws ecs list-task-definition-families --family-prefix ${{ env.FAMILY_PREFIX }} | jq -r '.families[0]'` --query taskDefinition > task-definition.json + echo $(cat task-definition.json | jq 'del( + .taskDefinitionArn, + .requiresAttributes, + .compatibilities, + .revision, + .status, + .registeredAt, + .registeredBy + )' ) > task-definition.json + + - name: Fill in the new image ID in the Amazon ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1.5.2 + with: + task-definition: task-definition.json + container-name: ScheduledContainer + image: ${{ secrets.AWS_OVARA_UTILITY_ECR_LAMPI_SIIRTAJA_REPO }}:${{ inputs.image-tag }} + + - name: Deploy to Amazon ECS Scheduled Tasks + uses: airfordable/ecs-deploy-task-definition-to-scheduled-task@v2.1.0 + with: + cluster: ${{ env.ECS_CLUSTER_NAME }} + rule-prefix: ${{ env.SCHEDULED_TASK_RULE_PREFIX }} + task-definition: ${{ steps.task-def.outputs.task-definition }} + + - name: Update container image version to AWS Parameter store + run: | + aws ssm put-parameter --name "/${{ inputs.environment }}/ecs/lampi-siirtaja/version" --type "String" --value "${{ inputs.image-tag }}" --overwrite