Skip to content

Commit 773032a

Browse files
authored
Merge pull request #8 from TrueSparrowSystems/deployment-changes
2 parents fd24217 + 73b12f5 commit 773032a

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ AWS_ACCESS_KEY_ID=access-key-id
55
AWS_SECRET_ACCESS_KEY=secret-access-key
66
AWS_DEFAULT_REGION=us-east-1
77

8+
AWS_AMPLIFY_APP_ID=amplify-app-id
9+
AWS_AMPLIFY_BRANCH_NAME=amplify-branch-name
10+
811
# CUSTOM_REPLACE_KEYS and CUSTOM_REPLACE_VALUES must be comma seperated values and number of elements should be same.
912
CUSTOM_REPLACE_KEYS="key_1", "key_2"
1013
CUSTOM_REPLACE_VALUES="value_1", "value_2"

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
.DS_Store
3+
# Rubymine IDE files
4+
.idea/*

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM bash:5.1.16-alpine3.15
22

3-
RUN apk add --no-cache wget aws-cli
3+
RUN apk add --no-cache zip curl jq wget aws-cli
44

55
ENV GHOST_STATIC_CONTENT_DIR=/src/content
66

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,29 @@ If your blog is hosted under `https://content.yourdomain.com` and you want to ho
77

88
You can also replace certain text from the generated static files by passing the following arguments `custom_replace_keys` and `custom_replace_values`. For more details, refer Inputs and Example usage section. It doesn't support the multiline replacement as of now.
99

10-
Additionally, it also provides the functionality to upload the static HTML files to S3 bucket. To access these files publicly, make it as a public bucket and enable static website hosting.
10+
Optionally, you can either host the static files on AWS S3 or on AWS Amplify.
11+
12+
To host Static Blog on AWS S3, provide the following input parameters:
13+
14+
- `s3_bucket_name` (Make the bucket publicly accessible and enable static web hosting)
15+
16+
- `aws_access_key_id`
17+
18+
- `aws_secret_access_key`
19+
20+
- `aws_region`
21+
22+
To host Static Blog on already existing AWS Amplify application, provide the following input parameters:
23+
24+
- `aws_amplify_app_id`
25+
26+
- `aws_amplify_branch_name`
27+
28+
- `aws_access_key_id`
29+
30+
- `aws_secret_access_key`
31+
32+
- `aws_region`
1133

1234
## Inputs
1335

@@ -52,6 +74,14 @@ Additionally, it also provides the functionality to upload the static HTML files
5274

5375
**Optional** AWS region.
5476

77+
## `aws_amplify_app_id`
78+
79+
**Optional** Amplify App id.
80+
81+
## `aws_amplify_branch_name`
82+
83+
**Optional** Amplify branch name.
84+
5585
## Example usage
5686

5787
```yaml

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ inputs:
3434
aws_region:
3535
description: "AWS region"
3636
required: false
37+
aws_amplify_app_id:
38+
description: "Amplify App id"
39+
required: false
40+
aws_amplify_branch_name:
41+
description: "Amplify Branch name"
42+
required: false
43+
3744
runs:
3845
using: "docker"
3946
image: "Dockerfile"
@@ -48,3 +55,5 @@ runs:
4855
- ${{ inputs.aws_access_key_id }}
4956
- ${{ inputs.aws_secret_access_key }}
5057
- ${{ inputs.aws_region }}
58+
- ${{ inputs.aws_amplify_app_id }}
59+
- ${{ inputs.aws_amplify_branch_name }}

entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if [[ $# -gt 0 && ${GITHUB_ACTIONS} -eq true ]]; then
1111
export AWS_ACCESS_KEY_ID=${INPUT_AWS_ACCESS_KEY_ID}
1212
export AWS_SECRET_ACCESS_KEY=${INPUT_AWS_SECRET_ACCESS_KEY}
1313
export AWS_DEFAULT_REGION=${INPUT_AWS_REGION}
14+
export AWS_AMPLIFY_APP_ID=${INPUT_AWS_AMPLIFY_APP_ID}
15+
export AWS_AMPLIFY_BRANCH_NAME=${INPUT_AWS_AMPLIFY_BRANCH_NAME}
1416
fi
1517

1618
/src/run.sh

run.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# - AWS_ACCESS_KEY_ID
1414
# - AWS_SECRET_ACCESS_KEY
1515
# - AWS_DEFAULT_REGION
16+
# - AWS_AMPLIFY_APP_ID
17+
# - AWS_AMPLIFY_BRANCH_NAME
1618

1719
GHOST_HOSTED_DOMAIN_WITH_PATH=$(echo ${GHOST_HOSTED_URL} | cut -d '/' -f 3-)
1820
GHOST_HOSTED_BLOG_PATH=$(echo ${GHOST_HOSTED_URL} | cut -d '/' -f 4-)
@@ -148,9 +150,62 @@ if [[ ! -z ${S3_BUCKET_NAME} ]]; then
148150
aws s3 sync ${blog_dir}/public ${s3_blog_path}/public --acl public-read --cache-control "public, max-age=604800, must-revalidate" --delete
149151
aws s3 sync ${blog_dir}/assets ${s3_blog_path}/assets --acl public-read --cache-control "public, max-age=604800, must-revalidate" --delete
150152
echo "***** S3 upload complete *****"
153+
elif [[ ! -z ${AWS_AMPLIFY_APP_ID} ]]; then
154+
echo ""
155+
echo "***** Started generating zip for static blog *****"
156+
cd ${GHOST_STATIC_CONTENT_DIR}
157+
zip -r ${GHOST_STATIC_BLOG_PATH}.zip ${GHOST_STATIC_BLOG_PATH}
158+
echo "***** Started create deployment for Amplify *****"
159+
job=`aws amplify create-deployment --app-id ${AWS_AMPLIFY_APP_ID} --branch-name ${AWS_AMPLIFY_BRANCH_NAME} --output json`
160+
# Extract values and store in variables
161+
jobId=$(echo "$job" | jq -r '.jobId')
162+
if [[ $? -ne 0 ]]; then
163+
echo "Error: Unable to fetch jobId"
164+
exit 1
165+
fi
166+
zipUploadUrl=$(echo "$job" | jq -r '.zipUploadUrl')
167+
if [[ $? -ne 0 ]]; then
168+
echo "Error: Unable to fetch zipUploadUrl"
169+
exit 1
170+
fi
171+
echo "jobId ===>>>>> ${jobId}"
172+
echo "zipUploadUrl ===>>>>> ${zipUploadUrl}"
173+
curl "${zipUploadUrl}" --upload-file ${GHOST_STATIC_BLOG_PATH}.zip
174+
if [[ $? -ne 0 ]]; then
175+
echo "Error: Unable to upload zip"
176+
exit 1
177+
fi
178+
aws amplify start-deployment --app-id ${AWS_AMPLIFY_APP_ID} --branch-name ${AWS_AMPLIFY_BRANCH_NAME} --job-id ${jobId}
179+
if [[ $? -ne 0 ]]; then
180+
echo "Error: Unable to start deployment"
181+
exit 1
182+
fi
183+
while true; do
184+
status=`aws amplify get-job --app-id ${AWS_AMPLIFY_APP_ID} --branch-name ${AWS_AMPLIFY_BRANCH_NAME} --job-id ${jobId} | jq -r '.job.summary.status'`
185+
if [[ $? -ne 0 ]]; then
186+
echo "Error: Unable to fetch status"
187+
exit 1
188+
fi
189+
# Check if the status is either "SUCCEED" or "FAILED"
190+
if [ "${status}" = "SUCCEED" ]; then
191+
echo "Job Status =>>>>>> ${status}"
192+
break
193+
elif [ "${status}" = "FAILED" ]; then
194+
echo "Job Status =>>>>>> ${status}"
195+
break
196+
elif [ "${status}" = "CANCELLED" ]; then
197+
echo "Job Status =>>>>>> ${status}"
198+
break
199+
else
200+
echo "Job Status =>>>>>> ${status}"
201+
fi
202+
# Wait for a while before checking again
203+
sleep 5 # Adjust the sleep duration as needed
204+
done
151205
else
152206
echo " "
153207
echo "If you want to upload the static site files to S3, provide following ENV variables: S3_BUCKET_NAME, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION"
208+
echo "Or if you want to upload the static site files to Amplify, provide following ENV variables: AWS_AMPLIFY_APP_ID, AWS_AMPLIFY_BRANCH_NAME, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION"
154209
fi
155210

156211
echo " "

0 commit comments

Comments
 (0)