-
Notifications
You must be signed in to change notification settings - Fork 3
88 lines (73 loc) · 2.65 KB
/
Copy pathdeploy.yml
File metadata and controls
88 lines (73 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Deploy to AWS
on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'dev'
type: choice
options:
- dev
- prod
env:
TF_VERSION: "1.5.0"
AWS_REGION: "us-east-1"
jobs:
deploy:
name: Deploy Infrastructure
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Build Lambda Package
run: |
mkdir -p package
pip install -r requirements.txt -t ./package
cp handler.py package/
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ env.AWS_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Create terraform.tfvars
run: |
cat > terraform.tfvars <<EOF
telegram_token = "${{ secrets.TELEGRAM_TOKEN }}"
lab_role_arn = "${{ secrets.LAB_ROLE_ARN }}"
environment = "${{ github.event.inputs.environment }}"
log_retention_days = 14
EOF
- name: Terraform Init
run: terraform init
- name: Terraform Plan
run: terraform plan -out=tfplan
- name: Terraform Apply
run: terraform apply -auto-approve tfplan
- name: Get Outputs
id: outputs
run: |
echo "api_url=$(terraform output -raw api_gateway_url)" >> $GITHUB_OUTPUT
echo "lambda_name=$(terraform output -raw lambda_function_name)" >> $GITHUB_OUTPUT
- name: Setup Webhook
run: |
API_URL="${{ steps.outputs.outputs.api_url }}"
curl -s "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/setWebhook?url=${API_URL}"
- name: Deployment Summary
run: |
echo "## Deployment Complete! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** ${{ github.event.inputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo "**API Gateway URL:** ${{ steps.outputs.outputs.api_url }}" >> $GITHUB_STEP_SUMMARY
echo "**Lambda Function:** ${{ steps.outputs.outputs.lambda_name }}" >> $GITHUB_STEP_SUMMARY