Skip to content

Commit 6cb9457

Browse files
authored
Tweaks (#3)
* Update action.yaml * Escaping echo chars * Removing show details - prettify action * Removing unnecessary file * Adding support for bucket with DNS and no CDN * Fixing and enforcing dependencies * Updating README.md
1 parent 2543951 commit 6cb9457

File tree

5 files changed

+195
-109
lines changed

5 files changed

+195
-109
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ GitHub action to deploy anything into a bucket, adding the options to add a CDN
44

55
This action will copy the files from the defined folder into an S3 bucket, defining the content type and serving ALL OF THEM PUBLICLY.
66

7+
## Action main options graph
8+
9+
```mermaid
10+
graph TD;
11+
A[S3 Bucket] --> B[S3 Endpoint]
12+
A -->|DNS| C[Direct S3 DNS] --> G[- No SSL\n- 63 chars FQDN limit]
13+
A -->|CDN| D[CDN Public URL] --> H[- SSL\n- CND URL]
14+
A -->|CDN + DNS| E[Public FQDN] --> I[- Owned SSL cert\n- Unlimited FQDN length]
15+
```
16+
717
## Requirements
818

919
1. Files to publish
@@ -27,7 +37,6 @@ Setting `aws_r53_create_sub_cert` to `true` will create a certificate **just for
2737

2838
> :warning: Be very careful here! **Created certificates are fully managed by Terraform**. Therefor **they will be destroyed upon stack destruction**.
2939
30-
3140
## Example usage
3241

3342
Create `.github/workflow/deploy.yaml` with the following to build on push.
@@ -97,7 +106,6 @@ The following inputs can be used as `step.with` keys
97106
| Name | Type | Description |
98107
|------------------|---------|------------------------------------|
99108
| `tf_action` | String | Option to run Terraform `apply` / `destroy` action. Will run `plan` if nothing defined. |
100-
| `tf_plan_show_details` | Boolean | Set to true to show a detailed output from Terraform plan. |
101109
| `tf_state_bucket` | String | AWS S3 bucket name to use for Terraform state. Defaults to `${org}-${repo}-{branch}-tf-state` |
102110
| `tf_state_bucket_destroy` | Boolean | Force purge and deletion of S3 bucket defined if terraform destroy action succeded. |
103111
<hr/>
@@ -108,7 +116,7 @@ The following inputs can be used as `step.with` keys
108116
|------------------|---------|------------------------------------|
109117
| `aws_spa_source_folder` | String | Source folder for files to be published. Will ignore any hidden file. Defaults to root folder of the calling repo if nothing defined. |
110118
| `aws_spa_root_object` | Boolean | Root object to be served as entry-point. Defaults to `index.html`. |
111-
| `aws_spa_website_bucket_name` | String | AWS S3 bucket name to use for the public files. Defaults to `${org}-${repo}-{branch}-sp` |
119+
| `aws_spa_website_bucket_name` | String | AWS S3 bucket name to use for the public files. Defaults to `${org}-${repo}-{branch}-sp`. If using a R53 domain and not a CDN, bucket name will be the FQDN one. See note. |
112120
| `aws_spa_cdn_enabled` | Boolean | Enable or disables the use of CDN. Defaults to `false`. |
113121
<hr/>
114122
<br/>
@@ -135,6 +143,17 @@ We use the kubernetes style for this. For example, kubernetes -> k(# of characte
135143

136144
For some specific resources, we have a 32 characters limit. If the identifier length exceeds this number after compression, we remove the middle part and replace it for a hash made up from the string itself.
137145

146+
## Note about bucket names
147+
148+
As a default, the bucket name will be `${GITHUB_ORG_NAME}-${GITHUB_REPO_NAME}-${GITHUB_BRANCH_NAME}-sp`.
149+
150+
But, in the case you add a Route53 domain and no CDN, the bucket name must match the FQDN defined, like `spa.example.com`. If setting `aws_r53_root_domain_deploy`, two buckets will be created. `www.{aws_r53_domain_name}`and `{aws_r53_domain_name}`. Traffic from www bucket will be forwarded to the main bucket.
151+
Because of this reason, the length of the FQDN *MUST* be below 64 characters. Will try using the provided FQDN, if not, fallback to `resource-identifier.{aws_r53_domain_name}` of the compressed one. IF it still exceeds the limit, will remove as many as needed.
152+
153+
> :warning: HTTPS (TLS / SSL) will only be available if using CDN.
154+
155+
In the case you are using domains and not using a CDN, no cert will be available, and length of the FQDN *MUST* be below 64 characters. Will be adjusted if it exceeds that limit.
156+
138157
## Contributing
139158
We would love for you to contribute to [bitovi/github-actions-deploy-static-site-to-aws](https://github.com/bitovi/github-actions-deploy-static-site-to-aws).
140159
Would you like to see additional features? [Create an issue](https://github.com/bitovi/github-actions-deploy-static-site-to-aws/issues/new) or a [Pull Requests](https://github.com/bitovi/github-actions-deploy-static-site-to-aws/pulls). We love discussing solutions!

action.yaml

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ inputs:
3535
tf_action:
3636
desctiption: 'Option to run Terraform apply / destroy option. Will run plan if nothing defined.'
3737
required: false
38-
tf_plan_show_details:
39-
description: 'Set to true to show a detailed output from Terraform plan.'
40-
required: false
4138
tf_state_bucket:
4239
description: 'AWS S3 bucket to use for Terraform state. Defaults to `${org}-${repo}-{branch}-tf-state`'
4340
required: false
@@ -78,7 +75,6 @@ inputs:
7875
description: 'Generates and manage the sub-domain certificate for the application. Default is `false`.'
7976
required: false
8077

81-
8278
outputs:
8379
public_url:
8480
description: "The URL of the generated app"
@@ -124,54 +120,92 @@ runs:
124120
AWS_R53_CREATE_ROOT_CERT: ${{ inputs.aws_r53_create_root_cert }}
125121
AWS_R53_CREATE_SUB_CERT: ${{ inputs.aws_r53_create_sub_cert }}
126122
run: |
123+
echo "::group::Generating Terraform pre-requisites" > /dev/null
127124
echo "running scripts/generate_deploy.sh"
128125
$GITHUB_ACTION_PATH/scripts/generate_deploy.sh
126+
echo "::endgroup::"
129127
130128
- name: Setup Terraform
131129
uses: hashicorp/setup-terraform@v2
132130

133131
- name: Terraform Init
134132
id: init
135133
shell: bash
136-
run: terraform -chdir=$GITHUB_ACTION_PATH/terraform_code init
134+
run: |
135+
echo "::group::Terraform Init"
136+
terraform -chdir=$GITHUB_ACTION_PATH/terraform_code init
137+
echo "::endgroup::"
137138
138139
- name: Terraform Validate
139140
id: validate
140141
shell: bash
141-
run: terraform -chdir=$GITHUB_ACTION_PATH/terraform_code validate
142+
run: |
143+
echo "::group::Terraform Validate"
144+
terraform -chdir=$GITHUB_ACTION_PATH/terraform_code validate
145+
echo "::endgroup::"
142146
143147
- name: Terraform Plan
144-
if: ${{ success () && inputs.tf_show_plan_details == 'true' && inputs.tf_action != 'destroy' }}
148+
if: ${{ success () && inputs.tf_action != 'destroy' }}
145149
id: plan
146150
shell: bash
147-
run: terraform -chdir=$GITHUB_ACTION_PATH/terraform_code plan
148-
149-
- name: Terraform Show Plan Details
150-
if: ${{ success () && inputs.tf_show_plan_details == 'true' && inputs.tf_action != 'destroy' }}
151-
shell: bash
152-
run: |
153-
echo ${{ steps.plan.outputs.stdout }}
154-
echo ${{ steps.plan.outputs.stderr }}
155-
echo ${{ steps.plan.outputs.exitcode }}
151+
run: |
152+
echo "::group::Terraform Plan"
153+
terraform -chdir=$GITHUB_ACTION_PATH/terraform_code plan -input=false
154+
echo "::endgroup::"
156155
157156
- name: Terraform Apply
158157
id: apply
159158
if: ${{ success() && inputs.tf_action == 'apply' }}
160159
shell: bash
161160
run: |
161+
echo "::group::Terraform Apply"
162162
terraform -chdir=$GITHUB_ACTION_PATH/terraform_code apply -auto-approve
163+
echo "::endgroup::"
164+
terraform -chdir=$GITHUB_ACTION_PATH/terraform_code output | grep public_url | sed -e 's/ *= */=/g' -e 's/"//g' >> $GITHUB_OUTPUT
163165
164166
- name: Terraform Destroy
165167
if: ${{ success() && inputs.tf_action == 'destroy' }}
166168
shell: bash
167-
run: |
169+
run: |
170+
echo "::group::Terraform Destroy"
168171
terraform -chdir=$GITHUB_ACTION_PATH/terraform_code destroy -auto-approve
172+
echo "::endgroup::"
169173
170-
- name: Terraform Destroy
174+
- name: Purge and delete tf-state bucket
171175
if: ${{ success() && inputs.tf_action == 'destroy' && inputs.tf_state_bucket_destroy == 'true' }}
172176
shell: bash
173177
env:
174178
TF_STATE_BUCKET: ${{ inputs.tf_state_bucket }}
179+
run: |
180+
echo "::group::Purge and delete tf-state bucket"
181+
$GITHUB_ACTION_PATH/scripts/destroy_tf_state_bucket.sh
182+
echo "::endgroup::"
183+
184+
- name: Print result
185+
if: ${{ success() && steps.apply.outputs.public_url != '' }}
186+
shell: bash
187+
run: |
188+
echo "## It's published! :rocket:" >> $GITHUB_STEP_SUMMARY
189+
echo ${{ steps.apply.outputs.public_url }} >> $GITHUB_STEP_SUMMARY
190+
191+
- name: Print result
192+
if: ${{ success() inputs.tf_action == 'destroy' && inputs.tf_state_bucket_destroy == 'true' }}
193+
shell: bash
194+
run: |
195+
echo "## Deploy Destroyed! :boom:" >> $GITHUB_STEP_SUMMARY
196+
echo "Infrastructure should be gone now!" >> $GITHUB_STEP_SUMMARY
197+
198+
- name: Print result
199+
if: ${{ success() inputs.tf_action == 'destroy' && inputs.tf_state_bucket_destroy != 'true' }}
200+
shell: bash
201+
run: |
202+
echo "## Deploy Destroyed! :boom:" >> $GITHUB_STEP_SUMMARY
203+
echo "Buckets and infrastructure should be gone now!" >> $GITHUB_STEP_SUMMARY
204+
205+
- name: Print error result
206+
if: ${{ failure() }}
207+
shell: bash
175208
run: |
176-
echo "running scripts/destroy_tf_state_bucket.sh"
177-
$GITHUB_ACTION_PATH/scripts/destroy_tf_state_bucket.sh
209+
echo "## Workflow failed to run :fire:" >> $GITHUB_STEP_SUMMARY
210+
echo "Please check the logs for possible errors." >> $GITHUB_STEP_SUMMARY
211+
echo "If you consider this is a bug in the Github Action, please submit an issue to our repo." >> $GITHUB_STEP_SUMMARY

scripts/copy_incoming_files.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

scripts/generate_deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ echo "GITHUB_IDENTIFIER: [$GITHUB_IDENTIFIER]"
3333
GITHUB_IDENTIFIER_SS="$($GITHUB_ACTION_PATH/scripts/generate_identifier.sh 30)"
3434
echo "GITHUB_IDENTIFIER SS: [$GITHUB_IDENTIFIER_SS]"
3535

36+
# Moving files, excluding hidden ones.
3637
SOURCE_FILES="$GITHUB_WORKSPACE/$AWS_SPA_SOURCE_FOLDER"
3738
rsync -av --exclude=".*" $SOURCE_FILES/ "${GITHUB_ACTION_PATH}/upload"
3839
SOURCE_FILES="${GITHUB_ACTION_PATH}/upload"

0 commit comments

Comments
 (0)