-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Attree
committed
Jan 30, 2020
1 parent
1c8289f
commit c2de5a1
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3.8-alpine | ||
|
||
ENV AWSCLI_VERSION='1.17.1' | ||
|
||
RUN pip install --quiet --no-cache-dir awscli==${AWSCLI_VERSION} | ||
RUN pip install --quiet --no-cache-dir mkdocs | ||
|
||
ADD entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: "mkdocs2S3" | ||
description: "Github action to build an MkDocs site and upload to S3" | ||
author: thomasattree | ||
runs: | ||
using: docker | ||
image: Dockerfile | ||
branding: | ||
icon: refresh-cw | ||
color: green |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
if [ -z "$AWS_S3_BUCKET" ]; then | ||
echo "AWS_S3_BUCKET is not set." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$AWS_ACCESS_KEY_ID" ]; then | ||
echo "AWS_ACCESS_KEY_ID is not set." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then | ||
echo "AWS_SECRET_ACCESS_KEY is not set." | ||
exit 1 | ||
fi | ||
|
||
# Default to eu-west-1 if AWS_REGION not set. | ||
if [ -z "$AWS_REGION" ]; then | ||
AWS_REGION="eu-west-1" | ||
echo "Using default region eu-west-1." | ||
fi | ||
|
||
# Build our mkdocs site. | ||
mkdocs build | ||
|
||
# Create a dedicated profile for this action to avoid conflicts | ||
# with past/future actions. | ||
aws configure --profile s3-sync-action <<-EOF > /dev/null 2>&1 | ||
${AWS_ACCESS_KEY_ID} | ||
${AWS_SECRET_ACCESS_KEY} | ||
${AWS_REGION} | ||
text | ||
EOF | ||
|
||
# Sync using our dedicated profile and suppress verbose messages. | ||
# All other flags are optional via the `args:` directive. | ||
sh -c "aws s3 sync ${SOURCE_DIR:-.} s3://${AWS_S3_BUCKET}/${DEST_DIR} \ | ||
--profile s3-sync-action \ | ||
--no-progress \ | ||
${ENDPOINT_APPEND} $*" | ||
|
||
# Clear out credentials after we're done. | ||
# We need to re-run `aws configure` with bogus input instead of | ||
# deleting ~/.aws in case there are other credentials living there. | ||
# https://forums.aws.amazon.com/thread.jspa?threadID=148833 | ||
aws configure --profile s3-sync-action <<-EOF > /dev/null 2>&1 | ||
null | ||
null | ||
null | ||
text | ||
EOF |