-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (78 loc) · 2.86 KB
/
Staging.yml
File metadata and controls
97 lines (78 loc) · 2.86 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
name: Staging Image Build & Push
on:
pull_request:
branches: [ "main" ]
permissions:
pull-requests: write
contents: read
id-token: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
Terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::806066816337:role/fastapi-image-IAM-role
role-session-name: fastapi-image-IAM-role
aws-region: eu-central-1
- name: Terraform plan
uses: dflook/terraform-plan@v1
with:
path: ./terraform
label: Staging
backend_config_file: ./terraform/env/dev.tfbackend
var_file: ./terraform/env/dev.tfvars
variables: |
vpc_id = "${{ secrets.VPC_ID }}"
hosted_zone_id = "${{ secrets.ZONE_ID }}"
image_tag = "${{ github.sha }}"
- name: Terraform apply
uses: dflook/terraform-apply@v1
with:
path: ./terraform
label: Staging
backend_config_file: ./terraform/env/dev.tfbackend
var_file: ./terraform/env/dev.tfvars
variables: |
vpc_id = "${{ secrets.VPC_ID }}"
hosted_zone_id = "${{ secrets.ZONE_ID }}"
image_tag = "${{ github.sha }}"
auto_approve: true
Build_Image:
needs: Terraform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::806066816337:role/fastapi-image-IAM-role
role-session-name: fastapi-image-IAM-role
aws-region: us-east-1
- name: Registry Alias Output
uses: dflook/terraform-output@v1
id: my-outputs
with:
path: ./terraform
backend_config_file: ./terraform/env/dev.tfbackend
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: ${{ steps.my-outputs.outputs.ecr_registry_id }}
REPOSITORY: ${{ steps.my-outputs.outputs.ecr_repository_name }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest