-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (128 loc) · 4.7 KB
/
ci.yml
File metadata and controls
143 lines (128 loc) · 4.7 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
on:
workflow_dispatch:
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
TF_VAR_availability_zones: "{\"az-1\": \"eu-west-1a\", \"az-2\": \"eu-west-1b\"}"
TF_VAR_vpc_cidr: "10.0.0.0/16"
TF_VAR_public_subnet_1_cidr: "10.0.0.0/24"
TF_VAR_public_subnet_2_cidr: "10.0.1.0/24"
TF_VAR_all_traffic_cidr: "0.0.0.0/0"
TF_VAR_container_name: ${{ secrets.CONTAINER_NAME }}
TF_VAR_docker_image: ${{ secrets.DOCKER_IMAGE }}
TF_VAR_domain: ${{ secrets.DOMAIN }}
TF_VAR_ecs_family: ${{ secrets.ECS_FAMILY }}
TF_VAR_ecs_launch_type: ${{ secrets.ECS_LAUNCH_TYPE }}
TF_VAR_env_name: ${{ secrets.ENV_NAME }}
TF_VAR_lb_type: ${{ secrets.LB_TYPE }}
TF_VAR_region: ${{ secrets.REGION }}
TF_VAR_replicas: ${{ secrets.REPLICAS }}
TF_VAR_sub_domain: ${{ secrets.SUB_DOMAIN }}
TF_VAR_target_group_type: ${{ secrets.TARGET_GROUP_TYPE }}
TF_VAR_dynamodb_name: "dynamodb_state_lock_table_romario"
TF_VAR_s3_bucket_name: "tf-state-arn-01"
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
STAGING_DIRECTORY: infrastructure/terraform/environments/staging
jobs:
build_and_deploy_to_staging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ env.AWS_SECRET_KEY }}
aws-region: ${{ env.TF_VAR_region }}
- name: login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKER_HUB_USER }}
password: ${{ env.DOCKER_HUB_PASSWORD }}
- name: Build Docker Image
run: |
echo "build docker image from current code"
docker build -f Dockerfile -t ${{ env.TF_VAR_docker_image }} .
- name: Push image to DockerHub
run: |
echo "pushing image to DockerHub"
docker push ${{ env.TF_VAR_docker_image }}
- name: configure Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform init
id: init
run: terraform init
working-directory: ${{ env.STAGING_DIRECTORY }}
- name: Terraform plan
id: plan
run: terraform plan -no-color -input=false -lock=false
continue-on-error: true
working-directory: ${{ env.STAGING_DIRECTORY }}
- name: Terraform apply
id: apply
run: |
terraform apply -auto-approve -lock=false
working-directory: ${{ env.STAGING_DIRECTORY }}
test:
runs-on: ubuntu-latest
needs: build_and_deploy_to_staging
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: run api tests
run: python -m pytest
- uses: actions/upload-artifact@v3
if: always()
with:
name: tests-results-allure-report
path: allure-results/
retention-days: 30
- name: deploy allure report to github pages
uses: simple-elf/allure-report-action@master
if: always()
id: allure-report
with:
allure_results: allure-results
gh_pages: gh-pages
allure_report: allure-report
allure_history: allure-history
- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: allure-history
destroy_resources:
runs-on: ubuntu-latest
needs: [build_and_deploy_to_staging, test]
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ env.AWS_SECRET_KEY }}
aws-region: ${{ env.TF_VAR_region}}
- name: configure Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.1.7"
- name: Terraform init
id: init
run: terraform init
working-directory: ${{ env.STAGING_DIRECTORY }}
- name: Terraform plan destroy
run: terraform plan -destroy -lock=false
working-directory: ${{ env.STAGING_DIRECTORY }}
- name: Terraform destory
id: destroy
run: terraform destroy --auto-approve -input=false -lock=false
working-directory: ${{ env.STAGING_DIRECTORY }}