Skip to content

Commit

Permalink
ECS-konttien käynnistys Githubissa
Browse files Browse the repository at this point in the history
  • Loading branch information
augustk committed Jan 17, 2025
1 parent 92e3618 commit 54d2bf9
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/run-dbt-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Run DBT Runner

on:
workflow_call:
inputs:
environment:
type: string
required: true
description: 'Environment (testi/tuotanto)'
workflow_dispatch:
inputs:
environment:
type: choice
description: 'Environment (testi/tuotanto)'
options:
- testi
- tuotanto

permissions:
id-token: write
contents: read

jobs:
deploy:
name: Run DBT Runner
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Configure AWS credentials (TESTI)
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-dbt-runner-deploy
aws-region: eu-west-1

- name: Configure AWS credentials (TUOTANTO)
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-dbt-runner-deploy
aws-region: eu-west-1

- name: Run scheduled task (TESTI)
if: ${{ inputs.environment == 'testi' }}
run: |
ci-tools/run-testi-dbt-runner.sh
- name: Run scheduled task (TUOTANTO)
if: ${{ inputs.environment == 'tuotanto' }}
run: |
ci-tools/run-tuotanto-dbt-runner.sh
61 changes: 61 additions & 0 deletions .github/workflows/run-lampi-siirtaja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Run Lampi-siirtäjä

on:
workflow_call:
inputs:
environment:
type: string
required: true
description: 'Environment (testi/tuotanto)'
workflow_dispatch:
inputs:
environment:
type: choice
description: 'Environment (testi/tuotanto)'
options:
- testi
- tuotanto

permissions:
id-token: write
contents: read

jobs:
deploy:
name: Run Lampi-siirtäjä
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Configure AWS credentials (TESTI)
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-dbt-runner-deploy
aws-region: eu-west-1

- name: Configure AWS credentials (TUOTANTO)
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-dbt-runner-deploy
aws-region: eu-west-1

- name: Run scheduled task (TESTI)
if: ${{ inputs.environment == 'testi' }}
run: |
ci-tools/run-testi-lampi-siirtaja.sh
- name: Run scheduled task (TUOTANTO)
if: ${{ inputs.environment == 'tuotanto' }}
run: |
ci-tools/run-tuotanto-lampi-siirtaja.sh
20 changes: 20 additions & 0 deletions ci-tools/run-testi-dbt-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -eo pipefail

echo "Käynnistetään testin DBT Runner"

