-
Notifications
You must be signed in to change notification settings - Fork 3
82 lines (67 loc) · 3 KB
/
ecs_kinesis_timestream_create.yml
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
name: Deploy ECS + Kinesis + Timestream project
on: workflow_dispatch
env:
PROJECT_DIR: projects/ecs-kinesis-timestream
PROJECT_NAME: "ecs-kinesis-timestream"
ENV: "pdn"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.4.6
terraform_wrapper: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up AWS CLI configuration
run: |
mkdir -p $HOME/.aws
echo "[default]" >> $HOME/.aws/credentials
echo "aws_access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $HOME/.aws/credentials
echo "aws_secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> $HOME/.aws/credentials
echo "[default]" >> $HOME/.aws/config
echo "region=${{ secrets.AWS_REGION }}" >> $HOME/.aws/config
- name: Create Backend S3 Bucket for Terraform
run: |
aws s3api create-bucket \
--bucket "tfstate-backend-${{ secrets.AWS_ACCOUNT_ID }}-${{ env.ENV }}" \
--region ${{ secrets.AWS_REGION }} \
- name: Terraform Init
run: |
cd ${{ env.PROJECT_DIR }}/terraform
terraform init
- name: Terraform Plan and Apply
run: |
cd ${{ env.PROJECT_DIR }}/terraform
terraform plan -var-file="env/${{ env.ENV }}/${{ env.ENV }}.tfvars"
terraform apply -auto-approve
- name: Upload Terraform State to S3
run: |
cd ${{ env.PROJECT_DIR }}/terraform
aws s3 cp terraform.tfstate s3://tfstate-backend-${{ secrets.AWS_ACCOUNT_ID }}-${{ env.ENV }}/
- name: Build and Push Docker Image for Data Producer
run: |
cd ${{ env.PROJECT_DIR }}/terraform
ECR_URL_DATA_PRODUCER=$(terraform output -raw aws_ecr_repository_url_data_producer)
echo $ECR_URL_DATA_PRODUCER
cd ../data-producer
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $ECR_URL_DATA_PRODUCER
docker build -t "$ECR_URL_DATA_PRODUCER:latest" .
docker push "$ECR_URL_DATA_PRODUCER:latest"
- name: Build and Push Docker Image for Grafana
run: |
cd ${{ env.PROJECT_DIR }}/terraform
ECR_URL_GRAFANA=$(terraform output -raw aws_ecr_repository_url_grafana)
echo $ECR_URL_GRAFANA
docker pull grafana/grafana:8.2.5
docker tag grafana/grafana:8.2.5 $ECR_URL_GRAFANA:latest
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $ECR_URL_GRAFANA
docker push "$ECR_URL_GRAFANA:latest"