-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (127 loc) · 4.97 KB
/
main.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Deployment using Elastic Beanstalk
on:
workflow_dispatch:
push:
branches: [ "stage" ]
pull_request:
branches: [ "main" ]
env:
# 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: us-east-1
app_bucket_name: ebs-ue1-eb-d-s3
s3Key: app.zip
applicationName: ebs-ue1-eb-d-eb-app
environmentName: ebs-ue1-eb-d-eb-env
terraformDir: ./terraform
appDir: ./node-application
jobs:
terraform_infrastructure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure aws credentials
uses: aws-action/configure-aws-credentials@v1
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: Echo Hello World
run: aws sts get-caller-identity
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
- name: Terraform Version
run: echo "Terraform version=$(terraform --version)" ##
- name: Terraform Init
run: terraform init
working-directory: ${{ env.terraformDir }}
- name: Terraform Plan
# run: terraform plan -var "iam_instance_profile=your-iam-instance-profile"
run: terraform plan --var-file=prod.tfvars -lock=false
working-directory: ${{ env.terraformDir }}
# - name: Terraform apply
# run: terraform apply -auto-approve -var-file=prod.tfvars -lock=false
# working-directory: ${{ env.terraformDir }}
- name: Terraform Destroy
run: terraform destroy -auto-approve -var-file=prod.tfvars -lock=false
working-directory: ${{ env.terraformDir }}
# build-and-test: #
# runs-on: ubuntu-latest
# needs: terraform_infrastructure
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Configure aws credentials
# uses: aws-action/configure-aws-credentials@v1
# 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: List files
# run: ls -la
# - name: Set up Node.js
# uses: actions/setup-node@v3
# with:
# node-version: '18'
# # - name: npm version
# # run: npm --version
# # - name: Install dependencies
# # run: sudo npm install
# # working-directory: ./node-application
# # - name: Build the application
# # run: sudo npm run build
# # working-directory: ./node-application
# - name: List files before zip
# run: ls -la ${{ env.appDir }}
# - name: Zip application
# run: |
# cd ${{ env.appDir }}
# zip -r ../app.zip .
# - name: List files after zip
# run: ls -la
# - name: Upload to S3
# run: aws s3 cp app.zip s3://${{env.app_bucket_name}}/app.zip --region us-east-1
# working-directory: .
# deploy:
# runs-on: ubuntu-latest
# needs: build-and-test
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Configure aws credentials
# uses: aws-action/configure-aws-credentials@v1
# 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: Deploy to Elastic Beanstalk
# run: |
# VERSION_LABEL=$(date +%Y%m%d%H%M%S)
# aws elasticbeanstalk create-application-version \
# --application-name ${{env.applicationName}} \
# --region us-east-1 \
# --version-label $VERSION_LABEL \
# --source-bundle S3Bucket=${{env.app_bucket_name}},S3Key=app.zip \
# --debug
# aws elasticbeanstalk update-environment \
# --application-name ${{env.applicationName}} \
# --environment-name ${{env.environmentName}} \
# --version-label $VERSION_LABEL \
# --debug
# # # - name: Deploy to Elastic Beanstalk (Example)
# # # run: |
# # # eb init -p node.js your-application-name --region $AWS_DEFAULT_REGION
# # # eb create your-environment-name
# # # eb deploy your-environment-name
# - name: Notify success
# if: success()
# run: echo "Deployment successful!!"
# # # 02_start_application:
# # # command: "npm start"
# # # cwd: "/var/app/staging"