ecscluster=$(aws ecs list-clusters | jq -r '.clusterArns | .[0]' | cut -d "/" -f2)
taskdefinition=$(aws ecs list-task-definitions --family-prefix testiEcsStacktestidbttaskScheduledTaskDef029C43B9 --sort DESC | jq -r '.taskDefinitionArns | .[0]' | cut -d "/" -f2)
assignpublicip=$(aws events list-targets-by-rule --rule testi-scheduledFargateTaskRule | jq -r '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.AssignPublicIp')
securitygroups=$(aws events list-targets-by-rule --rule testi-scheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.SecurityGroups')
subnets=$(aws events list-targets-by-rule --rule testi-scheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.Subnets')
awsvpcconfiguration=$(jq -c -n --argjson subnets "$subnets" \
--argjson securityGroups "$securitygroups" \
--arg assignPublicIp "$assignpublicip" \
'$ARGS.named')
networkconfiguration=$(jq -c -n --argjson awsvpcConfiguration "$awsvpcconfiguration" '$ARGS.named')
command="aws ecs run-task --cluster $ecscluster --task-definition $taskdefinition --launch-type="FARGATE" --network-configuration '$networkconfiguration'"
echo "$command"

eval "$command"
20 changes: 20 additions & 0 deletions ci-tools/run-testi-lampi-siirtaja.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -eo pipefail

echo "Käynnistetään testin Lampi-siirtäjä"

ecscluster=$(aws ecs list-clusters | jq -r '.clusterArns | .[0]' | cut -d "/" -f2)
taskdefinition=$(aws ecs list-task-definitions --family-prefix testiEcsStacktestiovaralampisiirtajaScheduledTaskDef9D6D6A5C --sort DESC | jq -r '.taskDefinitionArns | .[0]' | cut -d "/" -f2)
assignpublicip=$(aws events list-targets-by-rule --rule testi-lampiSiirtajaScheduledFargateTaskRule | jq -r '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.AssignPublicIp')
securitygroups=$(aws events list-targets-by-rule --rule testi-lampiSiirtajaScheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.SecurityGroups')
subnets=$(aws events list-targets-by-rule --rule testi-lampiSiirtajaScheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.Subnets')
awsvpcconfiguration=$(jq -c -n --argjson subnets "$subnets" \
--argjson securityGroups "$securitygroups" \
--arg assignPublicIp "$assignpublicip" \
'$ARGS.named')
networkconfiguration=$(jq -c -n --argjson awsvpcConfiguration "$awsvpcconfiguration" '$ARGS.named')
command="aws ecs run-task --cluster $ecscluster --task-definition $taskdefinition --launch-type="FARGATE" --network-configuration '$networkconfiguration'"
echo "$command"

eval "$command"
20 changes: 20 additions & 0 deletions ci-tools/run-tuotanto-dbt-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -eo pipefail

echo "Käynnistetään tuotannon DBT Runner"

ecscluster=$(aws ecs list-clusters | jq -r '.clusterArns | .[0]' | cut -d "/" -f2)
taskdefinition=$(aws ecs list-task-definitions --family-prefix tuotantoEcsStacktuotantodbttaskScheduledTaskDef96224624 --sort DESC | jq -r '.taskDefinitionArns | .[0]' | cut -d "/" -f2)
assignpublicip=$(aws events list-targets-by-rule --rule tuotanto-scheduledFargateTaskRule | jq -r '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.AssignPublicIp')
securitygroups=$(aws events list-targets-by-rule --rule tuotanto-scheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.SecurityGroups')
subnets=$(aws events list-targets-by-rule --rule tuotanto-scheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.Subnets')
awsvpcconfiguration=$(jq -c -n --argjson subnets "$subnets" \
--argjson securityGroups "$securitygroups" \
--arg assignPublicIp "$assignpublicip" \
'$ARGS.named')
networkconfiguration=$(jq -c -n --argjson awsvpcConfiguration "$awsvpcconfiguration" '$ARGS.named')
command="aws ecs run-task --cluster $ecscluster --task-definition $taskdefinition --launch-type="FARGATE" --network-configuration '$networkconfiguration'"
echo "$command"

eval "$command"
20 changes: 20 additions & 0 deletions ci-tools/run-tuotanto-lampi-siirtaja.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -eo pipefail

echo "Käynnistetään tuotannon Lampi-siirtäjä"

ecscluster=$(aws ecs list-clusters | jq -r '.clusterArns | .[0]' | cut -d "/" -f2)
taskdefinition=$(aws ecs list-task-definitions --family-prefix tuotantoEcsStacktuotantoovaralampisiirtajaScheduledTaskDef44BFAB1B --sort DESC | jq -r '.taskDefinitionArns | .[0]' | cut -d "/" -f2)
assignpublicip=$(aws events list-targets-by-rule --rule tuotanto-lampiSiirtajaScheduledFargateTaskRule | jq -r '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.AssignPublicIp')
securitygroups=$(aws events list-targets-by-rule --rule tuotanto-lampiSiirtajaScheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.SecurityGroups')
subnets=$(aws events list-targets-by-rule --rule tuotanto-lampiSiirtajaScheduledFargateTaskRule | jq -c '.Targets | map(select(.Id == "Target0")) | .[0] | .EcsParameters.NetworkConfiguration.awsvpcConfiguration.Subnets')
awsvpcconfiguration=$(jq -c -n --argjson subnets "$subnets" \
--argjson securityGroups "$securitygroups" \
--arg assignPublicIp "$assignpublicip" \
'$ARGS.named')
networkconfiguration=$(jq -c -n --argjson awsvpcConfiguration "$awsvpcconfiguration" '$ARGS.named')
command="aws ecs run-task --cluster $ecscluster --task-definition $taskdefinition --launch-type="FARGATE" --network-configuration '$networkconfiguration'"
echo "$command"

eval "$command"

0 comments on commit 54d2bf9

Please sign in to comment.