Skip to content

Commit 614c134

Browse files
committed
Initial commit
1 parent 8328e19 commit 614c134

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM amazon/aws-cli
2+
3+
ADD . /
4+
5+
ENTRYPOINT ["bash", "/script.sh"]

LICENSE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2019 Peter Ukonu
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

action.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Deploy Web App'
2+
description: 'Deploys a webapp to an s3 bucket and then invalidates cloudfront entry'
3+
author: 'Peter Ukonu'
4+
branding:
5+
color: 'blue'
6+
inputs:
7+
build_path:
8+
description: "The build path to deploy to s3"
9+
required: true
10+
bucket_name:
11+
description: "The AWS S3 bucket you will like to deployt to"
12+
required: true
13+
bucket_key:
14+
description: "The path of the folder you will to deploy to within the S3 bucket"
15+
required: true
16+
default: "/"
17+
distribution_invalidation_path:
18+
description: "The path in cloudfront to invalidate"
19+
required: false
20+
default: "/*"
21+
outputs:
22+
aws-deploy-output:
23+
description: 'A json output from AWS on the deployment'
24+
runs:
25+
using: 'docker'
26+
image: 'Dockerfile'
27+
args:
28+
- ${{ inputs.build_path }}
29+
- ${{ inputs.bucket_name }}
30+
- ${{ inputs.bucket_key }}
31+
- ${{ inputs.distribution_invalidation_path }}

script.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash -l
2+
3+
set -e
4+
5+
# check configuration
6+
7+
err=0
8+
9+
build_path=$1
10+
bucket_name=$2
11+
bucket_key=$3
12+
distribution_invalidation_path=$4
13+
aws_region=AWS_REGION
14+
15+
ls -l $build_path
16+
17+
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
18+
echo "AWS_ACCESS_KEY was not found. Set this in your github secrets"
19+
err=1
20+
fi
21+
22+
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
23+
echo "AWS_SECRET_ACCESS_KEY was not founde. Set this in your github secrets"
24+
err=1
25+
fi
26+
27+
if [ -z "$aws_region" ]; then
28+
echo "Specify an AWS region"
29+
err=1
30+
fi
31+
32+
if [ -z "$bucket_name" ]; then
33+
echo "Specify a bucket you will like to deploy to"
34+
err=1
35+
fi
36+
37+
if [ $err -eq 1 ]; then
38+
exit 1
39+
fi
40+
41+
output="AWS OUTPUT"
42+
echo "::set-output name=aws-deploy-output::$output"
43+
44+
aws s3 cp $build_path s3://$bucket_name/$bucket_key --recursive
45+
46+
if [ -z "$DISTRIBUTION_ID" ]; then
47+
echo "Skipping cloudfront invalidation..."
48+
else
49+
50+
if [ -z "$distribution_invalidation_path" ]; then
51+
echo "Specify the invalidation path. e.g. /* or /production/*"
52+
exit 1
53+
fi
54+
55+
echo "Invalidating cloudfront..."
56+
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "$distribution_invalidation_path"
57+
fi

0 commit comments

Comments
 (0)